My Scripting issues

I decieded to make my own thread for Lilly cause the other one is starting to get confusing.

Q1

how do I add a field chart?

I tried
node.add(node.root(),“FieldChartL”,“FIELDCHART”,0,0,0);
and
node.add(node.root(),“FieldChartL”,“FIELD-CHART”,0,0,0);

and neither worked.

I am guessing it might be element.add but I can’t figure to use that.

Q2 how do i access attributes of Pegs (and field charts when i add them).


I found i could

column.add(“Camera_Peg_Path”, “3DPATH”);
node.linkAttr(“Top/PegL”, “POSITION.3DPATH”, “Camera_Peg_Path”);
column.setEntry(“Camera_Peg_Path”, 1, 1, “1W” );

This works, but it now attached to the column forever it seems.
Is this going to create any problems? Is this the best way? How to I access the angles? Is there any documentation I could get (even if unofficial and not nicely formated) which lists all the possible variables attributes because the current scripting document is very under developed at the moment.

My goal is to automate the stereoscopic camera setup and then create a script to automate the camera rotation adjustments so they are perfect if you are wondering.


So far I have added everything,linked, set it out nice except the field charts. I can change the x values of pegs using the method above although i don’t know if this is the best way.

Just to give you an idea of what i am trying to do.

Okay sorry again for the late response. Here is how you add a field chart:

function createFieldChart()
{
node.add(node.root(), “fc1”, “FIELD_CHART”, 0, 0, 0);
}

You were close.

As for the document that lists all the variables, this is in the Scripting Template that you asked about. Let me know if you still need help with setting the peg to go 1W.

~Lilly
Toon Boom Support

Damn I can’t belive I didn’t try underscore. I feel embarassed, coders always replace dashes with underscores.

I am going to assume the column method i suggested (which worked) is not really a good way to do this because you can’t remove the columns.


So I started looking at the scripting template. I looked at peg and found the attributes which i will paste here































































Now I understand this are the attributes and what they are named, but how do I go about changing them using the scripting tools?

How would I move the peg, or change the enable3d to true?

I think once you give an example this template will be total gold for being able to do so much than i can currently do.

Okay I answered my question

You read the indents as “.” so for example to change the position of a Peg called PegL in the X axis 12 units i would

node.setTextAttr(“Top/PegL”, “POSITION.X”, 1, 12 );

but now I can’t seem to enable 3D so I am confused!

node.setTextAttr(“Top/PegL”, “ENABLE3D”, 1, “TRUE” );

I will keep playing. But things now make so much sense with the template. :smiley: :smiley: :smiley: :smiley:

OMG it is case senstive!!!
enable3d works!


So why in the scripts is there a general rule to uppercase all attributes? Is there a reason you do this?

But I answered all my scripting questions. I am really loving scripting now I know to get at everything!

edit:

Okay I tried changing some thigns to lower case and they don’t work. What is the uppercase./lowercase rules?

But I have new questions

Action.perform(“onActionChooseBrushTool()”); // this selects the brush tool

That selects the brush in your example. Can I have the commands for the other tools. It seems exciting the possibility of selecting the tools and automating mousemovent (like in the examples you gave a while back). This could be used to autocreate box/building shapes which would be totally awesome.

I also need to know about how to set frames for the attributes i am changing to finish my stereoscopic camera scipt.

Just so that you know it as a resource, you can view any of the slots by looking at the menus.xml file. This file is located in the Application folder > resources > menus.xml. Just read it with a text editor and you can see the slots.

I have included here the tools:


“onActionChooseBrushTool()”
“onActionChoosePencilTool()”
“onActionChooseTextTool()”
“onActionChooseEraserTool()”
“onActionChooseDropperTool()”
“onActionChooseMorphTool()”
“onActionChooseLineTool()”
“onActionChooseRectangleTool()”
“onActionChooseEllipseTool()”
“onActionChoosePolylineTool()”
“onActionChoosePaintTool()”
“onActionChooseCloseGapTool()”
“onActionChooseStrokeTool()”
“onActionChooseEditTransformTool()” text=“Edit Gradient/Texture”
“onActionChooseGrabberTool()”
“onActionChooseZoomTool()”
"onActionChooseRotateTool()"

