eduardo simioni

Tag: maxscript

sharing files between 3dsMax and Motionbuilder

by on Oct.28, 2013, under 3ds Max, ini, maxscript, MotionBuilder, pipeline, python, xml

Here’s a small tip on where to quickly put files (ini or xml for example) that you can easily fetch from both Max:


And Motionbuilder:

import os

Both will return “C:\Users\USER\AppData\Local”. And if you ever wondered what’s the difference between /AppData/Local and AppData/Roaming this might shed some light on it:

Leave a Comment :, , , , , , more...

scale all the things!

by on Aug.16, 2012, under 3ds Max, maxscript, pipeline

Here’s a nice trick my mate at Funcom, Endre Eikrem, told me. You can scale everything, scene, mesh, skin, rig, animation, with this simple code:

units.SystemScale = 0.5
units.SystemScale = 1.0
fetchMaxFile useFileUnits:false quiet:true

You just need to have “Respect System Unit in Files” activated, inside Customize/Unit Setup/System Unit Setup. That’s it!

Except! There’s always some exception. So far we found a couple of stuff that are not scaled with this trick:

  • Wire Parameters. They are strings, so it’s expected that Max doesn’t scale them.
  • Key Tangents. If tangents were manually edited they are not going to be scaled. On the other hand, animation keys are scaled correctly.
  • Float Limit Controller. It’s value is not scaled.

There might be other exceptions, but so far these are quite easy to workaround with Maxscript. Specially if your rig is simple. On Funcom rigs, we just needed to parse Orientation_Constraint controllers and edit their wire parameters to the FK/IK handle. Float_Limit controller is just a matter of finding it and setting a new value based on the units.SystemScale used. And key tangents are not to worry if you first bake/plot the animation on the handles. Keyframes being scaled, it works flawlessly.

If anyone trying this out find any more exceptions please let me know.

2 Comments :, , , , , , more...

xml with dotnet on maxscript

by on Apr.25, 2011, under 3ds Max, pipeline, xml

Paul Neale has a very good tutorial about dotnet and maxscript, specially reading and writing xml, but I decided to add some more information from a slightly different approach. First, let’s translate an XML to dotnetesque:

    <element1 />
    <element2 attributeName="attribute content">
        <element2.1>innerXML of this element</element2.1>

And the entire document is a XmlDocument (instance of dotNetObject “System.Xml.XmlDocument“)

There are many ways to read and write XML with dotnet. If you need to read the whole document first, probably the most optimized is by using XmlParser, but it can be a bit of a pain. If you are using Maxscript you are not doing it in realtime, so a couple miliseconds won’t make that much of a difference.

Anyway, if you are looking for specific information inside tags you can easily do it using .GetElementsByTagName:

	XmlDoc = dotNetObject "System.Xml.XmlDocument"
	XmlDoc.load "D:\\Characters\\Rider\\exportEMFX.xml"

	-- I know <baseCharacter> has only one entry, so I get the first one
	tagBaseChar = XmlDoc.GetElementsByTagName "baseCharacter"
	baseCharacter = (tagBaseChar.item 0).InnerXML
	-- I don't know how many <file>s there is, so I get them into an array
	tagFiles = XmlDoc.GetElementsByTagName "file"
	fileList = (for i=0 to (tagFiles.count-1) collect (tagFiles.item i).InnerXML)

To read something like:


Note that GetElementsByTagName doesn’t care about hierarchy, it just finds the element you are looking for, no matter where in the tree it is or how many times it’s repeated. If you have a “file” under “filesToLoad” and also under “filesToSave” it won’t differentiate between them.

If you have a tree/graph structure and you don’t know each tag name one solution is to recourse through it all loading them on a dictionary or array.

Say you have an hierarchy structure you want to save, together with their layers, into an XML. You can store the data in two arrays with:

this two are recursive functions to return the hierarchy in a single array
fn GetHierarchyTree lParent =
	toRet = #(
	for o in lParent.children do
		append toRet (GetHierarchyTree o)
