Skip to main content
Known Participant
October 27, 2009
Answered

Dataset not updating automatically

  • October 27, 2009
  • 1 reply
  • 7171 views

Hello,

I have a graph that is dynamic.  I already have a variable set up and also a dataset.  This file is saved.

Basically, I am trying to write some code that will open the document, import the variable file (with the new data from the xml file) and then update the graph.

Using the code below, the file opens and also the import of the variables is succesful.  However, the graph is not updating automatically.  I need to actually select the value from the dropdown in the variables window.  Can anyone please tell me what I am doing wrong.

   // Open the file and import the datasets and variables from xml file
  var docRef = open(new File(aiChartFilePath));
  
   alert("Importing the datasets.");
 
   docRef.importVariables(new File(xmlFilePath));

var ds1 = docRef.dataSets.getByName("Chart1Variable");
alert(ds1); //this gives the "DataSet Chart1Variable"
docRef.activeDataset = ds1;
ds1.display();
redraw();

rs = "OK";

Thanks in advance for your help.

This topic has been closed for replies.
Correct answer sonicDream

Hi,  not got access to attach files so below is what I was talking about.

#target indesign


function main() {

if (app.documents.length == 0) {

alert("Please have an 'Indesign' document before running this script.");

return;

}

var docRef = app.documents[0];

$.sleep( 3000 ); // Just my novice delay method

updateGraph();

$.sleep( 3000 ); // Ditto here

//updateGraph();// done this twice because there seems to be a bug where the dataset is not getting updated first time around

$.sleep( 3000 );
//} //end for
updateLinks(docRef);

};

// Reverse loop to do this

function updateLinks(docRef) {

for (var i = docRef.links.length-1; i >= 0; i--) {

//if (docRef.links.status == LinkStatus.linkOutOfDate) {

docRef.links.update();
// } if clause end
}// for

}

// A basic Bridge Talk example

function updateGraph() {

if ( BridgeTalk.isRunning( "bridge" ) ) {

var bt = new BridgeTalk();

bt.target = "illustrator";

bt.body = "#target illustrator" + "\r"
+ "var DBHelper = {" + "\r"
+ "mainFs: null," + "\r"
+ "loadFile: function(fileOrFilename, isAI) {" + "\r"
+ "var _fl = (fileOrFilename instanceof 'File') ? fileOrFilename : new File(fileOrFilename);" + "\r"
+ " if(isAI) { myDoc = app.open(_fl);}" + "\r"
+ "else {" + "\r"
+ "myDoc.importVariables(_fl);" + "\r"
+ "this.mainFs = app.activeDocument.path.fullName + '/' + app.activeDocument.name;" + "\r"
+ " myDoc.save();" + "\r"
+ "myDoc.close(SaveOptions.SAVECHANGES);" + "\r"
+ "$.sleep( 3000 );" + "\r"
+ "this.loadFile(this.mainFs,true);" + "\r"
+ "}" + "\r"
+ "}," + "\r"
+ "displaySet: function(setName) {" + "\r"
+ "app.activeDocument.activeDataset = myDoc.dataSets.getByName(setName);" + "\r"
+ "app.activeDocument.activeDataset.display();" + "\r"
+ "app.activeDocument.close(SaveOptions.SAVECHANGES);" + "\r"
+ "$.sleep( 3000 );" + "\r"
+ "}" + "\r"
+ "}" + "\r"

+ "DBHelper.loadFile('/u/adobe indesign/Capella Gross Sector Exposure.ai', true);" + "\r"
+ "DBHelper.loadFile('/u/adobe indesign/Capella Gross Sector Exposure2.xml',false);" + "\r"
+ "DBHelper.displaySet('Capella');" + "\r"
// Save to modify the link status
//+ "myDoc.close(SaveOptions.SAVECHANGES);";
bt.send();

}
else
{
alert ("Please start Adobe Bridge");
}
}
main();


This should be it ... my original code was a lil bit messy cause was written in a hurry

#target indesign


function main() {

if (app.documents.length == 0) {

alert("Please have an 'Indesign' document before running this script.");

return;

}

var docRef = app.documents[0];

$.sleep( 3000 ); // Just my novice delay method

updateGraph();

$.sleep( 3000 ); // Ditto here

//updateGraph();// done this twice because there seems to be a bug where the dataset is not getting updated first time around

$.sleep( 3000 );
//} //end for
updateLinks(docRef);

};

// Reverse loop to do this

function updateLinks(docRef) {

for (var i = docRef.links.length-1; i >= 0; i--) {

//if (docRef.links.status == LinkStatus.linkOutOfDate) {

docRef.links.update();
// } if clause end
}// for

}

// A basic Bridge Talk example

