Change Text propertys

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
fabiantheblind
Posts: 7
Joined: December 27th, 2010, 11:33 pm

Hello,

I'm trying to write a little script that builds a timecodelayer for me.
Now can somebody tell me how to change the Font and the color and so on?
I got this code:

Code: Select all

buildTimeCode();
function buildTimeCode()
{    
	app.beginUndoGroup("build Time Code");
    var curComp = app.project.activeItem;
    if (!curComp || !(curComp instanceof CompItem))
    {
        alert("Please select a Composition.");
        return;
    }
var tl = curComp.layers.addText("");
    tl.position.setValue([10,10]);
var bg = curComp.layers.addSolid([0,0,0], "bg", tl.width, tl.height, 1, curComp.duration);

var expr = "timeToTimecode(t = time + thisComp.displayStartTime, timecodeBase = "+"12"+", isDuration = true)";

    tl.property("Source Text").expression  = expr;
    tl.property("Source Text").value.font  = "Arial";
    tl.property("Source Text").value.fontSize = 18;
    tl.property("Source Text").value.color = [1.0,1.0,1.0];
    
    tl.moveToBeginning();


app.endUndoGroup();

}
The script runs thru builds the layers ( the solid size doesn't fit. this is another bug) but doesn' t change the color and the font.

Thanx

:F
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

There's an example here:
http://blogs.adobe.com/toddkopriva/2008 ... ng-ch.html

You need to grab the text value, change it, then set it back to the property:

Code: Select all

var myTextDocument = myTextLayer.property("ADBE Text Properties").property("ADBE Text Document")
var textDocument1 = myTextDocument.value;
textDocument1.fontSize = 60;
myTextDocument.setValue(textDocument1);
fabiantheblind
Posts: 7
Joined: December 27th, 2010, 11:33 pm

Thnx, that worx

Code: Select all

buildTimeCode();
function buildTimeCode()
{    
	app.beginUndoGroup("build Time Code");
    var curComp = app.project.activeItem;
    if (!curComp || !(curComp instanceof CompItem))
    {
        alert("Please select a Composition.");
        return;
    }

var tl = curComp.layers.addText("new_text_layer");
    tl.position.setValue([10,17]);
    tl.name = "tc_layer";

var expr = "timeToTimecode(t = time + thisComp.displayStartTime, timecodeBase = "+ curComp.frameRate+", isDuration = true)";
    tl.property("Source Text").expression  = expr;
var tltxt = tl.property("ADBE Text Properties").property("ADBE Text Document");

var txt = tltxt.value;
    txt.resetCharStyle();
    txt.fontSize = 18;
    txt.fillColor = [1, 1, 1];
    txt.font  = "Arial";
    
    tltxt.setValue(txt);
var bg = curComp.layers.addSolid([0,0,0], "tc_bg", curComp.width, curComp.height, 1, curComp.duration);
    bg.anchorPoint.setValue([0,0]);
    bg.position.setValue([0,0]);
    bg.scale.setValue([100,5]);

    
    tl.moveToBeginning();


app.endUndoGroup();

}
Post Reply