Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 23 of 23

Thread: AutoCAD VBA - Change all objects to Lay 0

  1. #21
    VBAX Newbie
    Joined
    Jan 2009
    Posts
    2
    Location
    Many thanks, Fixo!! I stepped into the code and found it that it only changes the color if the layer was locked. I tweaked it a little and it works great.

    Sorry, Lucas. I debated on whether or not to start a new thread, but I thought the code was related enough to use this one.

  2. #22
    VBAX Regular fixo's Avatar
    Joined
    Jul 2006
    Location
    Sankt-Petersburg
    Posts
    99
    Location
    Sorry my bad
    Try this one instead
    (not tesded though because of
    I can't rich Acad at the moment)

     
    Option Explicit
    Sub ChangeLayersColor()
         On Error Resume Next
         Dim oLayer As AcadLayer, itmLay As Variant, i As Long
         Dim lockedColl As New Collection
         With ThisDrawing
              For Each oLayer In .Layers
                   'unlock layer if this was locked
                   If oLayer.Lock = True Then
                        oLayer.Lock = False
                   ' add layer name to collection with key that allow to add just iniques only
                   i = i + 1
                   lockedColl.Add oLayer.Name, CStr(i)
                   End If
                        oLayer.color = acWhite
              Next
              .Regen acAllViewports
              For Each itmLay In lockedColl
              'then turn back to lock all the unlocked layers
              .Layers.item(itmLay).Lock = True
              Next
         End With
    End Sub
    ~'J'~

  3. #23
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Quote Originally Posted by Spike
    Many thanks, Fixo!! I stepped into the code and found it that it only changes the color if the layer was locked. I tweaked it a little and it works great.

    Sorry, Lucas. I debated on whether or not to start a new thread, but I thought the code was related enough to use this one.
    It definitely is closely related spike.........I should read before I post.
    Sounds like you found your solution.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •