apply a state for every camera in the scene!

I have a house in 3d and a background in it! I want to create scene states for every camera, so when I switch to any of them, I would see automatically the changes according to it's state! Any ideas?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
magicseed's picture

Hi, Where to download this

Hi,

Where to download this script please?

Regards,
neil

artrender.info's picture

but still the same

May be smth else?

try(destroyDialog ::bgaRoll)catch()
 
rollout bgaRoll "• • •"
(
	local d
	fn collectStates = (for s in 1 to sceneStateMgr.GetCount() collect sceneStateMgr.GetSceneState s)
	fn collectCameras ddl lb = if (cams = for c in cameras where not isKindof c TargetObject collect c).count != 0 do
	(
		local states = collectStates(), stCamList = #(), avCamList = #()
		for c in cams do
		(
			userProp = getUserPropBuffer c
			if userProp == "" then append avCamList c.name else
			(
				if findItem states userProp != 0 then append stCamList c.name else
				(
					setUserPropBuffer c "" ; append avCamList c.name
				)
			)
		)
		ddl.items = avCamList ; lb.items = stCamList
	)
	dropDownList ddl1 "Scene States:" width:190 pos:[5,5]
	dropDownList ddl2 "Available Cameras:" width:190 pos:[5,45]
	button btn1 "Set State To Camera" width:110 height:20 pos:[5,86]
	button btn2 "Refresh All" width:78 height:20 pos:[117,86]
	listbox lbox "State Cameras:" width:190 height:15 pos:[5,110]
	fn init = 
	(
		bgaRoll.ddl1.items = collectStates() 
		collectCameras bgaRoll.ddl2 bgaRoll.lbox
	)
	on bgaRoll open do init()
 
on btn2 pressed do 
(
	objTMData = attributes objData
    (
		local objTMS = for o in objects collect DataPair o o.transform 
		fn setObjTM arr = 
		(
			for i in 1 to arr.count where isValidNode arr[i].v1 do arr[i].v1.transform = arr[i].v2
		)
    )
    local d = FreeCamera()
	custAttributes.add d objTMData
 
)
on btn2 rightclick do
(
    ca = custAttributes.get d objTMData
    ca.setObjTM ca.objTMS
)	
 
 
 
 
	on btn1 pressed do 
	(
		if bgaRoll.ddl1.items.count != 0 and bgaRoll.ddl2.items.count != 0 do
		(
			if (cam = getNodeByName bgaRoll.ddl2.selected) != undefined do
			(			
				setUserPropBuffer cam bgaRoll.ddl1.selected
				bgaRoll.lbox.items = append bgaRoll.lbox.items bgaRoll.ddl2.selected
				bgaRoll.ddl2.items = deleteitem bgaRoll.ddl2.items bgaRoll.ddl2.selection
			)
		)
	)
	on lbox selected itm do 
	(
		if isValidNode (c = (getNodeByName bgaRoll.lbox.selected)) then select c else init()
	)
	on lbox doubleClicked itm do 
	(
		if isValidNode (c = (getNodeByName bgaRoll.lbox.selected)) then 
		(
			if sceneStateMgr.FindSceneState (st = getUserPropBuffer c) != 0 do
			(
				sceneStateMgr.RestoreAllParts st
				viewport.setCamera c
			)
		) else init()
	)
)
createDialog bgaRoll 200 330 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

in line

