PDA

View Full Version : How do you do file output with MaxScript?


RoleXXX
04-09-2007, 10:09 PM
I have this problem where I have to output certain attributes to a "log file" from objects in a scene.

The output must include the name, SuperClass, # of verts/edges/faces, object color, and the object parent.

I typed "showproperties$" on a basic sphere, and box and couldn't find any of the properties I was looking for. Is there another way to access the above properties?

Any tutorials or tips in the right direction would be helpful, thank you.

As an aside, I was doing tutorials by Dubs and Nick Clark. I entered in the following script from the tutorial:


for obj in $ do

(

obj.modifiers[#turbosmooth].iterations = 1

obj.modifiers[#turbosmooth].useRenderIterations = true

obj.modifiers[#turbosmooth].renderIterations = 2

)



It returns this error
-- Syntax error: at ), expected <factor>

-- In line: )

I have no idea what it's talking about with regards to "<factor>".

erilaz
04-10-2007, 12:41 AM
For vert/face count, I don't think there is a way to do it to a primitive, short of converting it to a mesh/ePoly. EDIT: I stand corrected! Thanks Christopher!

For object color just use:
objectColor = <object>.wirecolor

For parents just use:
objectParent = <object>.parent

Check out the General Node Properties section of the maxscript help for more.

Anubis
04-10-2007, 12:56 AM
As far as querying the stuff, here are the different properties:
outToFile = #()
for obj in $ do
(
append outToFile obj.name --name
append outToFile obj.verts.count --number of verts
append outToFile obj.faces.count --number of polys
append outToFIle obj.edges.count --number of edges
append outToFile (classOf obj) --class
append outToFile obj.wirecolor --object color
append outToFile obj.parent --parent node
append outToFile "--"
)
As to how you output that to a file, I read in and out files by line, associating them with the array element, but I think maxScript has an INI file in/out system, here is a sample of what I mean:

fn outToINI data path echo =
(
if doesfileexist path == false then
(
INIFile = createFile path
for i = 1 to data.count do
(
if echo == true then
(
print data[i]
)
format ((data[i] as string) + "\n") to:INIFile
)
close INIfile
)
)

outToINI outToFile "c:\\test.txt" false

You basically step through the array and write each line to disk. You can then add to this fn by making it check if the file exists, if so you need to open that file for writing, and also check to see if it's read only and make it -r if you want, but this is the basics, and I may be doing some things wrong, this is a simplified version of the way I do it. I also have a fn that reads in files to an array, allowing me to insert/replace stuff and export it again.

RoleXXX
04-10-2007, 02:43 AM
Thank you very much both of you. That was extremely useful!

Anubis
04-10-2007, 10:15 AM
erilaz: For vert/face count, I don't think there is a way to do it to a primitive, short of converting it to a mesh/ePoly. EDIT: I stand corrected! Thanks Christopher!
Nah erilaz you were right! I just ignored that, you can write a fn like you said that puts an edit poly mod on top then gets the info then removes it, here below i tried to do it super fast, my execute didnt work, and rather than troubleshoot it I did a case. Also, I couldn't delete the mod, and even when using "getModifierIndex" it couldn't find the editPoly, so it needs more than 3 minutes of troubleshooting but you get the idea...
fn getGeo obj type =
(
output = ""
addModifier obj (Edit_Poly ())
case type of
(
"faces": output = obj.faces.count
"verts": output = obj.verts.count
"edges": output = obj.edges.count
)
--return (execute ("obj." + type + ".count"))
--deleteModifier obj (Edit_Poly ())
return output
)

erilaz
04-10-2007, 01:29 PM
Phew! I'm glad we cleared that up! Here I was thinking I was going crazy! Thanks for responding Christopher. I would have gone nuts trying to work out why I couldn't do it! :D

Anubis
04-10-2007, 07:15 PM
Actually, now that I remember, you can access it like this:

$.mesh.verts.count

regardless of whether or not it's a 'non-mesh' like a box or sphere without having to toss a mesh select on top or the like.

Does anyone know why many people toss meshselects on non-meshes to get at their vert indices when it appears you can just do it like this:

getvert $.mesh 140

CGTalk Moderation
04-10-2007, 07:15 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.