Notifications
Clear all

[Closed] MaxScript Select camera without target

hello I have just one more problem to solve in script but can’t figure it out so If somebody can help me with just one more line of code.
I want script to collect Camera (without target) when opening. It can be selected by select by name that is filtered in class of cameras (“isKindOf”) and it’s working but I can’t add that filter when opening and collecting camera automatically. In my every scene the camera has the same name “CAM_2_Front” and script, when is collecting, it grabs target object with camera too. I tried to filter it in some other way but it’s not working, I got “call needs function or class, got: $Target_Camera:CAM_2_Front @ [-1.777199,-434.206512,187.059662]” problem. And in another way it can’t convert to a node. Few days of trying and still can’t figure it out. Here’s the code:

try destroydialog ::AutoCamera catch()
	
Rollout AutoCamera "AutoCamera" width:155
(
	
	button bt_SelectCamera "Select Camera"   align:#left  height:30 width:130
	listbox list_cameras "" align:#left height:5 width:130
	button bt_render "Render" border:false align:#center width:206 height:256

	
	local theCameras = #()
	
	
	----FUNCTIONS----
	fn FilterCameras  obj = isKindOf obj camera
	
	fn selectCameras =
	(
		selCam = selectByName title:"Pick Camera" filter:FilterCameras showHidden:true
		if selCam != undefined then
		(
			theCameras = selCam
			list_cameras.items = for c in theCameras collect c.name
			)else(
			list_cameras.items = #()
			theCameras = #()
		)
	)--end fn selectCameras
	

	----EVENTS----	
	on AutoCamera open do
	(
		camName = $CAM_2_Front 
		for i in camName do 
			(
				if camName isKindOf i camera do 
					(
						camName2
					)
			)
		openSelCam = camName2
		if openSelCam != undefined then
		(
			theCameras = openSelCam
			list_cameras.items = for c in theCameras collect c.name
			)else(
			list_cameras.items = #()
			theCameras = #()
		)
	)--end onOpen
	
	on bt_SelectCamera pressed do
	(
		if theCameras != undefined then selectCameras ()
		
	)--end bt_SelectCamera

	
	on bt_Render pressed do
	(
		cam = theCameras[list_cameras.selection]
		fnRender = render camera:cam vfb:false outputwidth:128 outputheight:256
		bt_Render.images = #(fnRender, undefined, 1,1,1,1,1 )
		fnRender
		)

)--END ROLLOUT

createdialog AutoCamera

or this:

try destroydialog ::AutoCamera catch()
	
Rollout AutoCamera "AutoCamera" width:155
(
	
	button bt_SelectCamera "Select Camera"   align:#left  height:30 width:130
	listbox list_cameras "" align:#left height:5 width:130
	button bt_render "Render" border:false align:#center width:206 height:256

	
	local theCameras = #()
	
	
	----FUNCTIONS----
	fn FilterCameras  obj = isKindOf obj camera
	
	fn selectCameras =
	(
		selCam = selectByName title:"Pick Camera" filter:FilterCameras showHidden:true
		if selCam != undefined then
		(
			theCameras = selCam
			list_cameras.items = for c in theCameras collect c.name
			)else(
			list_cameras.items = #()
			theCameras = #()
	
			)	
			print theCameras
	)--end fn selectCameras
	

	----EVENTS----	
	on AutoCamera open do
	(
		camName = $CAM_2_Front

		openSelCam = camName
		if openSelCam != undefined then
		(
			theCameras = openSelCam
			list_cameras.items = for c in theCameras collect c.name
			)else(
			list_cameras.items = #()
			theCameras = #()
		)
	)--end onOpen
	
	on bt_SelectCamera pressed do
	(
		if theCameras != undefined then selectCameras ()
		
	)--end bt_SelectCamera

	
	on bt_Render pressed do
	(
		cam = theCameras[list_cameras.selection]
		fnRender = render camera:cam vfb:false outputwidth:128 outputheight:256
		bt_Render.images = #(fnRender, undefined, 1,1,1,1,1 )
		fnRender
		)

)--END ROLLOUT

createdialog AutoCamera



2 Replies

To skip the target object:


camsARr = for o in cameras where classof o != targetobject collect o


Kostadin, thank you! Simple as that and working. I was doing a whole mess out of it but now it’s working.

Cheers!