[Closed] Maxscript xml
Can someone please show me how i could go about reading this simple file in max script. i know .net can parse xml but i only got to the sub headers i could not figure out how to get the data out to parse.
<Skeleton>
<Bone Count="100">
<Item Index="0" Parent="-1" Name="Bip01" Center="0.000000,0.000000,0.000000" Size="8.000000,8.000000,8.000000" />
<Item Index="1" Parent="0" Name="Bip01 Footsteps" Center="0.000000,0.000050,0.000000" Size="6.000000,0.000050,6.000000" />
<Item Index="2" Parent="0" Name="Bip01 Pelvis" Center="0.000000,0.000000,0.000000" Size="0.300000,0.500000,0.300000" />
<Item Index="3" Parent="2" Name="Bip01 Spine" Center="0.500000,0.000000,0.000000" Size="0.425000,0.724997,0.450000" />
<Item Index="4" Parent="3" Name="Bip01 Spine1" Center="0.500000,0.000000,0.000000" Size="0.425000,0.774984,0.450000" />
<Item Index="5" Parent="4" Name="Bip01 Spine2" Center="0.500000,0.000000,0.000000" Size="0.425000,0.824972,0.450000" />
<Item Index="6" Parent="5" Name="Bip01 Neck" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="7" Parent="6" Name="Bip01 Head" Center="0.490063,-0.000054,0.091191" Size="0.515948,0.337866,0.521123" />
<Item Index="8" Parent="7" Name="toufa Bone01" Center="0.048665,0.000000,0.000000" Size="0.048665,0.025000,0.025000" />
<Item Index="9" Parent="8" Name="toufa Bone02" Center="0.052099,0.000000,0.000000" Size="0.052099,0.025000,0.025000" />
<Item Index="10" Parent="7" Name="toufa Bone03" Center="0.053079,0.000000,0.000000" Size="0.053079,0.025000,0.025000" />
<Item Index="11" Parent="10" Name="toufa Bone04" Center="0.055967,0.000000,0.000000" Size="0.055967,0.025000,0.025000" />
<Item Index="12" Parent="11" Name="toufa Bone05" Center="0.070166,0.000000,0.000000" Size="0.070166,0.025000,0.025000" />
<Item Index="13" Parent="7" Name="zuiba Bone01" Center="0.029401,0.000000,0.000000" Size="0.029401,0.010000,0.010000" />
<Item Index="14" Parent="7" Name="yanjing Bone02" Center="0.013005,0.000000,0.000000" Size="0.013005,0.005000,0.005000" />
<Item Index="15" Parent="7" Name="yanjing Bone01" Center="0.013005,0.000000,0.000000" Size="0.013005,0.005000,0.005000" />
<Item Index="16" Parent="6" Name="Bip01 L Clavicle" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="17" Parent="16" Name="Bip01 L UpperArm" Center="0.500236,0.001358,0.005163" Size="0.500528,0.119708,0.155942" />
<Item Index="18" Parent="17" Name="Bip01 L Forearm" Center="0.500469,0.000936,-0.000265" Size="0.499404,0.103618,0.111453" />
<Item Index="19" Parent="18" Name="Bip01 L Hand" Center="0.500000,0.000000,0.000000" Size="0.500000,0.400000,0.100000" />
<Item Index="20" Parent="19" Name="Bip01 L Finger0" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="21" Parent="20" Name="Bip01 L Finger01" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="22" Parent="21" Name="Bip01 L Finger02" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="23" Parent="19" Name="Bip01 L Finger1" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="24" Parent="23" Name="Bip01 L Finger11" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="25" Parent="24" Name="Bip01 L Finger12" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="26" Parent="19" Name="Bip01 L Finger2" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="27" Parent="26" Name="Bip01 L Finger21" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="28" Parent="27" Name="Bip01 L Finger22" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="29" Parent="19" Name="Bip01 L Finger3" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="30" Parent="29" Name="Bip01 L Finger31" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="31" Parent="30" Name="Bip01 L Finger32" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="32" Parent="17" Name="Bip01 L ForeTwist" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="33" Parent="32" Name="Bip01 L ForeTwist1" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="34" Parent="16" Name="Bip01 LUpArmTwist" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="35" Parent="34" Name="Bip01 LUpArmTwist1" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="36" Parent="6" Name="Bip01 R Clavicle" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="37" Parent="36" Name="Bip01 R UpperArm" Center="0.500236,-0.001358,0.005163" Size="0.500528,0.119708,0.155942" />
<Item Index="38" Parent="37" Name="Bip01 R Forearm" Center="0.500469,-0.000936,-0.000265" Size="0.499404,0.103618,0.111453" />
<Item Index="39" Parent="38" Name="Bip01 R Hand" Center="0.500000,0.000000,0.000000" Size="0.500000,0.400000,0.100000" />
<Item Index="40" Parent="39" Name="Bip01 R Finger0" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="41" Parent="40" Name="Bip01 R Finger01" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="42" Parent="41" Name="Bip01 R Finger02" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="43" Parent="39" Name="Bip01 R Finger1" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="44" Parent="43" Name="Bip01 R Finger11" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="45" Parent="44" Name="Bip01 R Finger12" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="46" Parent="39" Name="Bip01 R Finger2" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="47" Parent="46" Name="Bip01 R Finger21" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="48" Parent="47" Name="Bip01 R Finger22" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="49" Parent="39" Name="Bip01 R Finger3" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="50" Parent="49" Name="Bip01 R Finger31" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="51" Parent="50" Name="Bip01 R Finger32" Center="0.500000,0.000000,0.000000" Size="0.500000,0.200000,0.200000" />
<Item Index="52" Parent="38" Name="dun prop1" Center="0.331161,0.000000,0.000000" Size="0.331161,0.025000,0.025000" />
<Item Index="53" Parent="37" Name="Bip01 R ForeTwist" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="54" Parent="53" Name="Bip01 R ForeTwist1" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="55" Parent="36" Name="Bip01 RUpArmTwist" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="56" Parent="55" Name="Bip01 RUpArmTwist1" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="57" Parent="5" Name="Back prop3" Center="0.759684,0.000000,0.000000" Size="0.759684,0.025000,0.025000" />
<Item Index="58" Parent="5" Name="Back prop1" Center="0.759684,0.000000,0.000000" Size="0.759684,0.025000,0.025000" />
<Item Index="59" Parent="5" Name="Back prop2" Center="0.759684,0.000000,0.000000" Size="0.759684,0.025000,0.025000" />
<Item Index="60" Parent="3" Name="Bip01 L Thigh" Center="0.499446,-0.004722,0.000967" Size="0.498698,0.117011,0.199663" />
<Item Index="61" Parent="60" Name="Bip01 L Calf" Center="0.499020,0.001325,-0.008422" Size="0.500094,0.113047,0.133326" />
<Item Index="62" Parent="61" Name="Bip01 L Foot" Center="0.500000,0.000000,0.300000" Size="0.500000,0.500000,0.500000" />
<Item Index="63" Parent="62" Name="Bip01 L Toe0" Center="0.500000,0.000000,0.500000" Size="0.500000,0.500000,0.500000" />
<Item Index="64" Parent="60" Name="Bip01 LCalfTwist" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="65" Parent="64" Name="Bip01 LCalfTwist1" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="66" Parent="3" Name="Bip01 R Thigh" Center="0.499446,0.004722,0.000967" Size="0.498698,0.117011,0.199663" />
<Item Index="67" Parent="66" Name="Bip01 R Calf" Center="0.499020,-0.001325,-0.008422" Size="0.500094,0.113047,0.133326" />
<Item Index="68" Parent="67" Name="Bip01 R Foot" Center="0.500000,0.000000,0.300000" Size="0.500000,0.500000,0.500000" />
<Item Index="69" Parent="68" Name="Bip01 R Toe0" Center="0.500000,0.000000,0.500000" Size="0.500000,0.500000,0.500000" />
<Item Index="70" Parent="66" Name="Bip01 RCalfTwist" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="71" Parent="70" Name="Bip01 RCalfTwist1" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="72" Parent="3" Name="Back prop4" Center="0.759684,0.000000,0.000000" Size="0.759684,0.025000,0.025000" />
<Item Index="73" Parent="3" Name="Back prop5" Center="0.759684,0.000000,0.000000" Size="0.759684,0.025000,0.025000" />
<Item Index="74" Parent="3" Name="Bip01 LThighTwist" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="75" Parent="74" Name="Bip01 LThighTwist1" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="76" Parent="3" Name="Bip01 RThighTwist" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="77" Parent="76" Name="Bip01 RThighTwist1" Center="0.500000,0.000000,0.000000" Size="0.500000,0.100000,0.100000" />
<Item Index="78" Parent="2" Name="yao Bone08" Center="0.068535,0.000000,0.000000" Size="0.068535,0.025000,0.025000" />
<Item Index="79" Parent="78" Name="yao Bone09" Center="0.089430,0.000000,0.000000" Size="0.089430,0.025000,0.025000" />
<Item Index="80" Parent="2" Name="yao Bone10" Center="0.068535,0.000000,0.000000" Size="0.068535,0.025000,0.025000" />
<Item Index="81" Parent="80" Name="yao Bone11" Center="0.089430,0.000000,0.000000" Size="0.089430,0.025000,0.025000" />
<Item Index="82" Parent="2" Name="yao Bone15" Center="0.083795,0.000000,0.000000" Size="0.083795,0.025000,0.025000" />
<Item Index="83" Parent="82" Name="yao Bone16" Center="0.085210,0.000000,0.000000" Size="0.085210,0.025000,0.025000" />
<Item Index="84" Parent="83" Name="yao Bone17" Center="0.073268,0.000000,0.000000" Size="0.073268,0.025000,0.025000" />
<Item Index="85" Parent="2" Name="yao Bone12" Center="0.081601,0.000000,0.000000" Size="0.081601,0.025000,0.025000" />
<Item Index="86" Parent="85" Name="yao Bone13" Center="0.095028,0.000000,0.000000" Size="0.095028,0.025000,0.025000" />
<Item Index="87" Parent="86" Name="yao Bone14" Center="0.076974,0.000000,0.000000" Size="0.076974,0.025000,0.025000" />
<Item Index="88" Parent="2" Name="yao Bone04" Center="0.099116,0.000000,0.000000" Size="0.099116,0.025000,0.025000" />
<Item Index="89" Parent="88" Name="yao Bone05" Center="0.105132,0.000000,0.000000" Size="0.105132,0.025000,0.025000" />
<Item Index="90" Parent="2" Name="yao Bone18" Center="0.083795,0.000000,0.000000" Size="0.083795,0.025000,0.025000" />
<Item Index="91" Parent="90" Name="yao Bone19" Center="0.085210,0.000000,0.000000" Size="0.085210,0.025000,0.025000" />
<Item Index="92" Parent="91" Name="yao Bone20" Center="0.073268,0.000000,0.000000" Size="0.073268,0.025000,0.025000" />
<Item Index="93" Parent="2" Name="yao Bone01" Center="0.079739,0.000000,0.000000" Size="0.079739,0.025000,0.025000" />
<Item Index="94" Parent="93" Name="yao Bone02" Center="0.083761,0.000000,0.000000" Size="0.083761,0.025000,0.025000" />
<Item Index="95" Parent="94" Name="yao Bone03" Center="0.075965,0.000000,0.000000" Size="0.075965,0.025000,0.025000" />
<Item Index="96" Parent="2" Name="yao Bone06" Center="0.099118,0.000000,0.000000" Size="0.099118,0.025000,0.025000" />
<Item Index="97" Parent="96" Name="yao Bone07" Center="0.105132,0.000000,0.000000" Size="0.105132,0.025000,0.025000" />
<Item Index="98" Parent="0" Name="Bip01 Prop1" Center="0.000000,0.500000,0.000000" Size="0.500000,0.500000,0.500000" />
<Item Index="99" Parent="0" Name="Bip01 Prop2" Center="0.000000,0.500000,0.000000" Size="0.500000,0.500000,0.500000" />
</Bone>
</Skeleton>
check out Paul Neal’s tuts if you haven’t already
Yes i read his tutorial and I Found one other tutorial the farthest i got was
getting the listener to print the main child nodes.
If i see an example of reading a file like this I would be very happy.
These are good tutorials tho thank you.
I will try his tutorials more it is getting late here ma bee i just can not think right now.
If you not want to mess with dotNet xml parser, may design your own reader.
Here’s some ‘on-the-fly’ pseudo code (not tested atm), just as idea:
xml = openFile "Skeleton.xml" mode:"r"
if readLine xml == "<Skeleton>" do
(
next = filterString (readLine xml) "<>\"="
if next[1] == "Bone Count" do
(
boneCount = next[2]
for i = 0 to boneCount-1 do
(
next = filterString (readLine xml) "<>\"/"
vIndex = next[2] -- or >> vIndex = i
vParent = next[4]
vName = next[6]
vCenter = next[8]
vSize = next[10]
-- do whatever here... or just collect the data
)
)
)
close xml
This should dump the contents out, tweak the xmldoc.load() call if your data is in a buffer.
testdatafilename = (getfilenamepath (getsourcefilename())) + "testdata.xml"
xmldoc = dotnetobject "System.XML.XMLDocument"
xmldoc.load testdatafilename
itemIter = (xmldoc.selectnodes "//Skeleton/Bone/Item").GetEnumerator()
while itemIter.MoveNext() do
(
format "
Entry:
"
attrIter = itemIter.Current.Attributes.GetEnumerator()
while attrIter.MoveNext() do
(
format " % = %
" attrIter.current.Name attrIter.current.value
)
)
.NET’s not that bad
.biddle
What you are looking for is getAttribute, this function will get the attribute value by name. The value is returned as a string and will need to be converted to the value type that you need in max. This can be done in many cases with execute.
Thanks all for your help. This is exactly what i was looking for. There are many ways to do one thing as shown here and they are all great.
Another alternative for the pot is to use LINQ to XML. I found this method much less cumbersome to use IMHO than navigating a XML tree manually via the XMLdocument method.