Locked and Loaded Posted June 28, 2012 Posted June 28, 2012 Hello Everyone, This is my first time on this forum, so forgive me if this has been posted already. I am trying to write a lisp routine, im noob as on lisps and I am trying to do the following: ;;============================================= ;; ;; Description: Place a HALO effect around selected multileader entities. ;; ;; Note: This works for AutoCAD shape files and not True Type Fonts. ;; ;;============================================= (defun c:halo () (setq FLTR '( (-4 . " (0 . "MULTILEADER") (-4 . "OR>") ) ) (Princ "\nSelect Multileader to HALO (CAN NOT be a true type font)...") (princ "\nPress ENTER after selecting entities to process them...") (setq SS (ssget FLTR)) (command "_.copy" ss "" "0,0" "0,0") (command "_.layer" "m" "halotext255" "c" "255" "" "lw" "2" "" "") (command "_.chprop" ss "" "_la" "halotext255" "p" "c" "bylayer" "") ;(command "_.draworder" ss "" "a" "p") ) Now what i want to do, I using quickselect, I want to select all the multileaders on layer 'halotext255', explode them, then select the exploded leaeder (1 x solid, 1 x polyline and 1 x line on layer 'halotext255) and delete them, leaving only the mtext underneath the text of the mleader. Any advice/help is greatly appreciated. Quote
asos2000 Posted June 28, 2012 Posted June 28, 2012 - First Entmake is better than command in creating objects instead of (command "_.layer" "m" "halotext255" "c" "255" "" "lw" "2" "" "") Use (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 Nme) (cons 70 0) (cons 62 Col) (cons 6 Ltyp) (cons 290 Plt) (cons 370 LWgt))) and use AutoCAD 2011 DXF Reference for DXF codes - Dont use unneeded variables instead of (setq FLTR '((-4 . "<OR") (0 . "MULTILEADER") (-4 . "OR>"))) (setq SS (ssget FLTR)) use (setq SS (ssget '((-4 . "<OR") (0 . "MULTILEADER") (-4 . "OR>")))) PS: refer to Code posting guidelines Quote
MSasu Posted June 28, 2012 Posted June 28, 2012 Use EXPLODE command to broke the MLeader entity and keep in mind that the result of this operation is stored as Previous selection set; next parse this to retain only desired entity. There is no need for a logical filter as long you are looking for only one type: (setq FLTR '([s][color=red](-4 . "<OR")[/color][/s] (0 . "MULTILEADER") [s][color=red](-4 . "OR>")[/color][/s] ) ) Quote
MSasu Posted June 28, 2012 Posted June 28, 2012 This example may help you: (if (setq ssetMLeaders (ssget "_:S" '((0 . "MULTILEADER")))) (progn (command "_EXPLODE" (ssname ssetMLeaders 0)) (setq ssetItems (ssget "_P")) (repeat (setq index (sslength ssetItems)) (setq assocItem (entget (ssname ssetItems (setq index (1- index))))) (if (/= (cdr (assoc 0 assocItem)) "MTEXT") (entdel (cdr (assoc -1 assocItem))) ) ) ) ) Quote
Locked and Loaded Posted July 2, 2012 Author Posted July 2, 2012 This example may help you: (if (setq ssetMLeaders (ssget "_:S" '((0 . "MULTILEADER")))) (progn (command "_EXPLODE" (ssname ssetMLeaders 0)) (setq ssetItems (ssget "_P")) (repeat (setq index (sslength ssetItems)) (setq assocItem (entget (ssname ssetItems (setq index (1- index))))) (if (/= (cdr (assoc 0 assocItem)) "MTEXT") (entdel (cdr (assoc -1 assocItem))) ) ) ) ) MSasu, That code works, but is there a way I can set the code so I dont have to select it manually, can I 'select previous' for this code, this is how I have incorprated it into my code: ;; Description: Place a HALO effect around selected multileader entities. ;; ;; Note: This works for AutoCAD shape files and not True Type Fonts. ;; ;;============================================= (defun c:halo () (setq FLTR '( (-4 . "<OR") (0 . "MULTILEADER") (-4 . "OR>") ) ) (Princ "\nSelect Multileader to HALO (CAN NOT be a true type font)...") (princ "\nPress ENTER after selecting entities to process them...") (setq SS (ssget FLTR)) (command "_.copy" ss "" "0,0" "0,0") (command "_.layer" "m" "halotext255" "c" "255" "" "lw" "2" "" "") (command "_.chprop" ss "" "_la" "halotext255" "p" "c" "bylayer" "") (if (setq ssetMLeaders (ssget "_:S" '((0 . "MULTILEADER")))) (progn (command "_EXPLODE" (ssname ssetMLeaders 0)) (setq ssetItems (ssget "_P")) (repeat (setq index (sslength ssetItems)) (setq assocItem (entget (ssname ssetItems (setq index (1- index))))) (if (/= (cdr (assoc 0 assocItem)) "MTEXT") (entdel (cdr (assoc -1 assocItem))) ) ) ) ) ;(command "_.draworder" ss "" "a" "p") ) I think that my code and your code, are 2 different languages. I am still noob when it comes to lisps, this code I have is a modified version of something similar... Could you show me how the code should look like? Is there a place I can go that will explain what 'setq' is and what is the reasoning for all the brackets?? I really want to learn how to write lisps... Quote
MSasu Posted July 2, 2012 Posted July 2, 2012 If I undestand your well, you were looking to parse the first selection set to retain the labels: (princ "\nPress ENTER after selecting entities to process them...") (if (setq SS (ssget '((0 . "MULTILEADER")))) (progn (command "_.copy" ss "" "0,0" "0,0") (command "_.layer" "m" "halotext255" "c" "255" "" "lw" "2" "" "") (command "_.chprop" ss "" "_la" "halotext255" "p" "c" "bylayer" "") (repeat (setq index1st (sslength ss)) (command "_EXPLODE" (setq tempItem (ssname ss (setq index1st (1- index1st))))) (setq ssetItems (ssget "_P")) (repeat (setq index2nd (sslength ssetItems)) (setq assocItem (entget (ssname ssetItems (setq index2nd (1- index2nd))))) (if (/= (cdr (assoc 0 assocItem)) "MTEXT") (entdel (cdr (assoc -1 assocItem))) ) ) ) ) ) Please check again my comment regarding selection filter. I think that my code and your code, are 2 different languages. Not at all, just plain AutoLISP. Quote
Locked and Loaded Posted July 2, 2012 Author Posted July 2, 2012 MSasu, you sir are a master! brilliant, works perfect. But one more question, sorry, how do I incorporate command 'HALO' into it? Quote
MSasu Posted July 3, 2012 Posted July 3, 2012 You just need to replace the code from your routine with the one modified by me; is also indicated to localize the variables and add a final PRINC statement to exit quietly (no nil on prompter). (defun c:halo( / associtem index1st index2nd ss ssetitems tempitem ) (princ "\nPress ENTER after selecting entities to process them...") (if (setq SS (ssget '((0 . "MULTILEADER")))) (progn (command "_.copy" ss "" "0,0" "0,0") (command "_.layer" "_m" "halotext255" "_c" "255" "" "_lw" "2" "" "") (command "_.chprop" ss "" "_la" "halotext255" "_p" "_c" "bylayer" "") (repeat (setq index1st (sslength ss)) (command "_EXPLODE" (setq tempItem (ssname ss (setq index1st (1- index1st))))) (setq ssetItems (ssget "_P")) (repeat (setq index2nd (sslength ssetItems)) (setq assocItem (entget (ssname ssetItems (setq index2nd (1- index2nd))))) (if (/= (cdr (assoc 0 assocItem)) "MTEXT") (entdel (cdr (assoc -1 assocItem))) ) ) ) ) ) (princ) ) Quote
Locked and Loaded Posted July 3, 2012 Author Posted July 3, 2012 That works very well! Thank you very much. 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.