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

illustrator selecting layers by name then "make mask" command

New Here ,
Mar 26, 2015 Mar 26, 2015

Copy link to clipboard

Copied

Hi guys,

I'm trying to get a vbscript to do this maybe easy task for some of you

I want to select 2 layers by name and then set the command :

NameA = "nomdeCalqueA"

NameB = "nomdeCalqueB"

Set appRef = CreateObject("Illustrator.Application")

        Set idoc = appRef.ActiveDocument

        appRef.activeDocument.Selection = Empty

     

    For Each targetDocument In appRef.Documents

        countOfLayers = targetDocument.Layers.Count

        For layerIndex = countOfLayers To 1 Step -1

            Set targetLayer = targetDocument.Layers(layerIndex)

                layerName = targetLayer.Name

                    If (InStr(layerName, NameA) = 1) Then

                    'then select my layer

                    End If

                    If (InStr(layerName, NameB) = 1) Then

                    'then select my layer

                    End If

Next

Next

     

        appRef.executeMenuCommand ("makeMask")

I'm a little lost...

Thank you for helping.

Nems.

TOPICS
Scripting

Views

1.2K

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
Adobe
Guide ,
Mar 26, 2015 Mar 26, 2015

Copy link to clipboard

Copied

the makeMask menu command makes a Clipping mask.

are you trying to create a clipping mask or a transparency mask?

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
New Here ,
Mar 26, 2015 Mar 26, 2015

Copy link to clipboard

Copied

Hi,

I'm trying to make a clipping mask, that's why 2 layers is need to be selected.

I didn't get how to make my two layers as active selections to excecute "makeMask"

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
Guide ,
Mar 26, 2015 Mar 26, 2015

Copy link to clipboard

Copied

I'm a Javascript kinda guy.

this will get you started...

selectAll('cut');

selectAll('art');

app.executeMenuCommand('makeMask');

function selectAll(layerName){

    stuff = app.activeDocument.layers.getByName(layerName);

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

        stuff.pageItems.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
Engaged ,
Mar 26, 2015 Mar 26, 2015

Copy link to clipboard

Copied

I am not aware that you can mask more than two elements, at least not to get the result that I suspect you desire. So what you will need to do, if you have more than one element on one or both layers, is to group the elements, select the two grouped elements, then mask them.

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
Guide ,
Mar 26, 2015 Mar 26, 2015

Copy link to clipboard

Copied

TT made me think.

if the cut layer has more then 1 item it wont give correct results.

make compound path first will help.

new script...

selectAll('cut');

$.sleep(500);

app.executeMenuCommand('compoundPath');

selectAll('art');

$.sleep(500);

app.executeMenuCommand('makeMask');

function selectAll(layerName){

    var stuff = app.activeDocument.layers.getByName(layerName);

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

        stuff.pageItems.selected = true;

    }

}

be aware this will move all items in the 2 layers to the cut layer

the sleep just helps reliability...

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
Engaged ,
Mar 26, 2015 Mar 26, 2015

Copy link to clipboard

Copied

LATEST

iDoc.Layers("Name") in VB.NET ...  try it for VBS or possibly iDoc.Layers.Item("Name").

Again -- just remember you're masking elements, not layers.

Since you're more comfortable with VB maybe this could help, albeit it VB.NET. Translation should be pretty easy for you though. Note: I just pop in GUIDs to temporarily name the groups. You can use a different naming convention.

Dim aDoc As Document = app.ActiveDocument
aDoc.Selection = False
Dim grp1 = CreateGroup(aDoc, "Layer 4")   'whatever layer name you want
app.ExecuteMenuCommand("compoundPath")
Dim grp2 = CreateGroup(aDoc, "Layer 2")   'whatever layer name you want
app.ExecuteMenuCommand("makeMask")


Private Function CreateGroup(aDoc As Document, layerName As String)
    Dim tmpGuid = Guid.NewGuid.ToString
    Dim layer As Layer = aDoc.Layers(layerName)
    Dim grp = layer.GroupItems.Add : grp.Name = tmpGuid
    For i = layer.PageItems.Count To 1 Step -1
        Dim pi = layer.PageItems(i)
        If Not pi.Name = tmpGuid Then pi.Move(layer.PageItems(tmpGuid), AiElementPlacement.aiPlaceInside)
    Next
    layer.PageItems(tmpGuid).Selected = True
    Return layer.PageItems(tmpGuid)
End Function

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
New Here ,
Mar 26, 2015 Mar 26, 2015

Copy link to clipboard

Copied

Hi Guys,

thank you for giving answers.

My script will be launched on a file with a layer including a path and a layer including a photo, all other layers are hidden.

Now I need to translate your javascript in vbscript because it is used in an HTA file.

does someone know what could be "layers.getByName(layerName)" in vbscript?

thank you again.

Nems.

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