rwsice9 Posted April 26, 2013 Posted April 26, 2013 Hey guys. I have a LISP I wrote this morning that asks for an insertion point, grabs the layer of the object, then draws a MLEADER on an associated layer. I have it working completely, except when a block is selected. Can anyone take a look at the code and help out? Thanks in advance! (defun c:wtags (/ p1 ) (setq oldlayer (getvar "clayer")) (setq os (getvar "osmode")) (setvar "osmode" 531) (setq p1 (getpoint "\nSelect wire to tag: ")) (setq ent (entget (car (nentselp p1)))) (setq wlayer (cdr (assoc 8 ent))) (if (= wlayer "F-ALRM-WIRE")(setvar "clayer" "F-ANNO-TAGS")) (if (= wlayer "F-ALRM-WIRE-SPKR")(setvar "clayer" "F-ANNO-TAGS-SPKR")) (if (= wlayer "F-ALRM-WIRE-INDC")(setvar "clayer" "F-ANNO-TAGS-INDC")) (if (= wlayer "F-ALRM-WIRE-DTCT")(setvar "clayer" "F-ANNO-TAGS-DTCT")) (if (= wlayer "F-ALRM-WIRE-PWR")(setvar "clayer" "F-ANNO-TAGS-PWR")) (if (= wlayer "F-ALRM-WIRE")(SETQ TAG "")) (if (= wlayer "F-ALRM-WIRE-SPKR")(SETQ TAG "S")) (if (= wlayer "F-ALRM-WIRE-INDC")(SETQ TAG "V")) (if (= wlayer "F-ALRM-WIRE-DTCT")(SETQ TAG "M")) (if (= wlayer "F-ALRM-WIRE-PWR")(SETQ TAG "P")) (command "_MLeader" p1 pause tag) (setvar "osmode" os) (setvar "clayer" oldlayer) ) Quote
Lee Mac Posted April 26, 2013 Posted April 26, 2013 (edited) Try something like this rwsice9: (defun c:wtags ( / *error* la pt ss vl vr wl ) (defun *error* ( msg ) (mapcar 'setvar vr vl) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (setq vr '(clayer osmode cmdecho) vl (mapcar 'getvar vr) ) (setvar 'osmode 531) (setvar 'cmdecho 0) (if (setq pt (getpoint "\nSelect Wire to Tag: ")) (if (setq ss (ssget pt)) (if (wcmatch (setq wl (strcase (cdr (assoc 8 (entget (ssname ss 0)))))) "F-ALRM-WIRE*") (progn (setq wl (substr wl 12) la (strcat "F-ANNO-TAGS" wl) ) (if (tblsearch "LAYER" la) (command "_.-layer" "_U" la "_T" la "_ON" la "_S" la "") (command "_.-layer" "_M" la "") ) (command "_.mleader" "_non" pt "\\" (cond ( (= wl "-SPKR") "S") ( (= wl "-INDC") "V") ( (= wl "-DTCT") "M") ( (= wl "-PWR") "P") ( "" ) ) ) ) (princ "\nObject not on \"F-ALRM-WIRE*\" layer.") ) (princ "\nNo Object found at selected point.") ) ) (*error* nil) (princ) ) Edited April 26, 2013 by Lee Mac Quote
rwsice9 Posted April 26, 2013 Author Posted April 26, 2013 Thanks Lee! Works perfect as far as setting the correct layers, but it doesn't want to fill in the text now. I do appreciate the help! Quote
Lee Mac Posted April 26, 2013 Posted April 26, 2013 Thanks Lee! Works perfect as far as setting the correct layers, but it doesn't want to fill in the text now. I do appreciate the help! Oops! Sorry, I forgot the hyphen on each of the layer name patterns. I have now corrected the above code, and have used a cond expression in place of an association list for safety, should the layer name pattern not appear in the list. Quote
Lee Mac Posted April 26, 2013 Posted April 26, 2013 You're very welcome! Ask if you have any questions about the code. Quote
rwsice9 Posted April 29, 2013 Author Posted April 29, 2013 I think I sort of at least understand what the code is doing, but not enough to modify on my own with no help. I do have one last question for you (I think). Is there a way to have it prompt for an MLEADER value when the object selected is on the F-ALRM-WIRE layer? While most of the layers have pre-set tags, the general F-ALRM-WIRE layer does not. The current code just draws in the blank mleader. (dont get me wrong, the code you whipped up is awesome ) Quote
Lee Mac Posted April 29, 2013 Posted April 29, 2013 I do have one last question for you (I think). Is there a way to have it prompt for an MLEADER value when the object selected is on the F-ALRM-WIRE layer? Sure, try this: (defun c:wtags ( / *error* la pt ss vl vr wl ) (defun *error* ( msg ) (mapcar 'setvar vr vl) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (setq vr '(clayer osmode cmdecho) vl (mapcar 'getvar vr) ) (setvar 'osmode 531) (setvar 'cmdecho 0) (if (setq pt (getpoint "\nSelect Wire to Tag: ")) (if (setq ss (ssget pt)) (if (wcmatch (setq wl (strcase (cdr (assoc 8 (entget (ssname ss 0)))))) "F-ALRM-WIRE*") (progn (setq wl (substr wl 12) la (strcat "F-ANNO-TAGS" wl) ) (if (tblsearch "LAYER" la) (command "_.-layer" "_U" la "_T" la "_ON" la "_S" la "") (command "_.-layer" "_M" la "") ) (command "_.mleader" "_non" pt "\\") (cond ( (= wl "-SPKR") (command "S")) ( (= wl "-INDC") (command "V")) ( (= wl "-DTCT") (command "M")) ( (= wl "-PWR") (command "P")) ( (command "" "_.ddedit" (entlast) "")) ) ) (princ "\nObject not on \"F-ALRM-WIRE*\" layer.") ) (princ "\nNo Object found at selected point.") ) ) (*error* nil) (princ) ) Quote
rwsice9 Posted April 29, 2013 Author Posted April 29, 2013 Sure, try this: ( (command "" "_.ddedit" (entlast) "")) I probably should have been able to figure that one out.. Now that I see it it seems like the obvious solution. Thanks again, man. Works absolutely perfectly! Quote
rwsice9 Posted April 29, 2013 Author Posted April 29, 2013 And it even worked on the F-ALRM-WIRE-CTRL layer! That's not even in the code at all!! Awesome! Quote
Lee Mac Posted April 29, 2013 Posted April 29, 2013 I probably should have been able to figure that one out.. Now that I see it it seems like the obvious solution. Thanks again, man. Works absolutely perfectly! And it even worked on the F-ALRM-WIRE-CTRL layer! That's not even in the code at all!! Awesome! Excellent to hear dude Cheers! Quote
rwsice9 Posted May 3, 2013 Author Posted May 3, 2013 Well, now that we have this all working properly, the company has changed their mind about what layer the mleaders should be on. Now they want them to be on whichever WIRE layer. I modified the code you wrote to do that, however this has created another issue. A couple of the wire layers are not a "continuous" linetype. How can I add a linetype override in the code to force all the leaders to be drawn with the continuous linetype? Once again, thank you very much for all the help! (defun c:wtags ( / *error* la pt ss vl vr wl ) (defun *error* ( msg ) (mapcar 'setvar vr vl) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (setq vr '(clayer osmode cmdecho) vl (mapcar 'getvar vr) ) (setvar 'osmode 531) (setvar 'cmdecho 0) (if (setq pt (getpoint "\nSelect Wire to Tag: ")) (if (setq ss (ssget pt)) (if (wcmatch (setq wl (strcase (cdr (assoc 8 (entget (ssname ss 0)))))) "F-ALRM-WIRE*") (progn (setq wl (substr wl 12) la (strcat "F-ALRM-WIRE" wl) ) (if (tblsearch "LAYER" la) (command "_.-layer" "_U" la "_T" la "_ON" la "_S" la "") (command "_.-layer" "_M" la "") ) (command "_.mleader" "_non" pt "\\") (cond ( (= wl "-SPKR") (command "S")) ( (= wl "-INDC") (command "V")) ( (= wl "-DTCT") (command "M")) ( (= wl "-POWR") (command "P")) ( (= wl "-CTRL") (command "R")) ( (command "" "_.ddedit" (entlast) "")) ) ) (princ "\nObject not on \"F-ALRM-WIRE*\" layer.") ) (princ "\nNo Object found at selected point.") ) ) (*error* nil) (princ) ) Quote
Lee Mac Posted May 3, 2013 Posted May 3, 2013 Try this: (defun c:wtags ( / *error* la pt ss vl vr wl ) (defun *error* ( msg ) (mapcar 'setvar vr vl) (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))) (princ (strcat "\nError: " msg)) ) (princ) ) (setq vr '(clayer osmode cmdecho) vl (mapcar 'getvar vr) ) (setvar 'osmode 531) (setvar 'cmdecho 0) (if (setq pt (getpoint "\nSelect Wire to Tag: ")) (if (setq ss (ssget pt)) (if (wcmatch (setq wl (strcase (cdr (assoc 8 (entget (ssname ss 0)))))) "F-ALRM-WIRE*") (progn (setq wl (substr wl 12) la (strcat "F-ALRM-WIRE" wl) ) (if (tblsearch "LAYER" la) (command "_.-layer" "_U" la "_T" la "_ON" la [color=red]"_L" "Continuous" la[/color] "_S" la "") (command "_.-layer" "_M" la [color=red]"_L" "Continuous" la[/color] "") ) (command "_.mleader" "_non" pt "\\") (cond ( (= wl "-SPKR") (command "S")) ( (= wl "-INDC") (command "V")) ( (= wl "-DTCT") (command "M")) ( (= wl "-POWR") (command "P")) ( (= wl "-CTRL") (command "R")) ( (command "" "_.ddedit" (entlast) "")) ) ) (princ "\nObject not on \"F-ALRM-WIRE*\" layer.") ) (princ "\nNo Object found at selected point.") ) ) (*error* nil) (princ) ) Quote
rwsice9 Posted May 3, 2013 Author Posted May 3, 2013 Know what I just realized? All I needed to do was modify the MLeader style to make the linetype continuous.. duh! Thanks again! Quote
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.