8 Replies Latest reply on Dec 19, 2012 8:33 AM by dan_rlpi_com

    I can't get ImportVariables(Filename.xml) to work

    Nlwest User Group Manager

      I'm try to automate the importing of the Varaible and datasets into my graphs via Scripting, but the ImportVaraibles() function doesn't seem to work.  Here is my Script, mostly copied from the example script provided with Illustrator (CS5).  And, this works manually, using the file names in the script, via Load Variable Library

       

          Set appRef = CreateObject(strIllistratorVersion)

         

             'Open the file and import the datasets

              Set docRef = appRef.Open(strTemplate & "200-500.ai")

              'docRef.Datasets.RemoveAll

              docRef.Variables("Yearbook").Delete

       

      Here is the problem, after I delete the previous library, then this next line, right from the example, does nothing

      The script then exits with 'No Datasets in this document'

              docRef.ImportVariables (strXMLFolder & "\Lumber_200-500.xml")

       

       

              'appRef.DoJavaScript "alert('Template:" & strTemplate & strRange & ".ai  |  XML file:" & strXMLFolder & "\"  & objFile.Name & "^')"

              If (appRef.Documents.Count > 0) Then

                  Set docRef = appRef.Documents(1)

                  'loop thru datasets

                  If docRef.DataSets.Count > 0 Then           

              '        ' Create folder object for path and save the dataset files.

                      Set fileSysRef = CreateObject( "Scripting.FileSystemObject" )

                      Set folderRef = fileSysRef.GetFolder(strEPSFolder)

                      For i = 1 To docRef.DataSets.Count

                          myPath = folderRef & "\" & docRef.DataSets(i).Name & ".ai"

                          'docRef.DataSets(i).Display

                          docRef.SaveAs (myPath)

                      Next               

                  Else

                      appRef.DoJavaScript "alert('No datasets in this document!')"

                  End If

              Else

                  appRef.DoJavaScript "alert('No document open. Please open a document with datasets.')"

              End If

              docRef.Close (2)

       

      appRef.DoJavaScript "alert('Export Complete.')"

       

      If I remove that delete line, the script runs, but just uses whatever Variables I had last loaded, not the XML file.

       

      It's simply not loading.  What do I need to do to get it to load?

       

      Thanks.

        • 1. Re: I can't get ImportVariables(Filename.xml) to work
          Larry G. Schneider Adobe Community Professional & MVP

          Is this supposed to be ExtendScript or VB? If ExtendScrpt then try Set docRef = appRef.Documents (0).

          • 3. Re: I can't get ImportVariables(Filename.xml) to work
            Muppet Mark Level 5

            Apart from the alerts()… I recognise them for everything else you may need to wait for Carlos to pop it… I tried a similar thing some time ago in AppleScript and recall having troubles… You have an uncommon issue VB and datasets ( not many users here of both )… Its usually easier to script whatever the XML vairables are…?

            • 4. Re: I can't get ImportVariables(Filename.xml) to work
              dan_rlpi_com

              I figured it out.  It seems I have to docRef.Close(1) after the ImportVariables, then re-open it to get the changes to refresh.

               

              Is there an easier way?

              • 5. Re: I can't get ImportVariables(Filename.xml) to work
                Muppet Mark Level 5

                As I don't do VB Im guessing that just re-saving the open document had no effect…?

                • 6. Re: I can't get ImportVariables(Filename.xml) to work
                  dan_rlpi_com Level 1

                  Correct.  ReSaving alone did nothing.

                  • 7. Re: I can't get ImportVariables(Filename.xml) to work
                    CarlosCanto Adobe Community Professional & MVP

                    it works fine here, after running the provided sample to create the folder and file on the desktop, I modified the script as shown below, added those two lines you're having trouble with and run it on the active document, I got no errors

                     

                    Set appRef = CreateObject("Illustrator.Application")
                    
                    
                    const DESKTOP = &H0&
                    set myShell = CreateObject("Shell.Application")
                    set myDesktopFolder = myShell.Namespace(DESKTOP)
                    set myDesktopFolderItem = myDesktopFolder.Self
                    myDesktopPath = myDesktopFolderItem.Path
                    
                    
                    Set objFileSys = CreateObject("Scripting.FileSystemObject")
                    Set objFolder = objFileSys.GetFolder(myDesktopPath)
                    
                    
                    If (objFileSys.FolderExists(objFolder & "\ImportedDatasets")) Then
                        Set importFolder = objFileSys.GetFolder(objFolder & "\ImportedDatasets")
                    Else
                        Set importFolder = objFolder.SubFolders.Add("ImportedDatasets")
                    End If
                    
                    saveFolder = importFolder.Path
                    aiFilename = "\DS_V.ai"
                    xmlFilename = "\DS_V.xml"
                    
                    
                    
                    
                    ' import the datasets on the active document
                    
                    
                    Set docRef = appRef.activeDocument
                        docRef.DataSets.RemoveAll     ' added this line
                        docRef.Variables("variable1").Delete     'added this line
                    docRef.ImportVariables (saveFolder & xmlFilename)
                    'docRef.Save
                    
                    
                    myMsg = "alert(""Done"")"
                    appRef.DoJavaScript myMsg
                    
                    • 8. Re: I can't get ImportVariables(Filename.xml) to work
                      dan_rlpi_com Level 1

                      I never said I got an error message.  No message, just no NEW data.

                       

                      Unfortunatley, we are not in a position to Variables(xx).Delete because that deletes the Variable Type when importing the new Variable.  This must have something to do with the Graph variable type.  Even though it's in the XML file with the type, it doesn't seem to be imported, so this only leaves me the option of ImportVariables over existing variables, and this doesn't seem to refreash without closing the document.

                       

                      Try this:

                       

                      ' import the datasets on the active document


                      Set docRef = appRef.activeDocument
                      '    docRef.DataSets.RemoveAll     ' added this line
                      '    docRef.Variables("variable1").Delete     'added this line


                      appRef.DoJavaScript  "alert('" & docRef.Datasets.Count & "')"

                      docRef.ImportVariables (saveFolder & xmlFilename)


                      appRef.DoJavaScript  "alert('" & docRef.Datasets.Count & "')"

                      'docRef.Save


                      myMsg = "alert(""Done"")"
                      appRef.DoJavaScript myMsg

                       

                      If you make sure the count of datasets is different before the import than in the XML you'll see that the count doesn't change after the import, during the course of the script.  Yes, the count will be different after the script finishes, but nothing else you do during the script will show the new data, and I want to export my chart as part of my script.

                       

                                      For i = 1 To docRef.DataSets.Count

                                          myPath = folderRef & "\" & docRef.DataSets(i).Name & ".ai"

                                          'docRef.DataSets(i).Display

                                          docRef.SaveAs (myPath)

                                      Next