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

Dataset not updating automatically

New Here ,
Oct 27, 2009 Oct 27, 2009

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.

TOPICS
Scripting
7.9K
Translate
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

correct answers 1 Correct answer

Contributor , Nov 13, 2009 Nov 13, 2009

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 );
//} /

...
Translate
Adobe
Participant ,
Oct 28, 2009 Oct 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

Translate
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
New Here ,
Oct 29, 2009 Oct 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);
}

Translate
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
New Here ,
Oct 29, 2009 Oct 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.

Translate
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
Contributor ,
Oct 31, 2009 Oct 31, 2009

You have to call dataset.update() method ... this event must be triggered whenever an update to the dataset is available ... i`m not quite sure how Illy handles dynamic update ... but this should bring you to the right track.

cheers.

Translate
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
New Here ,
Nov 02, 2009 Nov 02, 2009

Hi Sonic,

Thanks for the help.  Someone from another post had also advised using the update() method.  I tried putting ds1.update() in a number of different places but it did not work.  The last thing I tried was the following:

docRef.activeDataset = ds1;

ds1.display();
ds1.update();
    redraw();

But I still have to run the code twice before the graph changes.  Any more ideas please?

Translate
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
New Here ,
Nov 02, 2009 Nov 02, 2009

Hi,

If I do the following (re-position the ds1.update() 😞

docRef.activeDataset = ds1;
ds1.update();

ds1.display();
     redraw();

Then regardless of how many times I run the code the graph never gets updated.

Translate
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
Participant ,
Nov 02, 2009 Nov 02, 2009

Good morning,

Sometimes saving the file can be the best redraw.

Patrice

Translate
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
New Here ,
Nov 02, 2009 Nov 02, 2009

Morning Patrice,

I thought that too.  I tried to save the file after the code is run once.  But when opening it it still had the old data.  I would then chose the dataset from the drop down and the graph would update.  Therefore, the dataset has updated but the graph is not refreshed until it is actually picked or if I run the code again.

Translate
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
Participant ,
Nov 03, 2009 Nov 03, 2009

Good evening,

Your script seems correct on my computer.

I created a new set of date inthe same XML file. I can use Capella_1 and Capella_2 with a direct change on screen.

Please verify that you use the correct variables i.e.

Best regards

Patrice

NB: I'm using AI CS4

Translate
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
Participant ,
Nov 03, 2009 Nov 03, 2009

I received an error when attaching th javascript file

I try a second time

Translate
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
Participant ,
Nov 03, 2009 Nov 03, 2009

I received an error when attaching th javascript file

I include the script in this e-mail because of an error when attaching this file

var rs = "OK";
var textRef;
var textVar;
var pathRef;
var xmlFilePath = 'c:/tmp/variables.xml'
var aiChartFilePath = 'C:/tmp/Capella_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("Capella_2");

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

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

Translate
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
New Here ,
Nov 04, 2009 Nov 04, 2009

Hi Patrice,


Thanks very much for your help.  Your last update has helped because I think I know the reason why the update is not happening.  I did the same as you and added another dataset called Capella_2.  Now when running the code the graph updates correctly.  I closed the file and then I changed the code back to Capella_1 and the code did not work again.  I think the reason for this is that the graph was originally saved with Capella_1 as the only dataset.  So when running the code could Illustrator be assuming that the dataset is already Capella_1 and therefore no need to refresh anything.  I know it is not refreshing because I changed the values in the xml file before running.

Another issue I've noticed is that if I add another dataset to the xml variables file called Capella_3, there is an error message saying that the Element does not exist.  Second time I run the code then it works fine.  Another way I can make it work is if I save the file with a dataset called Capella_3 already present, then the change happens correctly.

Translate
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
Guide ,
Nov 10, 2009 Nov 10, 2009

Well with a bit of trial n error I did eventually get this to work for me. Having tried redraw(); $.sleep(); and everything else I could think of I threw in a dialog just to check something and it started to update on screen. Comment the dialog out and it still works you just don't see it happen on screen. Here is what I had. Loops through the graphs in the datasets xml and saves each out as .ai file.

#target illustrator

function main() {

usersHome = Folder('~').fsName.toString();

var filePath = usersHome + '/Desktop/VarDataGraphs.ai'

var xmlFilePath = usersHome + '/Desktop/Variable Graphs 2.xml'

docRef = open(new File(filePath));

docRef.activate();

if (docRef.variables.length == 1 && docRef.variables[0].kind == VariableKind.GRAPH) {

alert("We have a Graph Variable");

docRef.dataSets.removeAll();

$.sleep( 1000 );

docRef.importVariables(new File(xmlFilePath));

$.sleep( 1000 );

docRef.save();

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

var dsName = docRef.dataSets.name;

alert('Now moving on to NEW ' + dsName); // This line forces the redraw!!!

docRef.dataSets.display();

redraw();

$.sleep( 2000 );

var newFilePath = new File(usersHome + '/Desktop/' + dsName + '.ai');

SaveAsAiFile(newFilePath);

}

docRef.close(SaveOptions.DONOTSAVECHANGES);

}

else {

alert("We don't have a Graph Variable");

}

};

function SaveAsAiFile(saveFile) {

var aiOptions = new IllustratorSaveOptions();

//aiOptions.compatibility = Compatibility.ILLUSTRATOR12;

aiOptions.compressed = true;

aiOptions.embedICCProfile = true;

aiOptions.embedLinkedFiles = true;

//aiOptions.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;

//aiOptions.fontSubsetThreshold = 100;

//aiOptions.overprint = PDFOverprint.PRESERVEPDFOVERPRINT;

aiOptions.pdfCompatible = true

docRef.saveAs(saveFile, aiOptions);

};

main();

Translate
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
New Here ,
Nov 10, 2009 Nov 10, 2009

Hi Mark,

Thanks for the code.  I tried it out but the code still does not find any datasets even though there are 3 of them.  I open the file and in the variables tab I can select all 3 and the graph changes.  Just before your line--> for (var i = 0; i < docRef.dataSets.length; i++)  I put in alert(docRef.dataSets.length) and this gives a popup box of 0.  Therefore, no graphs are ever saved.

I am using CS3.

Translate
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
Contributor ,
Nov 10, 2009 Nov 10, 2009

this should work just fine ... put 2 datasets in the same file:

<?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="Capella_1">
            <Variable1>
               <data  numDataColumns="2">
                  <propertyRow  key="name">
                     <value></value>
                     <value>ClassA</value>
                     <value>ClassB</value>
                  </propertyRow>
                  <values>
                     <row>
                        <value  key="name">RowA</value>
                        <value>1</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:sampleDataSet  dataSetName="UPD">
            <Variable1>
               <data  numDataColumns="2">
                  <propertyRow  key="name">
                     <value></value>
                     <value>ClassA</value>
                     <value>ClassB</value>
                  </propertyRow>
                  <values>
                     <row>
                        <value  key="name">RowA</value>
                        <value>1</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>

Javascript code:

var DBHelper = {

                mainFs: null,
                loadFile: function(fileOrFilename, isAI) {
                            var _fl = (fileOrFilename instanceof "File") ? fileOrFilename : new File(fileOrFilename);
                            if(isAI) { myDoc = app.open(_fl);}                            
                            else {
                                myDoc.importVariables(_fl);
                                this.mainFs = app.activeDocument.path.fullName + "/" + app.activeDocument.name;
                                myDoc.save();
                                myDoc.close();
                                this.loadFile(this.mainFs,true);                               
                            }
                },
                displaySet: function(setName) {
                            app.activeDocument.activeDataset = myDoc.dataSets.getByName(setName);
                            app.activeDocument.activeDataset.display();
                }
}
DBHelper.loadFile("/d/_temp/Capella_Chart_1.ai", true);
DBHelper.loadFile("/d/_temp/variables.xml",false);
DBHelper.displaySet("Capella_1");

cheers;

Translate
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
Contributor ,
Nov 10, 2009 Nov 10, 2009

this should also work without opening and closing the document:

var DBHelper = {
                loadifReady: null,
                isLoaded: false,
                loadWhenReady: function(dsName) { this.loadifReady = dsName; },
                loadFile: function(fileOrFilename, isAI) {
                            var _fl = (fileOrFilename instanceof "File") ? fileOrFilename : new File(fileOrFilename);
                            if(isAI) { myDoc = app.open(_fl);}                            
                            else {
                                myDoc.importVariables(_fl);
                                while(!this.isLoaded) {
                                    try {
                                        app.activeDocument.activeDataset = myDoc.dataSets.getByName(this.loadifReady);
                                        this.isLoaded = true;
                                        this.displaySet();
                                    } catch(ex){}
                                }
                            }
                },
                displaySet: function() {
                            app.activeDocument.activeDataset = myDoc.dataSets.getByName(this.loadifReady);
                            app.activeDocument.activeDataset.display();
                }
}

DBHelper.loadFile("/d/_temp/Capella_Chart_1.ai", true);
DBHelper.loadWhenReady("Capella_1");
DBHelper.loadFile("/d/_temp/variables.xml",false);

the basic idea of this one is that it tests for the existence of that particular dataset name in a potentially infinite loop, and when it gets the name it simply continues with the script ... hope it helps.

cheers;

*later edit * sorry for the fact that even if you posted your files i totally forgot about this ... and this last script should work even with one dataset ... didn'`t test it but i`m quite surethat it does

Translate
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
New Here ,
Nov 11, 2009 Nov 11, 2009

Hi Sonic,

Thanks for the code.  It is doing exactly the same thing as with the other code posting.  I need to run it twice before it picks up any changes to the xml file I may have made.

This is what I am doing.

1)  Change the value of the xml file for the graph (eg from 1.2 to 200).

2) Run your code. (The graph is opened and shows the value before I made the change (ie 1.2), if I manually change the dataset the graph then gets updated ie 200)

3) Run your code again.  This time the graph is updated to 200.

Translate
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
Contributor ,
Nov 11, 2009 Nov 11, 2009

Well i know why probably it doesn't work for you ... let me explain you why:

you probably saved your .ai file with the datasets already loaded, meaning that you already loaded the datasets in variables.xml and then saved the document.

Do the following:

- duplicate your variables.xml file and name it variables2.xml ... leave only one dataset in this new file and name it "_none" and make some changes to the data within it(so you can see changes) ;

- then load variables2.xml in your .ai file, make active dataset to "_none". save the file as it is now.(do all this manually)

like this:

<?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="_none">
            <Variable1>
               <data  numDataColumns="2">
                  <propertyRow  key="name">
                     <value></value>
                     <value>ClassA</value>
                     <value>ClassB</value>
                  </propertyRow>
                  <values>
                     <row>
                        <value  key="name">RowA</value>
                        <value>1</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>

- after doing this run the script ... it will update as it supposed to; right now the script checks until it gets the dataset with the specified name, but since the file(and normally the dataset too) is already loaded(and saved so) it will exit ealier than it supposed to.

hope it helps;

cheers;

Translate
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
New Here ,
Nov 11, 2009 Nov 11, 2009

Hi Sonic,

Thanks for your previous message.  I did what you said.  Basically took the file and loaded it up with a new variable file with only 1 dataset called "_none" and saved the ai file.  When I open the file I can see only the 1 dataset called _none with the amended data.  Close it again.

I ran your code and it opens the correct file.  It then loads the original variable file with the 3 datasets.  But it goes into an infinite loop around

while(!this.isLoaded).  In debug mode I followed the code and the watch does state:- string this.isLoaded = "Capella".  However boolean this.isLoaded = false and therefore continues looping around the while statement.  If I then stop the code and look at the file I can see that the variable file has been loaded with the 3 datasets but for some reason the code just can not pick the "Capella" dataset.  Without changing anything on the illustrator graph and not saving etc, I run your script again and this time it recognises the fact that Capella is there and updates the graph.

I even put a sleep after your while statement and in your catch clause I added alert("Dataset Not Found") and on the first run of the code the alert box is always displayed. I stopped the code and then run it again immediately, without doing anything else, and no alert box is displayed.

I wonder if it is CS3 or something screwy with my setup because it seems you and others do not have the same issue.

Translate
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
Contributor ,
Nov 11, 2009 Nov 11, 2009

i'll attach the files when i will get home ... seems like you're doing something wrong ... or i might be wrong, though i doubt it since i tested the code and for me at least works without a problem ... i'll be back later with the files.

cheers;

Translate
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
Contributor ,
Nov 11, 2009 Nov 11, 2009

the 2nd script seems that it runs only when u saved your file with those datasets already loaded. however this one(my first script) seems to work without doing anything:

var DBHelper = {

                mainFs: null,
                loadFile: function(fileOrFilename, isAI) {
                            var _fl = (fileOrFilename instanceof "File") ? fileOrFilename : new File(fileOrFilename);
                            if(isAI) { myDoc = app.open(_fl);}                            
                            else {
                                myDoc.importVariables(_fl);
                                this.mainFs = app.activeDocument.path.fullName + "/" + app.activeDocument.name;
                                myDoc.save();
                                myDoc.close();
                                this.loadFile(this.mainFs,true);                               
                            }
                },
                displaySet: function(setName) {
                            app.activeDocument.activeDataset = myDoc.dataSets.getByName(setName);
                            app.activeDocument.activeDataset.display();
                }
}
DBHelper.loadFile("/d/_temp/Capella_Chart_1.ai", true);
DBHelper.loadFile("/d/_temp/variables.xml",false);
DBHelper.displaySet("Capella_1");

sorry for the misunderstanding(on my side)

cheers;

Translate
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
New Here ,
Nov 12, 2009 Nov 12, 2009

Hi Sonic,


That worked perfectly when running from Illustrator.  THANKS!!!

I've got one more favour to ask, please.  When running the code from Indesign I still need to run the code twice.  I think this maybe due to the time taken to save etc but I am not 100% sure.  I have tried to put in sleeps but that did not work.  When you get a chance could you check the attached file for me please.  Thanks very much.

Translate
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
New Here ,
Nov 12, 2009 Nov 12, 2009

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();

Translate
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
Contributor ,
Nov 13, 2009 Nov 13, 2009

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;

Translate
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