Forum Groups
  All forums
    Help & Feedback
      Questions
      Work in progress
      Finished Art
      Non-Max related
    Community
      Offtopic
      News
    Hardware
    Photography


Featured Threads
  inspiration alert!!!
(36 replies)
  Indespensible MaxScripts, Plugins and 3rd Party Tools
(37 replies)
  The allmighty FREE Resources Thread !
(17 replies)
  spam alert!!!
(4886 replies)
  Maxforums member photo gallery index
(114 replies)
  Maxforums Member Tutorials
(89 replies)
  three cheers to maxforums...
(240 replies)
  101 Things you didnt know in Max...
(198 replies)
  A Face tutorial from MDB101 :D
(95 replies)
  Maxforums.org Members Gallery
(516 replies)
  SON OF POST YOURSELF
(637 replies)
  Dub's Maxscript Tutorial Index
(119 replies)

Maxunderground news unavailable

Need help with script, align axis to objects on min Z and move object to Z=0 without changing X and Y
show user profile  dvaillancourt@forgefx.com
I’m trying to create a 2 button script that does 2 things.
1. I’d like the first button to take the selected object and align it’s own axis it’s Z minimum value.
2. I’d like the 2nd button to take the selected object and move it to world coordinate Z=0 without changing its’ current X and Y values.

For 1., I’m totally lost, this is all I have...

max hierarchy mode --enter hierarchy mode
actionMan.executeAction 0 "40113" --affect pivot only??
max align --activate align tool
x=0,y=0,z=1 --effect only the Z coordinates
current object=pivot --use the current object's pivot point
target object=minimum --use the target object's (itself) minimum value

For 2. I feel like I’m close but I can’t get it to work without changing the X and Y coordinates...

toolMode.coordsys #world
max move
$Zpos = [0] -- Here I’d like the object to move to Z=0 in relevance to the world coordinates without it affecting the X and Y coordinates.

Here's the full code...

rollout object_tool "Put Object at Z=0"
(
button btn1 "Axis to Btm" pos:[10,6] width:90 height:20


on btn1 pressed do
(
if selection.count == 0 then (MessageBox "No objects selected" title:"Error")
else
if (selection.count >= 1) do --if selection more then 1 object
(
FixArray = #() --creates empty array
for o in selection do -- do to all objects
(
(
append FixArray o --adds to fixArray
)-- End If
)-- End For

c = 1
while c <= FixArray.count do --while c is bigger then the selectioncount
(
--************here's where the code breaks obviously I don't fully know what I'm doing***************
--max hierarchy mode --enter hierarchy mode
--actionMan.executeAction 0 "40113" --affect pivot only
--max align --activate align tool
--x=0,y=0,z=1 --effect only the Z coordinates
--current object=pivot --use the current object's pivot point
--target object=minimum --use the target object's (itself) minimum value
--c += 1
)

)
)
button btnl2 "Obj to 0" pos:[110,6] width:90 height:20

on btnl2 pressed do -- this button will align the axis for any object selected.
(
if selection.count == 0 then (MessageBox "No objects selected" title:"Error")
else
if (selection.count >= 1) do --if selection more then 1 object
(
FixArray = #() --creates empty array
for o in selection do -- do to all objects
(
(
append FixArray o --adds to fixArray
)-- End If
)-- End For

c = 1
while c <= FixArray.count do --while c is bigger then the selectioncount
(
toolMode.coordsys #world
max move
$.pos = [n,n,0] --here's the 2nd point on which the code breaks, I'm trying to move the object to Z=0 without effecting its X and Y coords.
c += 1
)

)
)
)
theNewFloater = newRolloutFloater "Shockwave Tools2" 224 62
addRollout object_tool theNewFloater


read 909 times
4/25/2008 6:26:44 PM (last edit: 4/25/2008 6:26:44 PM)
show user profile  $$T-bone$$
have you tried adding a code for "hierarchy panel" ---> "reset transform"
i understand that your looking for a code that does not affect the X and Y coordinates but, can you just reset thier coordinates to Zero at the end of the code?




read 894 times
4/25/2008 7:50:45 PM (last edit: 4/25/2008 7:50:45 PM)
show user profile  Toen
Does this work the way you want?

1. $.pivot.z=$.min.z
2. $.position.z=0.0
read 874 times
4/25/2008 11:57:31 PM (last edit: 4/25/2008 11:57:31 PM)
show user profile  Headphones_John
>> 1. $.pivot.z=$.min.z
>> 2. $.position.z=0.0

looks about right...

Try this little script to auto locate the pivot to axis min/max points (your first function) http://www.hpjohn.com/PivotAlign.ms
----------

