Skip to main content
Participant
May 11, 2013
Question

Looking to generate a GUID

  • May 11, 2013
  • 1 reply
  • 1327 views

Hey all, I'm sure it's really simple but I'm new-ish to After Effects and new to Javascript/Extendscript, but not to scripting in general.

Anyway, I'm trying to hack together a quick XML exporter to generate autodesk gateway clips. I need to assign a UUID/GUID to all my tracks. Google hasn't led me to the function. But I'm sure it's in there somewhere, right?  Heck, if anyone has done this already or has examples of writing out an XML based on footage or layers, please share!

While I'm asking for help, any XML usage guides out there? I'm used to elementTree and right now I'm hacking the XML together by appending the appropriate strings together which is rather...messy.

Any and all help is appreciated.

thanks,

Rick

This topic has been closed for replies.

1 reply

Inspiring
May 11, 2013

Hi Rick,

About the GUID there's this here:

http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript

What did you want to know about the XML? The whole structure is explained on the Autodsek website: http://wikihelp.autodesk.com/Smoke/enu/2013/Help/User_Guide/1198-Gateway_1198/1224-Creating1224

I did something similar last year even though it's still WIP: http://aescripts.com/layer-library

So if you have a specific question feel free to ask.

Kevin

rickg_laAuthor
Participant
May 13, 2013

Kevin,

Thanks for the guid link! Exactly what I need.  For some reason, my google searches seemed to turn up lots of junk, and not much usuable help this time.

I'm fine on the gateway clip format. I'm just new to javascript. If I could use python for this,  I'd be done and on the beach.  I have a standalone PyQt solution that does what I want, but thought it would be neat to incorporate it into After Effects so our CG artists can build a precomp and check it before sending a clip to the Flame artists, no other UI necessary.

I guess a specific question would be... is there an "elementTree" way of creating the elements, subelements, and attrs/values within javascript?

myRoot = eTree.Element('myRootElement')

myKid = eTree.SubElement(myRoot,'childElem')

myKid.attrib['myAttribute'] ='value'

My ignorance has led me to hacking strings of characters together to format everything. Not the best way I'm sure.

oh... one other question, is there a quick way to get a file sequence like it shows in the AE UI?

     mySeqOfImages.[0001-0100].exr

or better yet:

     a/path/to/my/images/mySeqOfImages.[0001-0100].exr

I'm currently using:

     name= File.decode(proj.item(i).file.name);

     path  = File.decode(proj.item(i).file.fsName);

     duration = proj.item(i).duration;

and I was going to hack it together. (yeah, I'm a hack)

thanks again,

Rick_

Inspiring
May 14, 2013

I never found the doc very good on XML, some stuff said in the documentation never worked for me, but it might be my fault ... But you should definitely read it to check what I'm saying.

I'm copy pasting stuff from my old code because I don't really remember all the details, this is my own way of doing things so maybe not the best.

To init an XML I'd either create it like xml = new XML() or if I already have most of the data I need:

xml = <propertySet><info>Created by Library {version}</info></propertySet>

... where version is a double.

Then, to keep things simple I'd append the data by constructing a subtree in another function:

xml.info += getLayerData();

This actually puts the layer data node at the same level as the info node (if I remember properly).

In getLayerData there would be a loop doing the same thing: appending the tree constructed for each layers. Same thing for each layer: there would be a loop on each keyframe, mask, effect, etc. I found this kept things clean and it was simpler to build the XML. Here's the function that gets the keyframes, all the other functions work more or less this way:

function getXMLForKeyframes(type, property)

{

          var xml = null;

          var tmp;

          if (property.numKeys > 0)

          {

                    var keyframe;

                    xml = <keyframes></keyframes>;

                    xml.interpolation = getKeyframeInterpolationType(property.keyframeInterpolationType);

                    for (var i=1; i<=property.numKeys; i++)

                    {

                              tmp = getXMLForKeyframe(type, property, i);

                              switch ( i )

                              {

                                        case 1:

                                                  //  Don't use += if the node is empty or you'll create an extra empty field

                                                  xml.keyframes = tmp;

                                                  break;

                                        default:

                                                  xml.keyframes += tmp;

                                                  break;

                              }

                    }

          }

          return xml;

}

To add a property to the xml, you just have to do xml.propertyName = content , and content can be about anything.

To add a field to the XML tag, do xml.@fieldName = value, and value only should be a number or string I guess.

Concerning the file paths, I think fsName of the best way to go but I'm not sure why you use decode on it. If you want something OS-dependent use fsName otherwise I think it's path. Just try them all and combine them as you were planning to do, I wouldn't call any of that a hack.