Copy link to clipboard
Copied
var newTextLayer: TextLayer = app.project.activeItem.layers.addText("Hello, world.");
newTextLayer.property("Position").setValue([0,0]);
Copy link to clipboard
Copied
I think you just need to change the first line:
var newTextLayer = app.project.activeItem.layers.addText("Hello, world.");
newTextLayer.property("Position").setValue([0,0]);
Copy link to clipboard
Copied
That's how I had it initially when I first got the error. I was hoping specifically setting the variable type to TextLayer might address the issue, but it didn't.
Copy link to clipboard
Copied
It works fine for me. I've never seen that error message--I'm not sure how you would get that.
Copy link to clipboard
Copied
Figured it out if anyone else runs into this issue:
property("Position") returns a _PropertyClasses
_PropertyClasses is an alias for: Property | PropertyGroup | MaskPropertyGroup
But setValue() is only valid for Property. It does not exist for PropertyGroup or MaskPropertyGroup
For valid TypeScript, you have to first confirm that property("Position") is specifically a Property before attempting to call setValue(). There are many ways to accomplish this (https://www.typescriptlang.org/docs/handbook/2/narrowing.html), but here was my solution:
var textPos = newTextLayer.property("Position") as Property;
textPos.setValue([0,0]);
Copy link to clipboard
Copied
Sorry, I totally missed the TypeScript reference. Glad you got it sorted!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more