Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

After Effects Scripting

New Here ,
Dec 25, 2019 Dec 25, 2019

Good afternoon.

I want to link the z position of the layer to the Slider Control, which is assigned as an effect for this layer.

 

var myCarrentComp = app.project.activeItem;
var varCamPosZ = myCarrentComp.layer(1).transform.position.value[2];
myCarrentComp.layer(1).Effects.addProperty("Slider Control");
var PosZCode = "effect(\"Slider Control\")(\"Slider\");";
myCarrentComp.layer(i).transform.position.value[2].expression =PosZCode;

 

 

I thought the Slider Control effect would be related to the z position of the layer.
But this is not happening. Is there anyone who can help with this issue ???

Is there a command to separate the position of a layer of type Separate Dimensions???

TOPICS
Scripting
326
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 02, 2020 Jan 02, 2020
LATEST

Few things wrong in your code:

  • 1. myCarrentComp.layer(i).transform.position.value[2].expression =PosZCode;
    • i is undefined;
    • you are applying PosZCode expression to a value - this is wrong. You can only apply the expression to a property, not a value. Basically, you should do this: <...>transform.position.expression = PosZCode;
  • Your expression string is wrong - it should handle both 2D and 3D layers:
  • if (value.length !== 3) {
    	[value[0], value[1]];
    } else {
    	[value[0], value[1], effect("Slider Control")("Slider")];
    }

 

Final code could look like this:

(function() {
	var composition = app.project.activeItem;
	if (!composition || !(composition instanceof CompItem)) {
		return alert('Please select composition first');
	}

	var layer = composition.selectedLayers[0];
	if (!layer) {
		return alert('Please select a layer');
	}

	var slider = layer.property('ADBE Effect Parade').addProperty('ADBE Slider Control');
	var expression = 'if (value.length !== 3) {\r' + 
		'\t[value[0], value[1]];\r' +
		'} else {\r' + 
		'\t[value[0], value[1], effect("' + slider.name + '")("ADBE Slider Control-0001")];\r' +
		'}';
	layer.transform.position.expression = expression;
})();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines