×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

AutoCAD LSP; delete unused layers and rename layer

AutoCAD LSP; delete unused layers and rename layer

AutoCAD LSP; delete unused layers and rename layer

(OP)
In a nutshell, I'm trying to create an LSP that will
1) erase all unused/frozen layers
2) create a new layer call CUTOUTS
3) Color this layer Red.

Issues:
1) LSP is only erasing both hidden and frozen layers if a frozen layer is present to initiate this routine.
2) Works well, but i'd like it to make everything displayed to also be put onto this new layer
3) The xref layer is red but the 'object' layer remains white. (i can explain further if needed)

My code thus far:


(defun c:KK (/ ActDoc LayList LayNameList)
    ;; Erases all objects on frozen/off layers, then purges drawing.
    
    (vl-load-COM)

    (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (vlax-for Lay (vla-get-Layers ActDoc)
        (if
            (or
                (= (vla-get-LayerOn Lay) ':vlax-false)
                (= (vla-get-Freeze Lay) ':vlax-true)
            )
            (progn
                (vla-put-Lock Lay :vlax-false)
                (setq LayList (cons Lay LayList)
                    LayNameList (cons (vla-get-Name Lay) LayNameList)
                )
            )
        )
    )

    (vla-StartUndoMark ActDoc)
    (if LayList
        (progn
            (vlax-for Layout (vla-get-Layouts ActDoc)
                (vlax-for Obj (vla-get-Block Layout)
                    (if (member (vla-get-Layer Obj) LayNameList)
                        (vla-Delete Obj)
                    )
                )
            )
            (vla-PurgeAll ActDoc)
        )
    )
    (vla-EndUndoMark ActDoc)


; Create and change color of layer to CUTOUTS and red respectively
; Layers

(command "layer" "m" "CUTOUTS" "lt" "continuous" "" "c" "1" "" "")

; Initial System Variables
(setvar "lunits" 4)
(setvar "luprec" 4)
(setvar "aunits" 0)
(setvar "auprec" 4)
(setvar "angdir" 0)
(setvar "dimadec" 4)
(setvar "filletrad" 0)
(setvar "ucsicon" 1)
(setvar "osmode" 43)
(command "limits" "0,0" "120,90")
(command "zoom" "all")



  (Princ "\n   ***ALL - Unused and Frozen Layers are now GONE!!!***")
  (Princ "\n============================================================================")
  (Princ "\n   ***IMPORTANT - if no frozen layers present, purge will not complete.")
  (Princ "\n============================================================================")
  (princ)
)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources