Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / Parsing String Data
  RSS 2.0 ATOM  

Parsing String Data
Rate this thread
 
22123
 
Permlink of this thread  
avatar
  • Location: Quebec City, QC -- Canada
  • Total Posts: 53
  • Joined: 28 August 2006 10:51 PM

I am at my wits end with this, perhaps I am going about it all wrong, it is late and I cannot think straight anymore.

I trying to get the vertex count of exported data.

The exported data is a collada.xml file.

so what i did, and perhaps this is my misake, I approached it from the angle of parsing the collada file and generating an array of all lines (this worked very well for getting number of bones etc)

loc_readXML = (dotnetClass "System.IO.File").ReadAllLines XMLFile -- convert xml to ARRAY OF STRINGS

(Btw, eternal gratitude to Paul Neale for this)

Then I know that I have iterate thru that array and find an index that contains the following string:

<float_array id="Teapot01-mesh-positions-array" count="1590">

easy enough, I run 2 checks, one for “<float_array id=” and the second check for “mesh-positions-array”, this results in the correct indeces being returned.

In my test file, there are 2 objects, so I get 2 hits, so far so good.

the problem is that all i need is that “1590” above and the corresponding value from the other index (it is “24” btw, not that it matters)

trimleft and trimright don’t work too well,since there will be arbritary names added where is says “teapot01”, and there is a large number of vertex positions after the count="1590">, for example: count="1590">0.0 -0.165 0.124 etc

ALL I NEED IS TO GET THAT 1590 as an integer!

I am sorry I am exausted.

MB

please help if you can.....



Replies: 0
avatar

Here is ONE possible approach (there are many)

--This is the original string, yours will be from the file:
str = “<float_array id=\"Teapot01-mesh-positions-array\" count=\"1590\">"

theFS = filterString str “ =<>\"” --First tokenize it by splitting by the main characters used to delimit the content
theIndex = findItem theFS “count” --Then find where the count string is:
theCount = if theIndex > 0 and theIndex < theFS.count then --if it is found and not the last,
theFS[theIndex+1] as integer --grab the entry right after it and convert to integer
else -1 --otherwise returns -1 to denote the count could not be read



Borislav “Bobo” Petrov

Replies: 0
avatar
  • Location: Quebec City, QC -- Canada
  • Total Posts: 53
  • Joined: 28 August 2006 10:51 PM
  • Permlink of this post

Borislav Petrov 01 February 2009 04:30 AM

Here is ONE possible approach (there are many)

--This is the original stringyours will be from the file:
str "<float_array id=\"Teapot01-mesh-positions-array\" count=\"1590\">"

theFS filterString str " =<>\""  --First tokenize it by splitting by the main characters used to delimit the content
theIndex = findItem theFS "
count"  --Then find where the count string is:
theCount = if theIndex > 0 and theIndex < theFS.count then  --if it is found and not the last,
    theFS[theIndex+1] as integer --grab the entry right after it and convert to integer
else -1 --otherwise returns -1 to denote the count could not be read

Thank you sir, that did it!

Not that I am complaining, but the “FilterString” functions should also be defined in the “String Parser Methods” in the Maxscript help files, IMHO anyways.

Again, thank you,

MB



Replies: 0
avatar

Historically speaking, the “String Parser Methods” were a separate bunch of functions implemented in GMax 1.0 and then integrated into Max 5, which explains why they are on a separate page. The FilterString() had nothing to do with them.

But of course you are right that there should be some form of obvious cross linking between the two topics, or the String Parser Methods page could be completely integrated into the String Values topic.

I would rather just add linking since the String Values topic is rather long as it is…

Thanks for the feedback!



Borislav “Bobo” Petrov

Replies: 0