-
Nulls from pins then parent the pins to eachother script
Hi, i’m building my first script and need a little bit of help… I’m trying to make it so I get the null’s from pins and connect them as controllers. Then parent the nulls to eachother, but making the top most null.parent=null
I’ve got the first part working.
app.beginUndoGroup("Create Nulls for Pins");var theComp = app.project.activeItem;
if (theComp == null || !(theComp instanceof CompItem)){
alert(errorNoCompSelected);
} else {
var theLayers = theComp.selectedLayers;if (theLayers.length==0) {
alert(errorNoLayerSelected);
} else {
for (var i = 0; i < theLayers.length; i++){
var curLayer = theLayers[i];
// condition 1: must be a footage layer
if (curLayer.matchName == "ADBE AV Layer"){
//condition 2: must be a 2D layer
if (!curLayer.threeDLayer) {
//condition 3: must have puppet pins applied
if (curLayer.effect.puppet != null) {
var wherePins = curLayer.property("Effects").property("Puppet").property("arap").property("Mesh").property("Mesh 1").property("Deform");
var pinCount = wherePins.numProperties;
for (var n = 1; n <= pinCount; n++) {
// Get position of puppet pin
try {
var pin = curLayer.effect("Puppet").arap.mesh("Mesh 1").deform(n);
//var solid = theComp.layers.addSolid([1.0, 1.0, 0], nullName, 50, 50, 1);
var solid = theComp.layers.addNull();
//solid.name = pin.name + "_ctl";
solid.name = curLayer.name + "_" + pin.name;
//~~~~~
//scaled from layer coords to world coords
var p = pin.position.value;
solid.property("position").setValue(harvestPoint(p, curLayer, solid, "toComp"));
//~~~~~~
var pinExpr = "fromComp(thisComp.layer(\""+solid.name+"\").toComp(thisComp.layer(\""+solid.name+"\").anchorPoint));";
pin.position.expression = pinExpr;
} catch(err) {}
}
curLayer.property("Effects").property("Puppet").property("On Transparent").setValue(1);
curLayer.locked = true;
} else {
alert("Layer must have puppet pins.");
}
} else {
alert("Layer must be 2D.");
}
} else {
alert(errorFootageOnly);
}
}
}
}app.endUndoGroup();
and i’m trying to combine it with
{
for (var i = 0; i < theLayers.length; i++){
if (i == 0) {
for (var j = 0; j < theLayers.length; j++){
if(theLayers[i].parent==theLayers[j]) theLayers[i].parent=null;
}
} else {
theLayers[i].parent = null;
theLayers[i].parent = theLayers[i-1];
}
}
But for the life of me, I can’t get it work correctly. I would of included it into the creation of the null objects but then the others don’t exists so I’m unable to parent them. Also creating it after the nulls have been created I’m not sure how to select the nulls to parent them together. I thought of trying to find their names and parent them one at a time, but it hasn’t worked for me yet
Any help on this would be amazing