( 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.
Solved! Go to Solution.
Solved by Swordslayer. Go to Solution.
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 😉
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