Skip to main content
Participant
May 15, 2011
Question

Move paths to another layer VB-script

  • May 15, 2011
  • 1 reply
  • 26252 views

Hello.


This is my first post on this forum. I need help with making a script that selects all the paths in a document that has a certain line width, for example 3 pt, and move them to a specific layer.


Since my knowledge of javascript is limited I would like to have an example in vb script.


Thanks in advance


Tommy
This topic has been closed for replies.

1 reply

CarlosCanto
Community Expert
Community Expert
May 16, 2011

welcome to the forum, this is not VBS, it is VBA...but you'll get the idea

Sub move3ptPathsToOtherLayer()

    Dim iapp As New Illustrator.Application

    Dim idoc As Illustrator.Document

    Dim ilayer As Illustrator.Layer

    Dim ipath As Illustrator.PathItem

    Set idoc = iapp.ActiveDocument 'get active document

    Set ilayer = idoc.Layers("specificLayer") 'get specificLayer

    ilayerzorder = idoc.Layers.Index(ilayer) 'get layer zOrder placement

    ilayer.ZOrder aiSendToBack 'move to the bottom

    For i = idoc.PathItems.Count To 1 Step -1 'loop thru all pathItems backwards

        Set ipath = idoc.PathItems(i) 'get path

        If ipath.StrokeWidth = 3 Then 'check for size

            ipath.Move ilayer, aiPlaceAtBeginning 'move to specificLayer if size = 3 points

        End If

    Next

    'move layer back to its original position

    ilayer.Move idoc.Layers(ilayerzorder), aiPlaceBefore

    Set ipath = Nothing

    Set ilayer = Nothing

    Set idoc = Nothing

    Set iapp = Nothing

End Sub

fire_sweAuthor
Participant
May 16, 2011

Hi Carlos

Thanks! Your code snippet helped me alot!

With a few tweaks I managed to save a vbs script and it works perfectly!

Next step is to develop the script to create two layers for me, a thich and and a thin layer so I automaticly can seperate the line widths in my doucuments.

If I ran into problems I'm sure you guys here will here from me...

Here is the working vbs

Set appRef = CreateObject("Illustrator.Application")

     Set idoc = appRef.ActiveDocument 'get active document
    Set ilayer = idoc.Layers("Thick") 'get specificLayer

    ilayerzorder = idoc.Layers.Index(ilayer) 'get layer zOrder placement
    ilayer.ZOrder 4 'move to the bottom

    For i = idoc.PathItems.Count To 1 Step -1 'loop thru all pathItems backwards
        Set ipath = idoc.PathItems(i) 'get path
        If ipath.StrokeWidth = 4.25 Then 'check for size
            ipath.Move ilayer, 1 'move to specificLayer if size = 3 points
        End If
    Next

    'move layer back to its original position
    ilayer.Move idoc.Layers(ilayerzorder), 3

/Tommy

Sweden