I found a lisp in an old post and I edited it alittle with my own layers to have it change to but when I use it, it doesn't deleted the extra layers. It says layer cannot be deleted. Below is part of the code that I am using, I didn't copy all of them since there are alot of layers in the lisp that I added. Any help would be great. maybe I copied something wrong I am not sure.
{code}
( defun c:FIXMYLAYERS ( / ss_newlayer change_en )
( setq layerlist ( list ( cons "ENB_ROW-1" "ENB-ROW-1" )
( cons "Border_Condoc_DwgMgmt_Large$0$G-ANNO-TTLB" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Large$0$G-ANNO-TTLB-LOGO" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Large$0$G-ANNO-TTLB-NPLT" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Large$0$G-ANNO-TTLB-TEXT" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Small$0$G-ANNO-TTLB-LOGO" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Small$0$G-ANNO-TTLB-NPLT" "DefPoints" )
( cons "Border_Condoc_DwgMgmt_Small$0$G-ANNO-TTLB-TEXT" "DefPoints" )
( cons "DEFPPOINTS" "DefPoints" )
( cons "E-ANNO-REVC-0001" "AE NOTES" )
( cons "E-ANNO-REVC-0002" "AE NOTES" )
( cons "E-ANNO-REVS-0001" "AE NOTES" )
( cons "E-ANNO-REVS-0002" "AE NOTES" )
( cons "E-CLNG" "CEILING" )
( cons "ED-FIRE-CLNG" "AE FIRE ALARM" )
( cons "ED-LITE-SWCH" "AE ELECTRICAL" )
( cons "E-DP-2D$0$AD-BLDG" "FLOORPLAN" )
( cons "E-DP-2D$0$AE-AREA-IDEN" "ROOM TAG" )
( cons "E-DP-2D$0$AE-AREA-OCCP" "ROOM TAG" )
( cons "E-DP-2D$0$AE-DOOR" "FLOORPLAN" )
( cons "E-DP-2D$0$AE-EQPM" "EQUIPMENT" )
( cons "E-DP-2D$0$AE-EQPM-OVHD" "EQUIPMENT" )
( cons "E-DP-2D$0$AE-EQPM-UNDR" "EQUIPMENT" )
( cons "E-DP-2D$0$AE-FLOR" "MISC" )
( cons "E-DP-2D$0$AE-FLOR-CASE" "FURNITURE" )
( cons "E-DP-2D$0$AE-FLOR-CASE-OVHD" "FURNITURE" )
( cons "E-DP-2D$0$AE-FLOR-CASE-UNDR" "FURNITURE" )
( cons "E-DP-2D$0$AE-FLOR-EVTR" "MISC" )
( cons "E-DP-2D$0$AE-FLOR-OVHD" "MISC" )
( cons "E-DP-2D$0$AE-FLOR-SPCL" "MISC" )
( cons "E-DP-2D$0$AE-FLOR-STRS" "FLOORPLAN" )
( cons "E-DP-2D$0$AE-FLOR-STRS-HRAL" "FLOORPLAN" )
( cons "E-DP-2D$0$AE-AREA-IDEN" "ROOM TAG" )
( cons "AE FIRE ALARM" "AE FIRE ALARM" )
( cons "TOPO-FENCE-200" "FENCE-200" )
( cons "HATCH-250" "HTCH-250" ) );list
);sq
( foreach item layerlist
( if ( and ( tblsearch "Layer" ( car item ) )
( not ( tblsearch "Layer" ( cdr item ) )) );a
( command "-Layer" "Rename" ( car item ) ( cdr item ) "" )
);i
);fe
( setq ss_newlayer ( ssget "X" ))
( while ( setq change_en ( ssname ss_newlayer 0 ))
( setq ss_newlayer ( ssdel change_en ss_newlayer ))
( if ( assoc ( cdr ( assoc 8 ( entget change_en ))) layerlist )
( entmod ( subst ( cons 8 ( cdr ( assoc ( cdr ( assoc 8 ( entget change_en ))) layerlist ))) ( assoc 8 ( entget change_en )) ( entget change_en ) ))
);i
);w
( foreach item layerlist
( if ( tblsearch "Layer" ( car item ) )
( command "-Layer" "Delete" ( car item ) "" )
);i
);fe
( princ "\nFinished:" )(princ ))
{code}
Solved! Go to Solution.
Solved by brettgr. Go to Solution.
Your dwg contains AEC 3D objects such as walls, windows, doors...
You can try the AECTOACAD (-EXPORTTOAUTOCAD) command, this command will transform all AEC objects in AutoCAD entities, if when you run the command the dwg view is the top view, all the AEC 3d data will be removed...
Open the new dwg and run the SETBYLAYER command...
Henrique
Is there a way for wcmatch to not be case sensitive? Example when I have this in my program-- *DEMO* it will not change layers that are labled Demo. I have been using this alot been doing good.
@brettgr wrote:
Is there a way for wcmatch to not be case sensitive? Example when I have this in my program-- *DEMO* it will not change layers that are labled Demo. I have been using this alot been doing good.
"wcmatch" is case sensitive, one solution is use uppercase, with the "strcase" function, try replacing the "hms:LayerListx" with this one
(defun hms:LayerListx (pattern / TblName TblNameList) (while (setq TblName (tblnext "Layer" (null TblName))) (setq TblNameList (cons (cdr (assoc 2 TblName)) TblNameList)) );; while (setq TblNameList (vl-remove-if-not '(lambda (s) (wcmatch s pattern)) TblNameList)));; hms:LayerListx
HTH
Henrique
If I am reading this right I believe that what you posted I already had in my lisp I will attach what my LISP to this post for you to see.
@brettgr wrote:
If I am reading this right I believe that what you posted I already had in my lisp I will attach what my LISP to this post for you to see.
My mistake...
Supposed to be
(defun hms:LayerListx (pattern / TblName TblNameList) (while (setq TblName (tblnext "Layer" (null TblName))) (setq TblNameList (cons (strcase (cdr (assoc 2 TblName))) TblNameList)) );; while (setq TblNameList (vl-remove-if-not '(lambda (s) (wcmatch s pattern)) TblNameList)));; hms:LayerListx
Try the attached file.
Henrique
Thank you that worked!!
Awhile back you posted--
brettgr,
to include nested blocks, attributes, etc, your code should be rethought and rewritten, to become a well-structured and linear code, instead of a bunch of codes placed together, to make this, requires some time that I don't have...
However, I thought in another approach that it is slooooower (it uses AutoCAd commands), but I think it will work properly.
Henrique
I was wandering a couple things from this post. First thing is where is the best place to start to learn how to write LISP programs for AutoCAD. Hopefully somewhere someone like me that does not know a lot about programming? Second thing is you mentioned Well structured and linear code. What do you mean by that?
Brett
@brettgr wrote:
Thank you that worked!!
...
I was wandering a couple things from this post. First thing is where is the best place to start to learn how to write LISP programs for AutoCAD. Hopefully somewhere someone like me that does not know a lot about programming? Second thing is you mentioned Well structured and linear code. What do you mean by that?
Brett
You're welcome, Brett
To learn how to write LISP programs, you can start @ Afralisp, Lee Mac, jtbworld and the AutoCAD Developer Help (the Vlide Help)...
"Well structured and linear code"
Means that the code should be thought and written to have a continuous workflow, the easiest way to start thinking how the code supposed to be, is writing the code as a pseudo-code with all steps that the code will have, read it, try to cut steps which can be made with other steps and then try to write the code...
I hope my explanation was not too confusing...
Henrique
Thank you for the information! It will help me learn to program LISP's. No confusion it actually made sense. Thanks again for all your help!
I just came accross a drawing that gives me a error that says (Unhandled exception has occurred in a component in your application. If you click continue, the application will ignore this error and attempt to continue.) I have never had this come up before if you can take a look at it to see why I am receiving this err that would be great. I attached both the drawing and my translation lisp that I am currently using.
Hi Brett,
this would give an error
(command "setvar" "cmdecho" 0)
or you use the command call or the setvar function...
(command "cmdecho" 0)
(setvar 'CMDECHO 0)
but the error you are receiving the "Unhandled exception" is during the "setbylayer" command.
The dwg have 2 errors...
Command: audit
Fix any errors detected? [Yes/No] <N>: y
Auditing Header
Auditing Tables
Auditing Entities Pass 1
Pass 1 18200 objects audited
Auditing Entities Pass 2
Pass 2 17900 objects audited
AcDbPolyline(2090A) Invalid layer eWasErased $AUDIT-BAD-LAYER
AcDbBlockReference(2090B) Invalid layer eWasErased $AUDIT-BAD-LAYER
Pass 2 18200 objects audited
Auditing Blocks
67 Blocks audited
Total errors found 2 fixed 2
Erased 0 objects
Command:
To fix that, I added the "audit" command before the call to the "setbylayer" command, and the code don't give errors...
Attached is your file revised.
HTH
Henrique
Yeah after I messaged you I realized that it had to do with the setbylayer part of the lisp. The change you made worked out great Thanks! Is there ways to setbylayer for line type and lineweight?
Thanks,
Brett
You're welcome, Brett
SETBYLAYERMODE
1 = Color
2 = Linetype
4 = Lineweight
so, for Color, Linetype and Lineweight the SETBYLAYERMODE must be set to 7
EDIT: F1 and enter SETBYLAYERMODE, see the other options...
HTH
Henrique
When I went to help I didnt find 7 as a setting. Only found0,1,2,4,8,16,32,64,128. And if for some reason all of a suddent the drawing is now showing the error again.... I have no Idea what is going on it work just a few minutes ago haha. I have attached both again. The thing is tho if I run audit by myself it will run just fine. Maybe you can see something I cant see.
@brettgr wrote:
When I went to help I didnt find 7 as a setting. Only found0,1,2,4,8,16,32,64,128. And if for some reason all of a suddent the drawing is now showing the error again.... I have no Idea what is going on it work just a few minutes ago haha. I have attached both again. The thing is tho if I run audit by myself it will run just fine. Maybe you can see something I cant see.
1 + 2 + 4 = 7
Try to run the code that I attached in the previous post...
EDIT: I did, no errors in AutoCAD 2012.
Henriqhe
I would like to add something this auto layer translator but not sure where to start or if it is possible. What I am looking to do is add this end, something that will attsync to all attribues of all blocks in the drawing. I hope that is possible. I have attached my most recent lisp program.
Thanks for all your help,
Brett
What command do you use to select all blocks (beginner here) I know I can use QSELECT and block reference then select all. Not sure how to incorporate that into a lisp. And after do that do I just use the attsync command after I select all blocks? Or does it have to be done differnetly?
One way to run ATTSYNC on all block references:
(command ".ATTSYNC" "N" "*")
(Hint: run ATTSYNC on the command line and look at the options.)