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

How can I loop through name objects?

Explorer ,
Jul 05, 2017 Jul 05, 2017

Copy link to clipboard

Copied

I was wondering if there is a way to loop through specific name objects (thru-cut) one at a time? I like to apply action commands to the objects indivdually. Is this possible?

TOPICS
Scripting

Views

770

Translate

Translate

Report

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

Valorous Hero , Jul 06, 2017 Jul 06, 2017

You don't have the artboards being used as a property of a document object, are they still working for you?
Well I think your problem is that you specify your 'thru-cut' art as layers, while they are not layers. Layers have hasSelectedArtwork property, while art - or the items inside of layers - have the .selected property. In your case you'd change your code to: thisLayer.selected = true;

Votes

Translate

Translate
Adobe
Explorer ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

This is what I have so far.

#target illustrator

function test(){

  function getPartialNamedItems(nameStr){

    var doc = app.activeDocument, thisItem, arr = [];

    for(var i=0; i<doc.pageItems.length; i++){

      thisItem = doc.pageItems;

      if(thisItem.name.match(nameStr)){

        arr.push(thisItem);

      }

    };

    return arr;

  }

  var allItems = getPartialNamedItems ("thru-cut");

app.doScript ('Artboards', 'Test'); 

  //alert(allItems.length);

};

test();

Votes

Translate

Translate

Report

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
Valorous Hero ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

now loop through your found items and perform an app.doScript on each of them after setting their .selected to true to select the items, and app.activeDocument.selection = null to deselect everything.

Votes

Translate

Translate

Report

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
Explorer ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

Thanks for your help Silly-V. I realize that the method I was using was incorrect. I won't be able to create the artboards using an action and that portion will have to be scripted. Here is what I have so far. No errors, but it isn't creating new artboards to the "thru-cut" objects like I need it to. Any chance you can help me with this? Thanks.

//get the total number of thru-cut in active document

function CutThruItems(nameStr){

    var doc = app.activeDocument, thisItem, arr = []

    for(var i=0; i<doc.pageItems.length; i++){

        thisItem = doc.pageItems;

        if(thisItem.name.match(nameStr)){

            arr.push(thisItem);

            }

        }

    return arr;

    }

var allCuts = CutThruItems ("thru-cut");

alert(allCuts.length);

//looping on layers to create one artboard per layer     

        for ( var i = 0 ; i < allCuts.length; i++)   

        {     

            var abIndex = i; 

           

            allCuts=true;

            var sel = doc.selection

            //Create the artboard around selected art   

            doc.fitArtboardToSelectedArt(abIndex);   

            artboards[abIndex].name = currentLayer.name;       

               

            //reset selection for next iteration   

            doc.selection = null;     

        }     

Votes

Translate

Translate

Report

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
Valorous Hero ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

You have to do something like var newBoard = doc.artboards.add([0, 100, 200, -100]);

Votes

Translate

Translate

Report

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
Explorer ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

Very close. I have the artboard showing but it is now its not resizing to the artwork.

   

//////////////////////////////////////////////get the total number of thru-cut in active document

function CutThruItems(nameStr){

    var doc = app.activeDocument, thisItem, arr = []

    for(var i=0; i<doc.pageItems.length; i++){

        thisItem = doc.pageItems;

        if(thisItem.name.match(nameStr)){

            arr.push(thisItem);

            }

        }

    return arr;

    }

var allCuts = CutThruItems ("thru-cut");

alert(allCuts.length);

//////////////////////////////////////////////Checkpoint of visible thru-cut starts here

        for ( var i = 0 ; i < CutThruItems("thru-cut").length; i++){

           

        var currentItem = CutThruItems("thru-cut");

        //We don't want to deal with hidden layers

        if(currentItem.visible == false) continue;

        //Unlock the layer if needed

        currentItem.locked = false;

        //Select ALL in the layer

        currentItem.hasSelectedArtwork = true;

           

//////////////////////////////////////////////Artboard creation starts here

       

      if(i>0){ 

        var newAb = artboards.add([0,100,200,-100]);   

      } 

      var thisLayer = CutThruItems("thru-cut")

      thisLayer.hasSelectedArtwork = true; 

      doc.fitArtboardToSelectedArt(i); 

      doc.selection = null; 

    } 

    //alert("Finished:\nRenaming of Artboards to match Layer names is complete"); 

Votes

Translate

Translate

Report

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
Valorous Hero ,
Jul 06, 2017 Jul 06, 2017

Copy link to clipboard

Copied

LATEST

You don't have the artboards being used as a property of a document object, are they still working for you?
Well I think your problem is that you specify your 'thru-cut' art as layers, while they are not layers. Layers have hasSelectedArtwork property, while art - or the items inside of layers - have the .selected property. In your case you'd change your code to: thisLayer.selected = true;

Votes

Translate

Translate

Report

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