function updateGraph() {

if ( BridgeTalk.isRunning( "bridge" ) ) {

var bt = new BridgeTalk();

bt.target = "illustrator";

bt.body = "#target illustrator" + "\r"
+ "var DBHelper = {" + "\r"

+ "mainFs: null," + "\r"

+ "myDoc: null," + "\r"
+ "loadFile: function(fileOrFilename, isAI) {" + "\r"
+ "var _fl = (fileOrFilename instanceof 'File') ? fileOrFilename : new File(fileOrFilename);" + "\r"
+ " if(isAI) { this.myDoc = app.open(_fl);}" + "\r"
+ "else {" + "\r"
+ "this.myDoc.importVariables(_fl);" + "\r"
+ "this.mainFs = app.activeDocument.path.fullName + '/' + app.activeDocument.name;" + "\r"
+ "this.myDoc.save();" + "\r"
+ "this.myDoc.close(SaveOptions.SAVECHANGES);" + "\r"
+ "$.sleep( 3000 );" + "\r"
+ "this.loadFile(this.mainFs,true);" + "\r"
+ "}" + "\r"
+ "}," + "\r"
+ "displaySet: function(setName) {" + "\r"
+ "this.myDoc.activeDataset = this.myDoc.dataSets.getByName(setName);" + "\r"
+ "this.myDoc.activeDataset.display();" + "\r"
+ "this.myDoc.close(SaveOptions.SAVECHANGES);" + "\r"
+ "$.sleep( 3000 );" + "\r"
+ "}" + "\r"
+ "}" + "\r"

+ "DBHelper.loadFile('/u/adobe indesign/Capella Gross Sector Exposure.ai', true);" + "\r"
+ "DBHelper.loadFile('/u/adobe indesign/Capella Gross Sector Exposure2.xml',false);" + "\r"
+ "DBHelper.displaySet('Capella');" + "\r"
// Save to modify the link status
//+ "DBHelper.myDoc.close(SaveOptions.SAVECHANGES);";
bt.send();

}
else
{
alert ("Please start Adobe Bridge");
}
}
main();

cheers;

1 reply

Patrice Brel
Inspiring
October 28, 2009

Your script seems correct. However be sure that "Chart1Variable" is the ad ho part of the variable.

#target illustrator;
var docRef = activeDocument;
var ds1 = docRef.dataSets.getByName("myGraph01");
alert(ds1); //this gives the "DataSet myGraph01"
docRef.activeDataset = ds1;
ds1.display();
redraw();
rs = "OK";

In this XML, myGraph01 is my data which reference the name of my graph. My XML file name is "graphdata.xml"

<v:sampleDataSet  dataSetName="myGraph01">
   <myGraph>
     <data  numDataColumns="5">
      <values>
       <row>
        <value  key="name"></value>
        <value>50</value>
        <value>25</value>
        <value>25</value>
        <value>25</value>
       </row>
      </values>
     </data>
    </myGraph>
   </v:sampleDataSet>

Best regards

Patrice

pvisellAuthor
Known Participant
October 29, 2009

Hi Patrice,

Thanks for the help.

I noticed that you had docRef.activeDataset = ds1 so I changed that.  But the dataset is still not being automatically selected.  I still have to manually select the dataset and then the graph updates fine.  I changed my dataset name to Data1, below is my xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN"    "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd" [
   <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">
   <!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">
   <!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/">
   <!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/">
   <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
<!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">
]>
<svg>
<variableSets  xmlns="&ns_vars;">
   <variableSet  varSetName="binding1" locked="none">
      <variables>
         <variable  varName="Variable1" trait="graphdata" category="&ns_graphs;"></variable>
      </variables>
      <v:sampleDataSets  xmlns="&ns_custom;" xmlns:v="&ns_vars;">
         <v:sampleDataSet  dataSetName="Data1">
            <Variable1>
               <data  numDataColumns="2">
                  <propertyRow  key="name">
                     <value></value>
                     <value>ClassA</value>
                     <value>ClassB</value>
                  </propertyRow>
                  <values>
                     <row>
                        <value  key="name">RowA</value>
                        <value>50</value>
                        <value>4</value>
                     </row>
      <row>
                        <value  key="name">RowB</value>
                        <value>6</value>
                        <value>2</value>
                     </row>
      <row>
                        <value  key="name">RowC</value>
                        <value>8</value>
                        <value>5</value>
                     </row>
                  </values>
               </data>
            </Variable1>
         </v:sampleDataSet>
      </v:sampleDataSets>
   </variableSet>
</variableSets>
</svg>

--------------------------------------Below is my code.

var rs = "OK";
var textRef;
var textVar;
var pathRef;
var xmlFilePath = 'c:/variables.xml'
var aiChartFilePath = 'C:/Chart_1.ai'

try
{
   // Open the file and import the datasets and variables from xml file
     
  var docRef = open(new File(aiChartFilePath));
  
  alert("Importing the datasets.");
 

  #target illustrator
  docRef.importVariables(new File(xmlFilePath));
   
var ds1 = docRef.dataSets.getByName("Data1");

alert(ds1.name);
docRef.activeDataset = ds1;
ds1.display();
redraw();

rs = "OK";
} // end try
catch (err)
{
   rs = ("ERROR: " + (err.number & 0xFFFF) + ", " + err.description);
   alert(rs);
}

pvisellAuthor
Known Participant
October 29, 2009

Hi,

Looking at this further I may have come closer to the solution.  When I run the code once, then it is as mentioned above.  However, if I run the script a second time the graph gets updated.  Therefore, the code seems to work but needs to be run twice!  Does anyone know what the problem could be.  Thanks in advance.