4 Replies Latest reply on Dec 6, 2016 8:34 AM by CarlosCanto

    Add symbol and set text within it

    charlie656

      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[i];   

          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