The Buzzard Posted July 30, 2010 Share Posted July 30, 2010 Kind of off topic but still related. FWIW, technically speaking you dont really need to search the database for a layer name with entmake. However, you would if you needed to decide to either use ENTMAKE or ENTMOD something like the following: (defun DSTYLE3_LAYER_CREATE (LNAM$ LCLR# LTYP$ LWGT# #prog) (if (null (tblsearch "layer" LNAM$)) (set '#prog (lambda ( x ) (entmake x))) (set '#prog (lambda (x / ent y) (setq LNAM$ "TestLayer2") (setq ent (entget (tblobjname "LAYER" LNAM$))) (foreach y x (if (not (member (car y) '(0 100 2))) (setq ent (subst y (assoc (car y) ent) ent)))) (entmod ent) ))) (#prog (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 LNAM$) (cons 6 LTYP$) (cons 62 LCLR#) (cons 70 0) (cons 290 1) (cons 370 LWGT#) ) ) (princ) ) So using this... (DSTYLE3_LAYER_CREATE "Test-Layer" 1 "Continuous" 18) ;; would create the layer (DSTYLE3_LAYER_CREATE "Test-Layer" 2 "Continuous" 18) ;; would override the current layer def. Se7en, I am not sure that I understand you correctly, But don't you need to check for the existence of the layer before making it in any case? Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 30, 2010 Share Posted July 30, 2010 ENTMAKE wont REmake the layer; let me set up a test for you. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted July 30, 2010 Share Posted July 30, 2010 ENTMAKE wont REmake the layer; let me set up a test for you. Ok, So you are saying in the code I posted, Its basicly useless. Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 30, 2010 Share Posted July 30, 2010 no, why would it be useless? ...and BTW IMO nothing is useless! Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted July 30, 2010 Share Posted July 30, 2010 no, why would it be useless? ...and BTW IMO nothing is useless! I am sorry, I thought thats what you were implying. My mistake. Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 30, 2010 Share Posted July 30, 2010 ...oops, and it looks like i forgot the slash in the arg list "(LNAM$ LCLR# LTYP$ LWGT# / #prog)" too. here is the test: (defun DSTYLE3_LAYER_CREATE (LNAM$ LCLR# LTYP$ LWGT# / #prog) ;;; (if (null (tblsearch "layer" LNAM$)) ;;; (set '#prog (lambda ( x ) (entmake x))) ;;; (set '#prog (lambda (x / ent y) ;;; (setq ent (entget (tblobjname "LAYER" LNAM$))) ;;; (foreach y x ;;; (if (not (member (car y) '(0 100 2))) ;;; (setq ent (subst y (assoc (car y) ent) ent)))) ;;; (entmod ent) ))) ;;; (#prog ;;; ;;; commented out for test reasons. (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 LNAM$) (cons 6 LTYP$) (cons 62 LCLR#) (cons 70 0) (cons 290 1) (cons 370 LWGT#) ) ) ;;; (princ) ;;; un commented so we can see what entmake will return ) (DSTYLE3_LAYER_CREATE "Test-Layer" 1 "Continuous" 18) ;; would create the layer ;; and entmake will return the ent list... ;; (DSTYLE3_LAYER_CREATE "Test-Layer" 2 "Continuous" 18) ;; entmake will not re-create the layer and just returns nil. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted July 30, 2010 Share Posted July 30, 2010 Ok, I get your point. On the second layer call it did not overwrite the layer color from the first. Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 30, 2010 Share Posted July 30, 2010 Alright here is the second part of the test code. (defun DSTYLE3_LAYER_CREATE (LNAM$ LCLR# LTYP$ LWGT# / #prog) (if (null (tblsearch "layer" LNAM$)) (set '#prog (lambda ( x ) (entmake x))) (set '#prog (lambda (x / ent y) (setq ent (entget (tblobjname "LAYER" LNAM$))) (foreach y x (if (not (member (car y) '(0 100 2))) (setq ent (subst y (assoc (car y) ent) ent)))) (entmod ent) ))) (#prog ;;; (entmake ;;; ;;; commented out for test reasons. (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 LNAM$) (cons 6 LTYP$) (cons 62 LCLR#) (cons 70 0) (cons 290 1) (cons 370 LWGT#) ) ) ;;; (princ) ;;; un commented so we can see what entmake will return ) (DSTYLE3_LAYER_CREATE "Test-Layer" 1 "Continuous" 18) ;; would create the layer ;; and entmake will return the ent list... ;; (DSTYLE3_LAYER_CREATE "Test-Layer" 2 "Continuous" 18) ;; since entmake will not re-create the layer and just returns nil ;; we substitue the command to call enmake with a set of process ;; using entmod instead to redefine an existing layer. Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 30, 2010 Share Posted July 30, 2010 Ok, I get your point. On the second layer call it did not overwrite the layer color from the first. yeah. you got it. its because entmake will not recreate the layer. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted July 30, 2010 Share Posted July 30, 2010 yeah. you got it.its because entmake will not recreate the layer. Ok, But in the second situation it did modify the layer color. I see what you mean now. Thanks for that. Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 30, 2010 Share Posted July 30, 2010 no prob. Just so you know, you will still have to take a closer look and fix all my typo's in the example(s) i gave you because i didnt spend a whole lot of time typing and checking it (I just whipped it up as a conversation piece). Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted July 30, 2010 Share Posted July 30, 2010 Not to stir-up a debate, But when I used it in my code it was only to avoid running the layer function if it was not needed even if it does not overwrite the layer. But this was still interesring all the same. Thanks for the lesson. Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 30, 2010 Share Posted July 30, 2010 I kinda gleaned that (your intension's) from your code (thats why its not useless; it keeps ENTMAKE from even executing if the layer does exist) but, little details like this can make your code more robust for the end users. However, and this is a big "however", you need to keep these tricks well documented and segregated in your code lib's or create "black-box" type of procedures so that these sub procedures dont screw up some thing else. Trust me, i have dozens of lisp files i haven't even been able to clean up (and ive been here for three years) from my predecessor whom i now believe was addicted to crack or maybe even just a crack-pot! I spent months just replacing 20-30 line utility procedures (bloated code) with simple "one-liners"; I'm still finding mistakes. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted July 30, 2010 Share Posted July 30, 2010 I am still in my learning stage, But certain things that I pick up along the way I try to retain. Do not get me wrong, I am not trying to be a lisp programmer by any means. I would have moved on to other areas of it by now, But I stick with certain things for the primary reason of being some kind of help to customize AutoCAD for certain areas, And I am content with this. There is always room to learn something new, But its not a pressing issue with me. I will try not to bark in area that I am not familiar with unless there it is something to help improve the current knowledge I have gotton so far. I like how you approached it and were not critical over how I did this code. You had something to offer and I appreciate that. Thanks Quote Link to comment Share on other sites More sharing options...
autolisp Posted July 31, 2010 Author Share Posted July 31, 2010 autolisp,Attached is the layer fix. Type DSTYLE3 to start program. dear sir thx for help nice lisp Quote Link to comment Share on other sites More sharing options...
autolisp Posted July 31, 2010 Author Share Posted July 31, 2010 ...oops, and it looks like i forgot the slash in the arg list "(LNAM$ LCLR# LTYP$ LWGT# / #prog)" too. here is the test: (defun DSTYLE3_LAYER_CREATE (LNAM$ LCLR# LTYP$ LWGT# / #prog) ;;; (if (null (tblsearch "layer" LNAM$)) ;;; (set '#prog (lambda ( x ) (entmake x))) ;;; (set '#prog (lambda (x / ent y) ;;; (setq ent (entget (tblobjname "LAYER" LNAM$))) ;;; (foreach y x ;;; (if (not (member (car y) '(0 100 2))) ;;; (setq ent (subst y (assoc (car y) ent) ent)))) ;;; (entmod ent) ))) ;;; (#prog ;;; ;;; commented out for test reasons. (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 LNAM$) (cons 6 LTYP$) (cons 62 LCLR#) (cons 70 0) (cons 290 1) (cons 370 LWGT#) ) ) ;;; (princ) ;;; un commented so we can see what entmake will return ) (DSTYLE3_LAYER_CREATE "Test-Layer" 1 "Continuous" 18) ;; would create the layer ;; and entmake will return the ent list... ;; (DSTYLE3_LAYER_CREATE "Test-Layer" 2 "Continuous" 18) ;; entmake will not re-create the layer and just returns nil. dear se7en i test u r code but some error Command: dstyle3 ; error: no function definition: DSTYLE3_DIMSTYLE_CREATE Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted July 31, 2010 Share Posted July 31, 2010 dear se7eni test u r code but some error Command: dstyle3 ; error: no function definition: DSTYLE3_DIMSTYLE_CREATE Your welcome for the code autolisp, But the code that Se7en supplied was a test procedure for dealing with layers in different ways only and is not a dimension code at all. It does work, But you need to set it up properly. Quote Link to comment Share on other sites More sharing options...
autolisp Posted July 31, 2010 Author Share Posted July 31, 2010 Your welcome for the code autolisp, But the code that Se7en supplied was a test procedure for dealing with layers in different ways only and is not a dimension code at all. It does work, But you need to set it up properly. dear sir thx agian for help me 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.