laurell Posted June 27, 2012 Share Posted June 27, 2012 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! Quote Link to comment Share on other sites More sharing options...
BlackBox Posted June 27, 2012 Share Posted June 27, 2012 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 27, 2012 Share Posted June 27, 2012 Here is a quick reference providing some brief explanations for common error messages to enable you to diagnose the problem: http://lee-mac.com/errormessages.html Quote Link to comment Share on other sites More sharing options...
MSasu Posted June 28, 2012 Share Posted June 28, 2012 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-*") Quote Link to comment Share on other sites More sharing options...
laurell Posted July 6, 2012 Author Share Posted July 6, 2012 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! Quote Link to comment Share on other sites More sharing options...
pBe Posted July 7, 2012 Share Posted July 7, 2012 (edited) 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 July 7, 2012 by pBe 1 Quote Link to comment Share on other sites More sharing options...
laurell Posted July 9, 2012 Author Share Posted July 9, 2012 pBe, This works beautifully! Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.