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

Add symbol and set text within it

Explorer ,
Dec 05, 2016 Dec 05, 2016

Copy link to clipboard

Copied

Hi all,

I have a symbol in the symbols panel which contains a text box with a rounded shape behind it.

I want to add many copies of the symbol to the document with but change the content of the text box every time.

How can I do this with javascript?

I have a loop like this at the moment but don't know how to set the text inside the symbol once its added to the document.

My darkGreenSymbol has a text box in it and I have attached a variable called itemText to it.

var timelineItems = [];

timelineItems.push({color:0xFF0000,icon:'maintain',title:'1st July 2016',startDate:'2016-07-01',endDate:'2016-09-01'});

timelineItems.push({color:0xFF00FF,icon:'maintain',title:'1st September 2016',startDate:'2016-09-01',endDate:'2016-10-01'});

timelineItems.push({color:0xFF00FF,icon:'maintain',title:'23rd February 2017',startDate:'2017-02-23',endDate:'2017-05-01'});

var darkGreenSymbol = doc.symbols.DarkGreen;

for( var i = 0; i < timelineItems.length; i++ ){

    var item = timelineItems;   

    var itemStartDate = parseDate(item.startDate);

    var itemEndDate = parseDate(item.startDate);   

    var monthsOffset = 1 + monthDiff(timelineStartDate,itemStartDate);

    var timelineItem = doc.symbolItems.add(darkGreenSymbol);   

    timelineItem.left = startLeft + (monthWidth * monthsOffset);

    timelineItem.top = startTop - (i * verticalStep);

   

    // This doesnt work

    timelineItem.textVariables.itemText.contents = "Some new text everytime";

   

    $.writeln("timelineItem = "+timelineItem);

}

Maybe I am going about this the wrong way?

Thanks

TOPICS
Scripting

Views

501

Translate

Translate

Report

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
Adobe
Community Expert ,
Dec 05, 2016 Dec 05, 2016

Copy link to clipboard

Copied

you can't change the text inside a symbol instance at the moment.

where did you get textVariables object? I don't think it's part of the Illustrator DOM.

Votes

Translate

Translate

Report

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
Community Expert ,
Dec 05, 2016 Dec 05, 2016

Copy link to clipboard

Copied

...I meant, without breaking the link to its symbol.

Votes

Translate

Translate

Report

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
Explorer ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

I got textVariables somewhere on the internet. Just trying whatever to make it work.

I am used to working with Flash and movie clips so thats why I though I could change the text.

Is it possible to unlink the instance and change the text?

I am currently just putting new text on top.

Thanks

Votes

Translate

Translate

Report

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
Community Expert ,
Dec 06, 2016 Dec 06, 2016

Copy link to clipboard

Copied

LATEST

yes!! use the "breakLink()" method...omg, I have not noticed we had it, it's been here since at least CS6. I used to break it old school, by deleting the parent Symbol.

Votes

Translate

Translate

Report

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