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
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.
Copy link to clipboard
Copied
...I meant, without breaking the link to its symbol.
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
Copy link to clipboard
Copied
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.