[Closed] How do you do file output with MaxScript?
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:
[left]for obj in $ do
[/left]
[left](
[/left]
[left]obj.modifiers[#turbosmooth].iterations = 1
[/left]
[left]obj.modifiers[#turbosmooth].useRenderIterations = true
[/left]
[left]obj.modifiers[#turbosmooth].renderIterations = 2
[/left]
[left])
[/left]
It returns this error
– Syntax error: at ), expected <factor>
– In line: )
I have no idea what it’s talking about with regards to “<factor>”.
[left]
[/left]
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>.[b]wirecolor[/b]
For parents just use:
objectParent = <object>.[b]parent[/b]
Check out the General Node Properties section of the maxscript help for more.
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) + "
") to:INIFile
)
close INIfile
)
)
outToINI outToFile "c:\ est.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.
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. [i]EDIT: I stand corrected! Thanks Christopher![/i]
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
)
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!
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