Klaas Nienhuis
Klaas Nienhuis, a 3d-generalist, projectmanager, programmer and a guy who figures stuff out.
Twitter updates
- @SketchFab i was wondering where that traffic came from! Thank's, this will help to convince my clients to start using this even more. 1 day ago.
- Our model of maison d'artiste on @sketchfab is picking up some crazy traffic lately: http://t.co/DF0gPodh @dpianimation #webgl 1 day ago.
- Had a great talk with @namshee about @gathercontent, our experience with it and ideas for the future 1 day ago.
- RT @DpiAnimation: DPI is kennispartner van @nrc! Lees ons artikel over #configurators & #masscustomization op het NRC-blog: http://t ... 4 days ago.
- @SketchFab sure, thanks for the link. 1 week ago.
- @SketchFab done already! Klaasnienhuis.nl Any plans for a private viewing environment 1 week ago.
- Maison d'artiste by klaasnienhuis http://t.co/DF0gPodh via @sketchfab @naimuseum 1 week ago.
- launch #drezzd http://t.co/SuVeZhru shirts. #3d content by @dpianimation #3dsmax #masscustomization #apparel #configurator 1 week ago.
Article archive
- May 2012 (1)
- March 2012 (1)
- February 2012 (11)
- January 2012 (3)
- December 2011 (4)
- November 2011 (4)
- October 2011 (4)
- September 2011 (4)
- August 2011 (3)
- July 2011 (1)
- June 2011 (1)
- March 2011 (2)
- February 2011 (3)
- December 2010 (2)
- November 2010 (1)
- September 2010 (8)
- August 2010 (1)
- July 2010 (3)
- June 2010 (2)
- April 2010 (1)
- March 2010 (1)
- February 2010 (1)
- January 2010 (2)
- November 2009 (2)
- May 2009 (1)
- October 2008 (2)
- September 2008 (1)
XPath and xml in maxscript for 3dsMax
XPath provides a fast and flexible system of looking through your xml-files. It’ll help you find the node or nodes you need quickly. This is also supported in maxScript. I learned a lot on the w3Schools site on xpath and other xml-related stuff. Let’s do a few examples:
xpath examples
Last modified on 2011-09-25 15:24:44 GMT. 0 comments. Top.
Xpath example for 3dsMax
I’ll use a sample xml from the w3Schools site (get it here)
Next up some xpath queries which should function in maxscript
Put the xml above in a file called “bookstore.xml”
In maxscript enter the following lines
This will load up the xml-file in the xmlDoc variable. Now we’re ready to do some xpath magic!
--1 Get all books myNodes = xmlDoc.selectNodes "//book" --2 Get all childnodes of the bookstore element myNodes = xmlDoc.selectNodes "/bookstore/*" --3 Get all authors of all books myNodes = xmlDoc.selectNodes "//book/author" --4 Get all authors of books from 2005 myNodes = xmlDoc.selectNodes "//book[year='2005']/author" --4a do the same but the year is a variable yearVariable = 2005 myNodes = xmlDoc.selectNodes ("//book[year='" + (yearVariable as string) + "']/author") --5 Get all books from 2005 myNodes = xmlDoc.selectNodes "//book[year='2005']" --6 Get all books from 2003 cheaper than 45.00 myNodes = xmlDoc.selectNodes "//book[year='2003' and price<'45']" --In examples 3 and 4 you do something like this to get the actual text of the xml-element in an array myAuthors = (for i = 0 to myNodes .count-1 collect myNodes .itemOf[i].innertext) --In examples 1, 2, 5 and 6 you get an xml-element with child-elements. Do something like this to get a specific child-element myPrices = (for i = 0 to myNodes.count-1 collect (myNodes.itemOf[i].getElementsByTagName "price").itemOf[0].innertext)These examples are pretty simple and only use a fraction of what’s possible with xpath. However this is more than enough for my purposes and has helped me a lot in working with xml files. Example 4a also shows you can build up these xpath queries with variables. Don’t get confused with the single and double quotes!
Also check out the examples on the xpath documentation site.
For some real xml and maxscript kungfu check out Pete Addington’s site: http://lonerobot.net/
For a nice breakdown of xml in maxscript check out Paul Neale’s tutorials here and here.