3 Replies Latest reply on Sep 20, 2014 4:16 PM by CarlosCanto

    Create a symbol from placedItem/rasterItem does not work

    osc

      I need to create symbols in Illustrator CC programmatically from files on on disk. The following code gives an error when adding the symbol and I have no clue why. Any help will be appreciated. According to Adobe Illustrator CC Scripting Reference, a symbol can be added from a source art of type:

      • CompoundPathItems
      • GroupItems
      • MeshItems
      • NonNativeItems
      • PageItems
      • PathItems
      • RasterItems
      • SymbolItems
      • TextFrameItems

       

      Here is the code:

      #target illustrator

      var activeDoc = app.activeDocument;

      var tempLayer = activeDoc.layers.add(); //Layer object reference

      var newSymbol; //Symbol object reference

      var srcArt; //PlacedItem object reference

      var fName; //File name

       

      // create document list from files in selected folder

      var selectedFolder = Folder.selectDialog('Please select the folder to be imported:', Folder('~'));

      var imageList = selectedFolder.getFiles();

       

      for (var i = 0; i < 1; i++) {

          if (imageList[i] instanceof File) {

              fName = imageList[i].name.toLowerCase();

              if( (fName.indexOf('.eps') == -1) && (fName.indexOf('.png') == -1)) {

                  continue; // skip unsupported formats

              }

              else {

                  srcArt = activeDoc.placedItems.add(); //Place the image on the artboard

                  srcArt.file = imageList[i];

                  srcArt.embed();                                       

                  activeDoc.symbols.add(srcArt);  --> Execution stops here with the message "an Illustrator error occurred: 556099904 ('@i%!')"

                  newSymbol.name = fName.substring(0, fName.lastIndexOf(".") );

              }

          }

      }