Help needed with Spline to XML script
I'm actually working on a script which should export several splines to XML so a game (Shogun 2) can use it.
Since I'm a total Newbie regarding maxscript - everything I know was learned today by trial and error with a script I've found which already exports splines to xml but It would need some modifications.
- what it should do -
I need the script for exporting splines to a format which the game Shogun 2 is using (for a mod). Soldiers are using those splines as guide where to stand within buildings. Therefore some information are need like position of the knots, which type (in my example "low wall") and in which direction the spline is "facing"
- what my script actually does -
At the moment I select one spline, run the script and in the Listener I type exportasxml ("example.xml") which then gives me the file. But the script would have to write few hundred entries. Which code do I have to write that I can export severel selected splines at once?
Next thing:
-- what type the EF line is for i= 1 to k do
Because of this my script actually loops through all knots of a spline (which are only two) and so it writes two identical entries.
I tried
for i= 1 to $.count
so it instead loops through the selected splines and writes one entry for each spline, but atm it doesn't work.
Another question would be, if it's possible to get the "direction" in which a spline is facing?
Here an example what I actually get by using the code and how it should look like:
http://i304.photobucket.com/albums/nn166/Primergy/erklaumlrung_zps39517b8b.jpg
And here's the script for a quick look:
global theFileStream fn printToFile theString t:0 = ( -- auto tab (empty string) tabString = " "; tabString = substring tabString 1 (t*4); -- print format "%%\n" tabString theString to:theFileStream; ) fn exportAsXML fileName = ( theFileStream = createFile fileName; -- ok to write? if theFileStream != undefined then ( -- reference to selected shape s = selection[1] k = numKnots s knots = k as String cl = isClosed s 1 as String -- open printToFile ("<building_logic>") -- building defence type printToFile ("<building_defence_type>open</building_defence_type>") -- EF_lines printToFile ("<ef_lines>") -- what type the EF line is for i= 1 to k do ( local actiontype = getUserPropBuffer $ -- root node printToFile ("<ef_line name='"+ s.name +"' action=' "+ actiontype +"'>") for i= 1 to k do (knot = getKnotPoint s 1 i x = knot.x as String y = knot.y as String z = knot.z as String printToFile ("<end x='" + x +"'y='"+ y +"'z='"+ z +"'/>") )) printToFile ("<direction x='" + knots + "' y='" + knots + "' z='" + knots + "'/>") printToFile ("</ef_line>") -- ef_lines close printToFile ("</ef_lines>") --write artillery printToFile ("<ef_artillery_info>") --close artillery PrintToFile ("</ef_artillery_info>") -- close printToFile ("</building_logic>") ) close theFileStream; )