Website is permanently under construction

http://www.hpjohn.com

read 845 times
4/26/2008 10:28:02 AM (last edit: 4/26/2008 10:28:02 AM)
show user profile  Catman
the length of your name is messing with my ocd


read 825 times
4/26/2008 2:38:14 PM (last edit: 4/26/2008 2:38:14 PM)
show user profile  dvaillancourt@forgefx.com
Thanks for you're help all. I'll post the final script here once I get the UI set.

read 787 times
4/28/2008 8:31:05 AM (last edit: 4/28/2008 8:31:05 AM)
show user profile  dvaillancourt@forgefx.com
Acutally, I found a bug with the code. I've traced it down to the $.pos = [0,0,0] comand. The bug is that this command doesn't work when the object selected is a group. The only work around I could find was to first open the group, then select the group without selecting the geometry within the group. Anyone have any ideas on how to get $.pos = [0,0,0] for a grouped object without having to open the group?

read 776 times
4/28/2008 10:10:33 AM (last edit: 4/28/2008 10:10:33 AM)
show user profile  Toen
This should work. I wasn't sure how you were going to be making selections of things so what it does is check if there is something selected first, if there is then check to see if multiple items are selected or not. If multiple items are selected then it checks to see if they are part of a group or not, if so it handles it as a group, if not then as a selection of multiple nodes that aren't grouped. If only one time is selected then it works as before.

"[$.pos.x,$.pos.y,0.0]" and "[groupHead.pos.x,groupHead.pos.y,0.0]" can be changed to to "[0,0,0]" to zero all the values out.



if ($!=undefined and $selection.count>1) then (
if (isGroupMember $[1]) then (--selection of Grouped objects
groupHead=undefined-- will hold head object of Group
for obj in $ while groupHead==undefined do (--Search for/Get Group head object
if (isGrouphead obj) then (groupHead=obj)
)
--Move Group pivot point to local minimum z value of Group bounding box
groupHead.pivot.z=$.min.z
--Move Group to 0.0 Z position in world while keeping X/Y values the same
groupHead.pos=[groupHead.pos.x,groupHead.pos.y,0.0]
) else (--selection of non-grouped objects
for obj in $ do (
--Move selected object(s) pivot to local minimum z value of it's bounding box
obj.pivot.z=obj.min.z
--Move selected object(s) to 0.0 Z position in world while keeping X/Y values the same
obj.pos=[obj.pos.x,obj.pos.y,0.0]
)
)
) else (--selection of a single obj
--Move selected obj pivot to local minimum z value of it's bounding box
$.pivot.z=$.min.z
--Move selected obj to 0.0 Z position in world while keeping X/Y values the same
$.pos=[$.pos.x,$.pos.y,0.0]
)

read 765 times
4/28/2008 1:34:14 PM (last edit: 4/28/2008 1:44:54 PM)
show user profile  dvaillancourt@forgefx.com
This is excellent, thank you very much. Your new script does work with grouped objects as expected.
I think the final detail to get working is to get it to work when there are multiple groups selected. Is that possible?

-Thanks

read 750 times
4/28/2008 2:40:50 PM (last edit: 4/28/2008 2:40:50 PM)
show user profile  Toen
Ok try this, should work regardless if the selection is a bunch of groups, just a bunch of single objects, or a collection of both groups and single objects, single group, or single object.

if ($selection.count>0) then (
--Collect all Group heads and non-Group objects into single array for modification (pivots/position)
objSelection = for obj in $selection where (isGroupMember obj)!=true collect obj
for obj in ObjSelection do (
--Move selected obj/Group pivot to local minimum z value of it's bounding box
obj.pivot.z=obj.min.z
--Move selected obj/Group to 0.0 Z position in world while keeping X/Y values the same
obj.pos=[obj.pos.x,obj.pos.y,0.0]
)
)
read 738 times
4/28/2008 3:37:26 PM (last edit: 4/28/2008 3:57:26 PM)
show user profile  dvaillancourt@forgefx.com
Perfect. Thanks again.

Here's the final tool set that I've put together...
http://www.forgefx.com/temp/shockwave-tools.ms

I wanted to post the actual code, but the max forum croaked when I hit submit. Perhaps it's too long. So if you want it, you'll have to download it. It's got a lot of nice tools to align your axis's properly and have your objects placed properly for game engines.

read 728 times
4/28/2008 4:03:10 PM (last edit: 4/28/2008 4:03:10 PM)
show user profile  Toen
np!
read 702 times
4/29/2008 2:12:38 PM (last edit: 4/29/2008 2:12:38 PM)
#Maxforums IRC
Open chat window


Support Maxforums.org