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: 

Script Help

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
581 Views, 7 Replies

Script Help

Hello All,

I'm trying to combine 3 small pivot scripts into One, so that I can cycle threw each with one keystroke. I quite literally have ZERO experiance with MaxScript, have tried to google search, youtube, and read the information about it.. But i'm completly lost, and cant seem to get these to all work together... Can anyone possibly help me out?

 

(Below are the 3 scripts):

 

($.pivot.z = $.min.z )

Macroscript CenterPivot

($.pivot.z = $.max.z)

 

Honestly, I'm not even quite sure if I wrote the first and last correctly, as i get a script error when I click it with nothing selected. 😕

 

Thanks for any input,

Regards,

 

Nolan

7 REPLIES 7
Message 2 of 8
Steve_Curley
in reply to: Anonymous

1st and last are valid, middle would be "centerPivot $"
However, yes - all 3 will fail if there's no object currently selected, that's one good reason for not using "$" in scripts. At the very least you must ensure that the script doesn't run if nothing is selected, and at the same time account for more than 1 object being selected.
(for obj in selection do (obj.pivot.z = obj.min.z))
(for obj in selection do (centerPivot obj))
(for obj in selection do (obj.pivot.z = obj.max.z))
They will do nothing if the selection collection is empty (nothing is selected).
Or if you only want it to work when 1 object (not more or less, just 1) then
(if selection.count == 1 then (selection[1].pivot.z = selection[1].min.z))
(if selection.count == 1 then (centerPivot selection[1]) 
(if selection.count == 1 then (selection[1].pivot.z = selection[1].max.z))

As for cycling through them with a single keystroke (like the Region Selection toolbar button does) I don't know. I don't think you can create flyout toolbar buttons like that (though I could be wrong). It might be possible to script an imitation of that, but that would probably mean creating a global variable to track the current "option" and increment it when it's done. Probably easier to just create 3 scripts with a different shortcut for each.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

Message 3 of 8
Anonymous
in reply to: Steve_Curley

Thanks for the Reply Steve! Much appriciated.

 

Regarding the cycling threw. I'm not really looking to create any UI for the script. I mainly just want to assign a keystroke to the routine. I was thinking it would look somthing like this (if it was even possible).

 

Set pivot to obj.Min.z, if pivot is set to obj.min.z, set to centerPivot, if set to centerPivot obj, set to obj.max.z

 

I guess i really just dont know the coding language to try it, and I dont really understand how to add variables like, "If X is X do X".

Message 4 of 8
Steve_Curley
in reply to: Anonymous

Ok, which version do you want? All selected or only allow it to work if there's just one?

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

Message 5 of 8
Anonymous
in reply to: Steve_Curley

just one object selected would be PERFECT!

Message 6 of 8
Steve_Curley
in reply to: Anonymous

Here you go 🙂

(
if selection.count == 1 then
	(
	local obj = selection[1]
	if obj.pivot.z == obj.min.z then
		obj.pivot.z = obj.max.z
	else
		if obj.pivot.z == obj.max.z then
			centerPivot obj
		else
			obj.pivot.z = obj.min.z
	)
)

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

Message 7 of 8
Anonymous
in reply to: Steve_Curley

DUDE!! YOU ARE MY **** HERO!!!

I've been trying to get this figured out for months! lol *facepalm*

Message 8 of 8
Steve_Curley
in reply to: Anonymous

No worries 🙂
Slight modification - insert this line at the top of the script (in the Maxscript Editor) and execute it (Ctrl+E) once. Then go to Customise > Customise User Interface > Keyboard (tab). Change the Category dropdown to ScriptTools, highlight the PivotMover and add a shortcut key. Makes life easier 🙂

macroScript PivotMover category:"ScriptTools" tooltip:"Pivot Mover" Icon:#("Maxscript",1)

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

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

Post to forums  

Autodesk Design & Make Report