Forum Replies Created
-
Michael Müller
October 11, 2018 at 5:45 pm in reply to: Extendscript: Changing Effect Values via ExpressionsAlright, that is already great news.
I still don’t understand why my script won’t apply the expression to the Point Controls.
I am too much of a beginner to understand everything that is in there. I basically patched it together from different pieces I found, asked for or did a little research to complete it.Now what is interesting is that the function won’t react in any way to Point Controls at all if I delete Line 71, which says
“if(!property.canSetExpression) return;”
If I keep the line in, the slider for “X” appears and has the [0] value. However, no expression is applied and the slider doesn’t do anything, as opposed to using the script on a “regular” property, where all necessary sliders appear and work the way they should.I’d kiss your feet Dan if you could tell me what is wrong in my code here and how I can fix it. I’d just love to have this damn script finished. It already is quite useful as it is but it would be the bomb if there wasn’t this bug with Point Controls. I know I should have started with the basics of scripting instead of begging for help with stuff I have no clue of, but now I got already this far and the goal is near.
Thanks a lot
Michael
-
Michael Müller
October 11, 2018 at 1:30 pm in reply to: Extendscript: Changing Effect Values via ExpressionsThis is what I want the outcome to be like, yes. Only that this is triggered by a js file. I added the code I was able to get so far to make it more clear.
The code generates as many sliders as the array length says, and adds information to what it’s linked to in the slider name.
This works for normal properties like Position and Anchor Point, and also for scale (which was the main reason I started the entire thing)
However, it would be nice to be able to separate the dimensions of Effect Point Controls too. This doesn’t seem to work for some reason. Only one slider is generated and no expression is applied to the property! Which made me think that these kind of properties might fall under the !.canSetExpression exception.I hope this makes the issue more clear.
Michael
function completeSeparation() {
var differentSlidersForProperties = true;
var composition = app.project.activeItem;
if (!composition || !(composition instanceof CompItem))
return alert("Please select composition first");app.beginUndoGroup("Add Controllers");
forSelectedProperties(separateDimentions);
app.endUndoGroup();function forSelectedProperties(callback) {
var selectedProperties = composition.selectedProperties;
for (var i = 0, il = selectedProperties.length; i < il; i++) {
callback(selectedProperties[i]);
}
}function separateDimentions(property) {
// Skip if property cannot have expressions
if (!property.canSetExpression) return;function getPropChain(prop) {
var ret = [];
if (prop.parentProperty !== null) { //when this prop's parent is Layer, parentProperty is null
ret = getPropChain(prop.parentProperty)
}
ret.push(prop.name); //prop.name add last
return ret;
}var curComp = app.project.activeItem;
var curLayer = curComp.selectedLayers[0];
var curPropChain = getPropChain(curLayer.selectedProperties[0]);var JOINT = " > ";
var mastersuffix = curPropChain.slice(1, -1).join(JOINT).toString().replace(new RegExp("Contents >","g"), "");// Start constructing effect name suffix
var effectNameSuffix = '';
if (differentSlidersForProperties) {
effectNameSuffix = ' (' + property.name + '), [' + mastersuffix + '] ';
}// Get a layer from current property
var layer = getLayerFromProperty(property);// Get layers Effect property
var effectsProperty = layer.property("ADBE Effect Parade");// Get properties value as an array
var value = getPropertyValue(property);var prefixes = ['X', 'Y', 'Z'];
var controller;
var controllers = [];
var exprArray = [];for (var i = 0, il = value.length; i < il; i++) {
var sliderName = prefixes[i] + effectNameSuffix;if (!hasSlider(sliderName)) {
// Add a slider with properties value
addSlider(sliderName, value[i]);// Remember controllers name
controller = 'ctrl' + (i + 1);
controllers.push(controller);// Construct expression and push it into array
exprArray.push(controller + ' = effect("' + sliderName + '")("Slider");');
}addExpression(property);
}function addExpression(property) {
// Make a String out of array
var expression = exprArray.join('\r');// Create executable line, as in [ctrl1, ctrl2] etc
expression = expression + '\r' + '[' + controllers.join(', ') + '];';// Apply expression
property.expression = expression;
}function hasSlider(sliderName) {
for (var i = 1, il = effectsProperty.numProperties; i <= il; i++) {
if (effectsProperty.property(i).name === sliderName) {
return true;
}
}
return false;
}function addSlider(sliderName, value) {
var slider = effectsProperty.addProperty('ADBE Slider Control');
slider.name = sliderName;
slider.property(1).setValue(value);
}function getLayerFromProperty(property) {
while (property.parentProperty) {
property = property.parentProperty;
}
return property;
}function getPropertyValue(property) {
// Get properties value at timr 0
var value = property.valueAtTime(0, false);// Make sure it's an array
if (!value.length) {
value = [value];
}// If it's a 2D layer, trim the 3rd value
if (!layer.threeDLayer && value.length === 3) {
value.length = 2;
}return value;
}
}
}; -
Thanks Dan, that was just what I needed!
Probably I should get into the habit of creating variables instead of pickwhipping, I wasn’t aware of the fact that this could mess up an expression.