fn GetLayerTree lParent =
	toRet = #(
	for o in lParent.children do
		append toRet (GetLayerTree o)

this is just an example, you shouldn't use globals like this
global parentTree = #()
global layerTree = #()

gets the data into parentTree and layerTree
fn getData =
	for o in objects where o.parent == undefined do
		append parentTree (GetHierarchyTree o)
		append layerTree (GetLayerTree o)

To save this into an XML you also go with recursion:

fn recurseTreeToXML baseNode xmlDocNew pTree lTree =
    for i=1 to pTree.count do
		-- if it's a leaf, there's data, so we append
        if (isKindOf pTree[i] String) then
            curNode = xmlDocNew.CreateElement pTree[i]
            curNode.SetAttribute "layer" lTree[i]
            baseNode.appendChild curNode
            baseNode = curNode
        else -- it's a branch with more data underneath
            recurseTreeToXML baseNode xmlDocNew pTree[i] lTree[i]
fn saveDataOnXML =
	-- you cannot append elements to an xmldoc
	-- you have to append elements to a single root element, child of xmldoc
    xmlDocNew = dotNetObject "System.Xml.XmlDocument"
    xmlRoot = xmlDocNew.CreateElement (getFilenameFile maxfilename)
    xmlDocNew.appendChild xmlRoot
    recurseTreeToXML xmlRoot xmlDocNew parentTree layerTree ("C:\\temp\\test.xml")

And also to read an XML:

fn recurseXML docElement =
	tempPTree = #(
	tempLayerTree = #(docElement.getAttribute "layer")
	for i = 0 to (docElement.childNodes.count - 1) do
		tmp = (recurseXML docElement.childNodes.itemOf[i])
		append tempPTree tmp[1]
		append tempLayerTree tmp[2]
	return #(tempPTree, tempLayerTree)

global parentTreeXML = #()
global layerTreeXML = #()
fn readXML =
	xmlDoc = dotNetObject "System.Xml.XmlDocument"
	xmlDoc.load ("C:\\temp\\test.xml") 
	docElement = XmlDoc.documentElement
	-- if we don't do this here we end up with the root node on parentTreeXML
	-- which can be worked out in anoter way also, of course.
	for i = 0 to (docElement.childNodes.count - 1) do
		tmp = (recurseXML docElement.childNodes.itemOf[i])
		append parentTreeXML tmp[1]
		append layerTreeXML tmp[2]

Remember, besides dotnet help website, showproperties and showmethods are your best friends. You can also copy this code and paste on maxscript editor or jedit or somewhere with a syntax highlighter to better read it.

1 Comment :, , , , , , , more...

reading/writing xml with python and maxscript

by on Mar.09, 2011, under pipeline

If you know where to find the information it becomes quite straight forward if you are not doing anything complex. With python you can use xml.dom.minidom, while with maxscript you can use either .NET Object “System.Xml.XmlDocument” or Class “System.Xml.XmlReader“.

With python you create a root element and append child elements from there. A very good sample can be found on: To read you have getElementsByTagName on both python and dotnet XmlDocument. XmlReader might be a bit faster, but you have to parse elements by yourself.

There’s an issue with minidom’s toprettyprintxml, it adds whitespace and tabs between tags, around textNodes. And they are obviously read afterwards. A couple of different solutions are discussed on Ron Rothman’s blog, the easiest one using xml.dom.ext.PrettyPrint.

Leave a Comment :, , , , more...

make Biped FK Keyframes

by on Jan.13, 2011, under 3ds Max

Biped uses a weird nomenclature for IK/FK. Another evening I was helping a friend from Mystic that needed all biped keyframes in FK. This is just a quickie script to collapse/bake/plot biped to make them from “planted” (IK) to “free” (FK).

fn makeBipedFK = 
    for o in objects where (classof o == Biped_Object) do
        for i=1 to o.controller.keys.count do
            k = biped.getKey o.controller i
            if (isproperty k "ikBlend") then
                k.ikBlend = 0
                k.ikSpace = 0
                k.ikAnkleTension = 0
                k.ikJoinedPivot = false

Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!