Silicon Publishing YouTube Channel

Publishing with Silicon

Silicon Publishing blog: reconciling information and rendition technologies
  • Home
  • About

Archive

Archive for May, 2012

Silicon Publishing Invents the desperationCounter

May 9th, 2012 maxdunn No comments

Anybody who works with automating Adobe Illustrator long enough will find some level of flakiness in the behavior of this application. It is very old, and doesn’t enjoy the same level of support for automation as does InDesign, a much more modern application. I got this email this morning, and it seems we are one step closer to taming the Illustrator beast…

”
Colleagues,

To place a graphic in Illustrator, you create a new placedItem using placedItems.add(), then you set the file property of the placedItem to a file reference for the graphic you want to import. That’s okay. But when you’re creating/exporting/closing lots of files, Illustrator sometimes loses track of what’s going on. In times like these, Illustrator will create a placedItem that doesn’t really exist. When that happens, trying to set the file property will fail, but it won’t throw an error until later—because the placedItem.file property is null. In fact, the whole placedItem is garbage—but Illustrator doesn’t *know* that it’s junk until it tries to do something with it. If you set the placedItem.file property to an existing file and the property remains null, you know you’ve got a bad object.

So…be encouraging. I find that asking Illustrator to do something a few times usually produces the result I want. Something like this (I can probably go through and remove a few of the extra steps here, but, however inelegant, this does work):

//Place the EPS file by setting the file property of the placedItem to the EPS.
try{
      SuiteTalk.log("Setting file property for placedItem to EPS file for layer " + lName + ".", "DEBUG");
      placedEPS.file = epsFile;
      SuiteTalk.log("Setting file succeeded.", "DEBUG");
}
catch(e:Error){
      SuiteTalk.log("Error creating placed EPS for layer " + lName + ".", "DEBUG");
      SuiteTalk.log("File exists? " + epsFile.exists + ".", "DEBUG");
      SuiteTalk.log("File URL: " + epsFile.url + ".", "DEBUG");
      //Try again.
      if(epsFile.exists == true){
            var epsFilePlaced:Boolean = false;
            var desperationCounter:int = 0;
            while(epsFilePlaced == false){
                  try{
                        //Try again from the beginning.
                        newDoc.activate();
                        placedEPS = newDoc.placedItems.add();
                        placedEPS.file = epsFile;
                  }
                  catch(e:Error){
                        //"SuiteTalk" is for writing to a log file
                        SuiteTalk.log("Retry failed for setting file of placedItem for layer " + lName + ".", "DEBUG");
                        if(desperationCounter >= 100){
                              se = new SuiteTalkError( "Error creating placedItem for EPS: " + e.message, "103");
                              se.other = lName;
                              outErrors.push(se);
                              SuiteTalk.log("Could not create placedItem for EPS for layer " + lName + ".", "DEBUG");
                              epsFilePlaced = true;
                        }
                        desperationCounter ++;
                  }
                  if(placedEPS.file != null){
                        epsFilePlaced = true;
                  }
            }
      }
}

So far, it’s never run through the desperationCounter, and it’s always–eventually—imported the file.

And now, a round of applause for Jonathan Brown’s “isValid” property on InDesign objects.

Thanks,

Ole
”

LOL, we can’t always be elegant, especially with older applications.

Categories: Adobe, Creative Suite Tags: Adobe, Illustrator, scripting
RSS
  • Google
  • Youdao
  • Xian Guo
  • Zhua Xia
  • My Yahoo!
  • newsgator
  • Bloglines
  • iNezha

Random Posts

  • IDML Resources
  • A Whitepaper for Silicon Publishing
  • Adobe Learns XML, Slowly
  • The Evolution of Silicon Paginator
  • Connecting InDesign to Web-based Assets

Tag Cloud

Access Adobe AdobeMax Adobe MAX Berners-Lee blogging Day Digital Editions DITA ePubs Filebloat FLA Flash Flex FXG Google HTML5 HTML5 vs. Flash Hyperlinks IDML Illustrator InDesign inDesign Server InDesignServer Kindle MarkLogic Motorola Mobility Online Design overabundance Publishing Scene7 scripting Silicon Silicon Designer Specialization SVG technology VBA web Web to Print Welcome www XFL XML XSL

Categories

  • Adobe
  • Apple
  • Creative Suite
  • Day Software
  • DITA
  • Flash
  • General
  • HTML5
  • InDesign
  • InDesign Server
  • Kindle
  • MarkLogic
  • Scene7
  • Tablet
  • Web App
  • Web to Print
  • XML

Blogroll

  • A List Apart
  • DITA-FMx
  • IDML
  • InDesign Server
  • Silicon Publishing

Archives

  • April 2013
  • October 2012
  • September 2012
  • July 2012
  • May 2012
  • March 2012
  • February 2012
  • November 2011
  • October 2011
  • August 2011
  • June 2011
  • April 2011
  • December 2010
  • November 2010
  • October 2010
  • June 2010
  • May 2010
  • February 2010
  • December 2009
  • November 2009

Meta

  • Log in
Top WordPress
Copyright © 2009-2013 Publishing with Silicon
Theme by NeoEase. Valid XHTML 1.1 and CSS 3.