[Closed] How to output a node's properties to a file?
Hi guys!
My question is:How to output a node’s properties to a file?
For instance, first,I got a box and I want to know the values of all its properties then output the values to a file.
Second, I read the values form the file to create a new box with the same parameters.
So how to do it?
I suppose we can use this method: showProperties <node> as the following:
a = box()
showProperties a
.height : float
.length : float
.lengthsegs : integer
.width : float
.widthsegs : integer
.mapcoords : boolean
.heightsegs : integer
.realWorldMapSize : boolean
And what am I gonna do next?
I mean these only the names of properties and how to get the values one by one?
And this is my code below. I wanna get the properties of the selection’s material.
What’s my problem?
-- collect material properties
fn collectMatPros mat matProsArray =
(
-- output properties to a stringStream
local tempMat = mat,
theStrStream = stringStream ""
showProperties tempMat to:theStrStream
-- convert stream to string;then filter the string
local theStr = theStrStream as string,
tempArray = filterString theStr "
",
theArray = #()
for i in tempArray do
if i[1] == "." do -- if it's so,it's a property
(
local subTempArray = filterString i ".(/)"
for j in subTempArray do
(
local matProStr = "tempMat." + j,
proValue = execute matProStr
if classOf proValue != arrayParameter do
if proValue != undefined do
(
append theArray j
append theArray proValue
)
)
)
)
-- test
matProsArray = #()
collectMatPros $.mat matProsArray
--print matProsArray
this should get you started:
for i in (getPropNames $) do format “%: %: %
” (i as string) (getProperty $ i) (classof (getProperty $ i))
you can use the setINISetting and getINISetting to write to your own ini file.
You will need the class of the property so you can do things like “true” as booleanclass as the getINISettingreturns values as strings
Thank you! Your method is much easier than mine. I got a crazy way to do this!
I’m very luck to see your reply.I’m a lucky man!
:bounce:
If you are interested in using XML files for the data storage have a look at my dotNet tutorials as I have an example file that stores data about objects in the scene and writes it all out to an XML formated file.