When you ask about setting frames for your attributes, do you mean setting keyframes? I was about to post a separate post on that in the other thread, but maybe I’ll just continue that here since I think that was you that asked about it, right?

Regarding the case sensitivity, I am told that the attribute should be written exactly the way it is in the pdf. That is, enable3d should be just “enable3d”. However you’ve noticed that sometimes you can get away with leaving them all capitalised. The reason for this is that we used to always write things LIKE_THIS and so we kept that syntax there for backwards compatibility reasons. We want to be able to open files that were created in previous versions of the software. However we recommend that you use the same uppercase/lowercase that you’ll find in the pdf.

For example, ignoreParentPegScaling would be written exactly like that.

Now when it comes to booleans, there are two ways of defining booleans - true/false or yes/no. In the case of the enable3d attribute, it accepts a yes/no boolean. So when you do the setTextAttr command, make sure you use “Y” or “N”. Here’s an example:

function changeEnable3d()
{
var n = selection.selectedNode(0);
node.setTextAttr(n, “enable3d”, 0, “N”);
}



Okay, now regarding creating keyframes. I will write another post on this one very soon.

To add keyframes to animate an attribute of an element, there are a few things to be aware of. First is that there are several options an element can have that will affect the keyframes. For example, is the element on a 3D path or a separate path? Note that depending on this selection, the functions that you have available in the timeline will be different. Similarly, the functions that you will want to keyframe will be different. This is the same concept if you’re working with rotations in Euler vs. Quaternion, but for the moment I’m just going to do an example with the Path, then we can talk about angles if further clarification is needed.


function keyframePath()
{
var n = selection.selectedNode(0);
var s = node.getTextAttr(n, 0, “offset.separate”); //checks to see whether the node is Separate or 3D Path

if (s == “Off”)
//This section sets the keyframes for a 3D Path
{
node.setTextAttr(n, “offset.3DPATH.x”, frame.current(), 1);
node.setTextAttr(n, “offset.3DPATH.y”, frame.current(), 3);
node.setTextAttr(n, “offset.3DPATH.z”, frame.current(), 5);

//This example uses the current frame as the frame at which we want the keyframe to be set. Similarly, you could simply type in a value for the frame number.

}

else
//This section sets the keyframes for a Separate path
{
Action.perform(“onActionInsertKeyframe()”); //in this case we need to set a keyframe first because it won’t create a keyframe unless the function column already exists.
node.setTextAttr(n, “offset.x”, frame.current(), 1);
node.setTextAttr(n, “offset.y”, frame.current(), 2);
node.setTextAttr(n, “offset.z”, frame.current(), 3);
}
}


Do my comments in the above example help to illustrate how it works to create keyframes on a layer? Let me know if you need more help.

~Lilly
Toon Boom Support

Thank you. This answers my questions and gives me answers to future questions :slight_smile:

I will go right now and try to see if I can get it working. I have been looking foward to you getting back so I could finish this off :smiley:

3Dpath i got working easily however angles I can’t figure.

I am using quaternion so I figure I need to handle this the same way as 3d path. I searched the template and figured i need to use “quaternionpath” instead of “3dpath”.

This is the test script i made



node.add(node.root(),“PegM”,“PEG”,-10,-300,0);

node.setTextAttr(“Top/PegM”, “enable3d”, 1,“Y” );

node.setTextAttr(“Top/PegM”, “position.3dpath.x”, 1, 10 );
node.setTextAttr(“Top/PegM”, “position.3dpath.x”, 5, 5 );


frame.setCurrent(1);
// Action.perform(“onActionInsertKeyframe()”);
node.setTextAttr(“Top/PegM”, “rotation.quaternionpath.anglex”, frame.current(), 10 );

frame.setCurrent(1);
// Action.perform(“onActionInsertKeyframe()”);
// node.setTextAttr(“Top/PegM”, “rotation.quaternionpath.anglex”, frame.current(), 5 );



