Python script for importing object transformation info into Maya


#1

[SIZE=2]Dear Gurus of computer-wisdom.[/SIZE]

Python script :How to get the XML data into the right attribute channels of the objects (rotateX, rotateY… and so on)"?

For animation purpose I imported geometry into Maya. Together with it I imported xml-data with the transformation information of these objects. (Transformation, rotation, scaling). I managed to get both into Maya but I have problems to put the Information from the XML into the attribute channel of the equivalent object.

The XML is parsed with an Python-script I found in the Internet, but my knowledge of scripting is still very limited. I haven’t managed to modify the script sufficiently to associate the XML-info to the objects.

Here is what a I have achieved so far:

  1. Import obj objects from another application into maya (6 cubes for testing)
  2. import and parse an XML-file with the transformation info in it. I used a script described by Matthew Murray.
    [VIMEO]30939939[/VIMEO]

The script loads the XML fine and displays the transformation values with the print function.
What I haven’t achieved is to plug the parsed values into the attribute channel of the equivalent object.
Could someone have a look and give me a hint how to solve the problem. Mockery on the way is Ok. Thanks in advance

Python script:

import xml.dom.minidom as xd
import maya.cmds as cmds

class readXML():

def __init__(self):
    
    path = 'C:\\Users\\blabla\\Desktop\\Temp\\GH-Export.xml' 
    print(path)
    
    xFile = xd.parse(path)
    
    elements = xFile.getElementsByTagName('Ctrl')
    #searches for Tagname 'Ctrl'
    print(elements)
    for e in elements:
        attrs = e.attributes.keys()
        for a in attrs:
            pair =e.attributes[a]
            print('Name is ' + str(pair.name) + ' Values is ' + str(pair.value))

inst =readXML()


XML:

<?xml version=“1.0” ?>
<pose>
<Ctrl ctrlName=“Cube0” rotateX=“0.0” rotateY=“0.0” rotateZ=“0.0” scaleX=“0.0” scaleY=“0.0” scaleZ=“0.0” translateX=“0” translateY=“0” translateZ=“0” visibility=“True”/>
<Ctrl ctrlName=“Cube1” rotateX=“1.1” rotateY=“10.1” rotateZ=“100.1” scaleX=“1.01” scaleY=“10.01” scaleZ=“100.01” translateX=“1” translateY=“10” translateZ=“100” visibility=“True”/>
<Ctrl ctrlName=“Cube2” rotateX=“2.2” rotateY=“20.2” rotateZ=“200.2” scaleX=“2.02” scaleY=“20.02” scaleZ=“200.02” translateX=“2” translateY=“20” translateZ=“200” visibility=“True”/>
<Ctrl ctrlName=“Cube3” rotateX=“3.3” rotateY=“30.3” rotateZ=“300.3” scaleX=“3.03” scaleY=“30.03” scaleZ=“300.03” translateX=“3” translateY=“30” translateZ=“300” visibility=“True”/>
<Ctrl ctrlName=“Cube4” rotateX=“4.4” rotateY=“40.4” rotateZ=“400.4” scaleX=“4.04” scaleY=“40.04” scaleZ=“400.04” translateX=“4” translateY=“40” translateZ=“400” visibility=“True”/>
<Ctrl ctrlName=“Cube5” rotateX=“5.5” rotateY=“50.5” rotateZ=“500.5” scaleX=“5.05” scaleY=“50.05” scaleZ=“500.05” translateX=“5” translateY=“50” translateZ=“500” visibility=“True”/>
</pose>


#2

You have the element name “Cube0”, the channel called “rotateX” and a value like 93.5.
The most obvious way would be to combine these informations like this:

cmds.setAttr(elementName + "." + channelName, value)


#3

Thanks mate.

I have tried that. The problem is the script doesn’t differ between an object name, channelname and value the right way.
So to speak “ctrl” or “rotateX” a.s.o .are tags the script searches for and stores it in “pair.name”.
“Cube3” or “40.4” are stored in"pair.value"

So I guess I would need to change the script in the way that it finds “Cube0…5” as the object name seperately and not as a value amongst many others.If that is understandable.

Any ideas?