Jump to content
laurell

AutoLISP delete layers

Recommended Posts

laurell

Hello,

 

I am a newbie to AutoLISP and need to write a program to delete all layers in a file except these: Fixture-Shapes, CHECKLANE, Arch-Wall-Interior (Construction), Arch-Wall-Interior, Arch-Wall-Exterior. Here's what I have so far - I'm getting the error message: "error: malformed list on input"

 

 

(defun c:deletelayer2 (/ ss)

; get layers to keep
; if object not on these layers, delete
; purge - delete empty layers

; select all things NOT on these layers.  "_x" is a filter that selects all.
   (if (setq ss (ssget "_x" ' ((-4 . "<NOT")
                               (8 . "Fixture-Shapes, CHECKLANE, Arch-Wall-Interior (Construction), Arch-Wall-Interior, Arch-Wall-Exterior")
                               (-4. "NOT>"))))
       (command "._erase" ss "")
   ;    (prompt "\n** Nothing selected ** ")
   (princ)

)
) 

Thank you!

Share this post


Link to post
Share on other sites
BlackBox

Welcome to CADTutor, laurell!

 

Have you already considered the PURGE, and LAYDEL Commands?

 

As for deleting layers, the code you posted has a couple of mistakes (no biggie), but I am more interested in knowing more about what you're trying to do exactly? Your code deletes entities on all layers except those which you wish to retain, and not the layers on which those entities reside.

 

More information is needed.

Share this post


Link to post
Share on other sites
MSasu

The code from first post had the paranthesis balanced, did you edited it meantime? However, there is a syntax error in this line - there must be a space in front of the dot:

(-4[color=red][b].[/b][/color] "NOT>")

 

Do you have other layers that start with "Arch-Wall-" prefix? If not, you may write the filter as:

(8 . "Fixture-Shapes,CHECKLANE,Arch-Wall-*")

Share this post


Link to post
Share on other sites
laurell
Welcome to CADTutor, laurell!

 

Have you already considered the PURGE, and LAYDEL Commands?

 

As for deleting layers, the code you posted has a couple of mistakes (no biggie), but I am more interested in knowing more about what you're trying to do exactly? Your code deletes entities on all layers except those which you wish to retain, and not the layers on which those entities reside.

 

More information is needed.

 

Thanks everyone for your help!

 

RenderMan,

I'm trying to remove all unneeded info from .DWG files that I receive so they will not bog down my computer when I export to .PDF and edit in Illustrator. I know that the only information I actually need is on the specified layers. Ideally I'd like to delete all other layers and the artwork on them.

 

Thank you!

Share this post


Link to post
Share on other sites
pBe

Have you already considered the PURGE, and LAYDEL Commands?

 

1+ on PURGE and LAYDEL

 

...(command "._erase" ss "")...

Thank you!

 

Welcome to CADTutor, laurell!

 

Using erase command wont do you any good. If there are entiteis on layouts other than model or inside a block on the layer to be deleted

 

_Laydel will delete these entities and the layer itself regardless of space , only thing you need to do is ensure its unlock and not the current layer.

 

This code will delete all layers except those on the list

(defun c:demo  (/ aDoc name)
     (setvar 'Clayer "0")
     (repeat 4
           (vla-purgeall
                 (setq aDoc (vla-get-ActiveDocument
                                  (vlax-get-acad-object)))))
     (vlax-for
            itm
                 (vla-get-layers aDoc)
           (if (and
                     (not (wcmatch
                                (setq name (vla-get-name itm))
                                "*|*"))
                     (not (eq name "0"))
                     (not (member name
                                  '("thislayer1"
                                    "thislayer2"
                                    "thislayer3"))))
                 (progn
                       (vla-put-lock itm :vlax-false)
                       (vl-cmdf "_.-laydel" "_N" name "" "_Y"))
                 )
           )
     (repeat 4 (vla-purgeall aDoc))
     (princ)
     )

 

Now if you want to delete only those on the list

replace this line

[b](not [/b](member name   '("thislayer1" "thislayer2" "thislayer3"))[b])[/b]

with this

(member name   '("thislayer1" "thislayer2" "thislayer3"))

 

HTH

Edited by pBe

Share this post


Link to post
Share on other sites
laurell

pBe,

 

This works beautifully! Thank you :D

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...