But i can’t seem to get it to work no matter what I try (i tried the second method too but I am sure it doesn’t work cause of the quaternion issue) Ignore the commented out lines they are just there for testing. The 3dpath part works fine.

I got it working for euler

selection.addNodeToSelection(“Top/PegM”);

frame.setCurrent(1);
node.setTextAttr(“Top/PegM”, “rotation.separate”, frame.current(), “false” );
Action.perform(“onActionInsertKeyframe()”);
node.setTextAttr(“Top/PegM”, “rotation.anglex”, frame.current(), 10 );



frame.setCurrent(5);
Action.perform(“onActionInsertKeyframe()”);
node.setTextAttr(“Top/PegM”, “rotation.anglex”, frame.current(), 5 );

one more unrelated question (sorry for so many questions!)

how can I get animate to select the actual frame in the timeline. I have been messing with your drawing examples and you need to select the actual frame before going to camera view to make it work. I need to select it in a script because I plan to make 6 drawings and turn them into a box. I can do everything to do it except the selecting of the frame

This is my attempt to select it (note vnode is the drawing and i can see that it is selected but it won’t work because the first frame isn’t also selected)

selection.clearSelection();
selection.addNodeToSelection(vnode);


Action.perform(“onActionChooseRectangleTool()”)

view.currentToolManager().scriptMouseDown(0, 0, 1, true);
view.currentToolManager().scriptMouseMove(1000, 1000, 1, true);
view.currentToolManager().scriptMouseUp(1000, 1000, 1, true);

TheRaider,

I’m afraid I’m going to need a little bit more time to get back to you on the Quaternion issue. I verified with the programmers that the Quaternions were added after the scripting interface was created, so there was no way of directly setting the angles for Quaternions like there is with Eulers. I apologise for the inconvenience here. I am told that there is a way to do it, however I am still waiting on an example script that I can make available to you.

Regarding selecting the correct frame for doing a drawing, I found that this, too, was not quite so straight forward. Because we have to actually send the selected CELL to the drawing view in order to draw, we cannot simply do a frame.setCurrent(), because this selects the current frame but not the cell.

What you need to do is create a loop to scroll to the desired cell. See the following example:

var ff;
Action.perform(“onActionMainGotoFirstFrame()”);
for(ff=1 ; ff<10 ; ++ff)
{
Action.perform(“onActionMainGotoNextFrame()”);
}
Action.perform(“onActionSendToDrawingView()”);


In this case, we’re interested in frame 10. So simply substitute whatever frame you’re interested in into the loop. This one should then work to create the drawing.

Let me know if that helps!

~Lilly
Toon Boom Support

That helps a lot thank you. I have got the 3d stereoscopic script working with eulers. So it now works I just have to be sure I am 100% doing the right thing.

You have helped me so much and thank you for that. I now feel really confident and can do so much with scripting. It is definitly much more powerful than most people would realise. Hopefully i can realise some of that potential and make some interesting scripts.

Okay I still can’t get it to select the actual cell. I used the method you suggested Lilly however it just moved the cursor up and down the timeline and didn’t select the actual cell.

I have a feeling it may be a problem with the selection because even when I use select all I can’t get any of the layers to turn blue (like they are selected).

Also I think i need to select camera view not drawing view (but i searched the menu file and there was only a sendtodrawingview not one for camera view). I think this problem might go away and not need to send to a view (if i leave it on camera view) all I need to do is select the area. I only want to select the first frame.

Here is what I have, you can see a few of the things i tried commented out although i tried lots more. I tried every function of the selection function too.

function QuickBox()
{

//Create new empty drawing

var elemname = “newdrawing”;
//elemname = elemname + “side1”;

var elemId = element.add(elemname, “BW”, scene.numberOfUnitsZ(), “SCAN”, “TVG”);
var vnode = node.add(node.root(), elemname, “READ”, 0, 0, 0);
column.add(elemname, “DRAWING”);
column.setElementIdOfDrawing(elemname, elemId );
node.linkAttr(vnode, “DRAWING.ELEMENT”, elemname);
node.link(vnode,0,“Top/Composite”,0);

//Select node

selection.clearSelection();
selection.addNodeToSelection(vnode);
//selection.addDrawingColumnToSelection(elemname);
//selection.selectAll();

Action.perform(“onActionSelEnable()”);

Action.perform(“onActionMainGotoFirstFrame()”);
//Action.perform(“onActionMainGotoNextFrame()”);
Action.perform(“onActionSendToDrawingView()”);

//draw rectangle

Action.perform(“onActionChooseRectangleTool()”);

view.currentToolManager().scriptMouseDown(0, 0, 1, true);
view.currentToolManager().scriptMouseMove(1000, 1000, 1, true);
view.currentToolManager().scriptMouseUp(1000, 1000, 1, true);

}

selection.setSelectionFrameRange(1,1); ← looks promising but it does nothing(visually) for me.

I will get back to you on the selection issue shortly.

I am glad that you got the Euler angles to work. It’s definitely easier to do it that way. If you still have the desire to poke around with Quaternions, I got a sample script for you on how to set a keyframe for a Quaternion. Clearly it’s much more complicated:


function myTest()
{
var ret;
var name = “myQuaternion”;
ret = column.type(name);
if (ret.isEmpty())
{
column.add(name, “QUATERNIONPATH”);
}
else if (ret != “QUATERNIONPATH”)
{
MessageLog.trace(“Error " + name + " defined and is not a quaternion path”);
return;
}
var x, y, z;
x = 0;
y = frame.current();
z = 23;
func.addKeyFrame3DPath(name, frame.current(), x, y, z, 0, 0, 0);
}

function myTest2()
{
if (selection.numberOfNodesSelected() != 1)
return;

var n = selection.selectedNode(0);
var t = node.type(n);
if (t != “PEG” && t != “READ”)
{
MessageLog.trace("must select a peg or a read selection: " + t);
return;
}
var ret;
node.setTextAttr(n, “enable3d”, 1, “Y”);
ret = node.setTextAttr(n, “rotation.separate”, 1, “N”);
var linked = node.linkedColumn(n, “rotation.quaternionpath”);

if (linked.isEmpty())
{
linked = node.getName(n) + “_quaternion”;
ret = column.add(linked, “QUATERNIONPATH”);
MessageLog.trace("add col returned " + ret);
ret = node.linkAttr(n, “rotation.quaternionpath”, linked);
}
MessageLog.trace("linked = " + linked + "node = " + n + " ret = " + ret);
var x, y, z;
x = 0;
y = frame.current();
z = 23;
func.addKeyFrame3DPath(linked, frame.current(), x, y, z, 0, 0, 0);

}

~Lilly
Toon Boom Support

Regarding the selection/draw script, I verified with the developer that the only way that he can make it work is to assign the script to two separate buttons. Also, you’re correct, the focus does have to be in the camera view. So if you have Focus on Mouse Enter enabled, then make sure that you attach your buttons to the camera view, or else turn off focus on Mouse Enter and you can leave the buttons on the scripting bar.

Here’s an example:

function QuickBox()
{
//Create new empty drawing
var elemname = “newdrawing”;
var elemId = element.add(elemname, “BW”, scene.numberOfUnitsZ(), “SCAN”, “TVG”);
column.add(elemname, “DRAWING”);
column.setElementIdOfDrawing(elemname, elemId );
var vnode = node.add(node.root(), elemname, “READ”, 0, 0, 0);
node.linkAttr(vnode, “DRAWING.ELEMENT”, elemname);
node.link(vnode,0,“Top/Composite”,0);

selection.clearSelection();
selection.addNodeToSelection(vnode);

Action.perform(“onActionMainGotoFirstFrame()”);
column.setEntry(elemname, 1, frame.current(), “1”);

}

function QuickBox2()
{
Action.perform(“onActionChooseRectangleTool()”);
view.currentToolManager().scriptMouseDown(0, 0, 1, true);
view.currentToolManager().scriptMouseMove(1000, 1000, 1, true);
view.currentToolManager().scriptMouseUp(1000, 1000, 1, true);
}

Let me know if that works for you.

~Lilly
Toon Boom Support