Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Set rotation of a new object in a for loop

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
nick
600 Views, 4 Replies

Set rotation of a new object in a for loop

(
	VRayStereoscopic pos:[0,0,0] isSelected:off
		$VRayStereoscopic001.eye_distance = 600
	
	
	rollout add_camera_rollout "Number of cameras needed."
	(
		edittext base_name ""
		button camera_count "Add new Cameras"
		on camera_count pressed do
		(
			if base_name.text != "" do
			(
				c_count = base_name.text as integer
				for i = 1 to c_count do
					i = Freecamera name:("CAM00" + i as string) isSelected:on pos:[0,0,1600]
					roti = eulerangles 90 0 0
					rotate i roti
				)--end on
		)--end rollout
	)
	createDialog add_camera_rollout 250 50
	
	--TODO user click in top view viewport for initial camera placements, cameras created on those positions
)

I'm trying to set objects 90 degrees on creation, in a for loop but keep getting "rotate" function not defined. I'm very new to MaxScript and setting a rotation seems quite difficult.

 

Tags (2)
4 REPLIES 4
Message 2 of 5
nick
in reply to: nick

Ahh, thanks to @martincoven on Twitter, I've found my mistake in i = Freecamera.... should be defined another name.

Message 3 of 5
Swordslayer
in reply to: nick

Not only that, there are several issue apart from reusing iterator variable that's invisible outside of the loop scope. First, you realize that this is not python and identical indentation is not enough, right? One-line statements are okay, but as it is now, the rotate whatever roti would only fire after the loop is completed, i.e. it would only affect the last created camera. Btw. in its current state, you'd create multiple nodes with the same name (CAM001, CAM0011 etc. - the fixed '00' prefix isn't the best solution either); use prefix:"CAM" instead of name: parameter, this will let max handle the numbering (and padding). Also, why use editText and go through the hassle of trying to interpret the text inside and cast it to integer (what if the text is "-"?) when you can use spinner instead (and switch it to integer values only). Then, if you are creating multiple cameras, why are you creating them with isSelected: on, this will effectively leave only the last created selected. Collect all of them and select the collection instead:

 

try destroyDialog ::add_camera_rollout catch()

rollout add_camera_rollout "Number of cameras needed." width:250 height:50
(
	spinner spnCount "Count: " range:[1, 1e6, 1] type:#integer fieldWidth:50 align:#center
	button btnAddCameras "Add new Cameras"

	on btnAddCameras pressed do select \
	(
		for i = 1 to spnCount.value collect
			FreeCamera prefix:"CAM" rotation:(eulerAngles -90 0 0) pos:[0, 0, 1600] 
	)
)
createDialog add_camera_rollout

Don't worry, that's not criticism, everyone has to start somewhere - but it's much better when you start doing things the right way as soon as possible. Old habits die hard 😉

Message 4 of 5
Swordslayer
in reply to: nick

Btw. if you want to do that with user input, have a look at scripted mouse tools (and mouse tool clauses). This should get you started:

 

try destroyDialog ::add_camera_rollout catch()

rollout add_camera_rollout "Number of cameras needed." width:250 height:50
(
	spinner spnCount "Count: " range:[1, 1e6, 1] type:#integer fieldWidth:50 align:#center
	button btnAddCameras "Add new Cameras"

	local cams = #()
	
	tool camPlacer
	(
		local cam
		local stopCount = spnCount.value + 1

		on start do free cams

		on mousePoint clickNo do
			if clickNo == stopCount then #stop else
			(
				cam = FreeCamera prefix:"CAM" rotation:(eulerAngles -90 0 0) pos:gridPoint
				append cams cam
			)

		on mouseMove clickNo do cam.pos = gridPoint
	)

	on btnAddCameras pressed do
	(
		startTool camPlacer
		select cams
	)
)
createDialog add_camera_rollout
Message 5 of 5
nick
in reply to: Swordslayer

Brilliant! Thank you, @Swordslayer I've learned a bunch from your two posts.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report