View Full Version : Select objects through loop??
Gibbz 10-27-2005, 11:04 AM 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 "%\n" 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\n" loop
format "% dummy selection\n" tempdummy
dummy_pivot = $tempdummy.pivot
--f = dummy_loop
--dummy_pivot = selection[(f as string)f].pivot --get pivot value
format "%\n" dummy_pivot to:output_file --format of output
--dummy_loop = dummy_loop + 1
--)
close output_file
-- edit ("c:\dummys.txt")
|
|
j-man
10-27-2005, 01:35 PM
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 "\t%\t%\n" h.name h.transform -- format the transform (to a file?)
)
)
Moosley
10-27-2005, 01:41 PM
or this :)
output_file = createfile ("c:\dummys.txt") --output to path
for h in helpers where matchPattern h.name pattern:"Dummy*" do format "%\n" 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'.
Jeff_hanna
10-27-2005, 01:42 PM
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 "%\t%\r\n" 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
Gibbz
10-27-2005, 10:54 PM
ok sweet, thanks guys :)
ill check it out tonight after work.
Gibbz
10-28-2005, 09:20 AM
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 :)
Gibbz
10-28-2005, 11:19 AM
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 "%\t%\r\n" 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
magicm
10-28-2005, 12:51 PM
Hi Gibbz,
Try replacing this line :
meshshop.getvert Box01 1 --Box01 is my object
with :
meshshop.getvert $Box01 i --Box01 is my object
Martijn
Gibbz
10-28-2005, 01:34 PM
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\tuts\tut3_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 "%\t%\r\n" i (myVertex/39.37) to:output_file --divide to convert from max to meters
)
close output_file
stuh505
10-28-2005, 02:08 PM
uh...it's meshop not meshshop
CGTalk Moderation
10-28-2005, 02:08 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.