[Closed] Select objects through loop??
im trying to select dummy01 grab the pivot, write to file, then grab the next dummy in the scene.
Having real issues selecting a dummy using a string. Ive included my script, which is a mess in its current state. Ive tryed a few things, but im fairly new ot max script and need some help.
Heres the code.
total_dummys = 2 –set to number of dumys in scene
dummy_loop = 1
–tempdummy = selection[1] –create refrence to get pivot from
output_file = createfile (“c:\dummys.txt”) –output to path
– dummy_pivot = tempdummy.pivot –get pivot value
–format “%
” dummy_pivot to:output_file –format of output–for loop = 1 to total_dummys do
–(loop=1 tempdummy = "dummy0" + (loop as string) --convert loop to a string format "% Loops
” loop
format “% dummy selection
” tempdummydummy_pivot = $tempdummy.pivot --f = dummy_loop --dummy_pivot = selection[(f as string)f].pivot --get pivot value format "%
” dummy_pivot to:output_file –format of output
–dummy_loop = dummy_loop + 1–)
close output_file
– edit (“c:\dummys.txt”)
Hi Gibbz,
This will help you along your way!
for h in helpers do -- iterate through all of the helpers in the scene
(
if (classof h==dummy) and (isgrouphead h==false) then -- check to see that the object is a dummy, and not a group head
(
format " % %
" h.name h.transform -- format the transform (to a file?)
)
)
or this
output_file = createfile ("c:\dummys.txt") --output to path
for h in helpers where matchPattern h.name pattern:"Dummy*" do format "%
" h.pivot to:output_file
close output_file
Additional: If your dummy object is not a standard helper and is instead a mesh called dummy, just swap ‘helpers’ in the above code for ‘objects’.
Helpers and classOf() are your friends in this case. Helpers is a virtual array that contains every helper object in the scene. ClassOf will tell you the class of whatever you pass in as a parameter.
To do things only to any dummies in the scene you can loop over Helpers and check each member to see if it’s a dummy. If so, act upon it.
for MyHelper in Helpers do
(
if classOf MyHelper == Dummy then
(
<do stuff>
)
)
So, to grab all the dummies in a scene and write their pivot information to a file the script would be:
output_file = createfile "c:\dummys.txt"
for MyHelper in Helpers do
(
if classof MyHelper == Dummy then
(
format “% %
” MyHelper.name MyHelper.pivot to:output_file
)
)
close output_file
That creates the file c:\dummy.txt and writes the name and pivot (seperated by a tab) of every dummy in the scene to the file
Ok guys, that works fine, but max doesnt seem to use meters(ive setup the scene to be in meters, but it outputs an max units)…
Is there a way to output as meters? ive tryed addig the following…
units.MetricType #Meters
but it doesnt seem to help.
Edit: ok i found a hack, just divide by 39.37…
Thanks for your helkp guys
Ok trying ot make a variation of the script that get all the vertecis in a editpoly mesh and writes t othe file in the same way…
units.MetricType #Meters
output_file = createfile "c:\dummys.txt"
myVerts = $.numverts
-- subobjectLevel = 1 --converts to vertex mode
-- $.EditablePoly.SetSelection #Vertex #{1} --select vertex 1
for i = 1 to myVerts do
(
meshshop.getvert Box01 1 --Box01 is my object
format "% %
" MyHelper.name (MyHelper.pivot/39.37) to:output_file --divide to convert from max to meters
)
close output_file
But the getVert never works, it only ever spits out errors, even when trying things in the listener
Thanks
Hi Gibbz,
Try replacing this line :
meshshop.getvert Box01 1 –Box01 is my object
with :
meshshop.getvert $Box01 i –Box01 is my object
Martijn
Hey thanks I put it in but im still getting an error
the following error
<File:c:\dummys.txt>
8
-- Error occurred in i loop; filename: D:\Program Files\Autodesk\3dsMax8\Scripts uts ut3_grabvertcoords.ms; position: 268
-- Frame:
-- i: 1
-- myVertex: undefined
-- meshshop: undefined
-- Unknown property: "getVert" in undefined
OK
OK
my updated code…
units.MetricType #Meters
output_file = createfile "c:\dummys.txt"
myVerts = $.numverts
--subobjectLevel = 1 --converts to vertex mode
--$.EditablePoly.SetSelection #Vertex #{1} --select vertex 1
for i = 1 to myVerts do
(
myVertex = meshshop.getvert $Box01 i --Box01 is my object
format "% %
" i (myVertex/39.37) to:output_file --divide to convert from max to meters
)
close output_file