on btn2 rightclick do
(
ca = custAttributes.get d objTMData -- Unable to convert: undefined to type: MaxObject <<

artrender.info's picture

ahhh

srry! My fault!

artrender.info's picture

STILL THE SAME ERROR

try(destroyDialog ::bgaRoll)catch()
 
 
rollout bgaRoll "• • •"
(
 
 
	fn collectStates = (for s in 1 to sceneStateMgr.GetCount() collect sceneStateMgr.GetSceneState s)
	fn collectCameras ddl lb = if (cams = for c in cameras where not isKindof c TargetObject collect c).count != 0 do
	(
		local states = collectStates(), stCamList = #(), avCamList = #()
		for c in cams do
		(
			userProp = getUserPropBuffer c
			if userProp == "" then append avCamList c.name else
			(
				if findItem states userProp != 0 then append stCamList c.name else
				(
					setUserPropBuffer c "" ; append avCamList c.name
				)
			)
		)
		ddl.items = avCamList ; lb.items = stCamList
	)
	dropDownList ddl1 "Scene States:" width:190 pos:[5,5]
	dropDownList ddl2 "Available Cameras:" width:190 pos:[5,45]
	button btn1 "Set State To Camera" width:110 height:20 pos:[5,86]
	button btn2 "Refresh All" width:78 height:20 pos:[117,86]
	listbox lbox "State Cameras:" width:190 height:15 pos:[5,110]
	fn init = 
	(
		bgaRoll.ddl1.items = collectStates() 
		collectCameras bgaRoll.ddl2 bgaRoll.lbox
	)
	on bgaRoll open do init()
 
on btn2 pressed do 
(
	objTMData = attributes objData
    (
		local objTMS = for o in objects collect DataPair o o.transform 
		fn setObjTM arr = 
		(
			for i in 1 to arr.count where isValidNode arr[i].v1 do arr[i].v1.transform = arr[i].v2
		)
    )
    local d = FreeCamera()
	custAttributes.add d objTMData
 
)
on btn2 rightclick do
(
    ca = custAttributes.get d objTMData
    ca.setObjTM ca.objTMS
)	
 
 
 
 
	on btn1 pressed do 
	(
		if bgaRoll.ddl1.items.count != 0 and bgaRoll.ddl2.items.count != 0 do
		(
			if (cam = getNodeByName bgaRoll.ddl2.selected) != undefined do
			(			
				setUserPropBuffer cam bgaRoll.ddl1.selected
				bgaRoll.lbox.items = append bgaRoll.lbox.items bgaRoll.ddl2.selected
				bgaRoll.ddl2.items = deleteitem bgaRoll.ddl2.items bgaRoll.ddl2.selection
			)
		)
	)
	on lbox selected itm do 
	(
		if isValidNode (c = (getNodeByName bgaRoll.lbox.selected)) then select c else init()
	)
	on lbox doubleClicked itm do 
	(
		if isValidNode (c = (getNodeByName bgaRoll.lbox.selected)) then 
		(
			if sceneStateMgr.FindSceneState (st = getUserPropBuffer c) != 0 do
			(
				sceneStateMgr.RestoreAllParts st
				viewport.setCamera c
			)
		) else init()
	)
)
createDialog bgaRoll 200 330 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

in line

on btn2 rightclick do
(
ca = custAttributes.get d objTMData -- Unable to convert: undefined to type: MaxObject <<

barigazy's picture

I already told you. You need

I already told you. You need to put local variable "d" outside function.

rollout bgaRoll "• • •"
(
local d
...
)

bga

barigazy's picture

... but

you not need this free camera (it'sonly for example). What you need is to add this CA to all cameras in List View. You can add also more infos not only scene objects transform informations.

bga

artrender.info's picture

I look at this code, and I can't understand!

if

ca = custAttributes.get d objTMData

doesn't work for camera d, then it will not work for other cameras as well ?!!!?

barigazy's picture

...

The problem is not CA. You need to define better scenario for this tool, because there is more limitations that you need to consider.
The main problems are:
- Transform, animated and linked objects
- Different count of objects in different states
and who knows what more.
That's why Autodesk recreate whole State Scene in max2013+ ei. max2012(SAP)
I never play with this. Maybe someone can help you with that.

bga

barigazy's picture

:)

Try to write something and then we talk.

bga

artrender.info's picture

now I can rest in piece!

Barigazy, look! I've added to your code some lines from previous hints

try(destroyDialog ::bgaRoll)catch()
 
 
	objTMData = attributes objData
	(
		local objTMS = for o in objects collect DataPair o o.transform 
		fn setObjTM arr = 
			for i in 1 to arr.count where isValidNode arr[i].v1 do 
				arr[i].v1.transform = arr[i].v2
	)
rollout bgaRoll "• • •"
(
 
 
	fn collectStates = (for s in 1 to sceneStateMgr.GetCount() collect sceneStateMgr.GetSceneState s)
	fn collectCameras ddl lb = if (cams = for c in cameras where not isKindof c TargetObject collect c).count != 0 do
	(
		local states = collectStates(), stCamList = #(), avCamList = #()
		for c in cams do
		(
			userProp = getUserPropBuffer c
			if userProp == "" then append avCamList c.name else
			(
				if findItem states userProp != 0 then append stCamList c.name else
				(
					setUserPropBuffer c "" ; append avCamList c.name
				)
			)
		)
		ddl.items = avCamList ; lb.items = stCamList
	)
	dropDownList ddl1 "Scene States:" width:190 pos:[5,5]
	dropDownList ddl2 "Available Cameras:" width:190 pos:[5,45]
	button btn1 "Set State To Camera" width:110 height:20 pos:[5,86]
	button btn2 "Refresh All" width:78 height:20 pos:[117,86]
	listbox lbox "State Cameras:" width:190 height:15 pos:[5,110]
	fn init = 
	(
		local d = FreeCamera()
		custAttributes.add d objTMData
		bgaRoll.ddl1.items = collectStates() 
		collectCameras bgaRoll.ddl2 bgaRoll.lbox
	)
	on bgaRoll open do init()
	on btn2 pressed do 
	(
		--init()
		ca = custAttributes.get d objTMData
		ca.setObjTM ca.objTMS
	)
	on btn1 pressed do 
	(
		if bgaRoll.ddl1.items.count != 0 and bgaRoll.ddl2.items.count != 0 do
		(
			if (cam = getNodeByName bgaRoll.ddl2.selected) != undefined do
			(			
				setUserPropBuffer cam bgaRoll.ddl1.selected
				bgaRoll.lbox.items = append bgaRoll.lbox.items bgaRoll.ddl2.selected
				bgaRoll.ddl2.items = deleteitem bgaRoll.ddl2.items bgaRoll.ddl2.selection
			)
		)
	)
	on lbox selected itm do 
	(
		if isValidNode (c = (getNodeByName bgaRoll.lbox.selected)) then select c else init()
	)
	on lbox doubleClicked itm do 
	(
		if isValidNode (c = (getNodeByName bgaRoll.lbox.selected)) then 
		(
			if sceneStateMgr.FindSceneState (st = getUserPropBuffer c) != 0 do
			(
				sceneStateMgr.RestoreAllParts st
				viewport.setCamera c
			)
		) else init()
	)
)
createDialog bgaRoll 200 330 10 110 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

A runt it, then I move an object from the scene and then,
When I press refresh, I get error

-- Unable to convert: undefined to type: MaxObject
error for -> ca = custAttributes.get d objTMData

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.