morgos Posted March 10 Posted March 10 Does anyone knows if it is possible to use a variable instead of explicitly enter the code name?, I tried but got an error, Quote
Lee Mac Posted March 10 Posted March 10 It depends on the context - this tutorial may shed some light as to the reason for the error. 1 Quote
GLAVCVS Posted March 10 Posted March 10 4 hours ago, morgos said: Does anyone knows if it is possible to use a variable instead of explicitly enter the code name?, I tried but got an error, Your explanation is too short for some like me. If you continue to seek help, you should elaborate a bit more on the explanation. Quote
Steven P Posted March 10 Posted March 10 Can you post an example of what you are trying to do.... though I think Lee Mac has it covered - that's the common mistake Quote
morgos Posted March 10 Author Posted March 10 (edited) I am trying to trim contours inside buildings, my lisp iterates through the buildings in the dwg one by one and the user clicks on the contours inside the building to trim it, it works fine but I wanted to make it more general and the user enters the layer name which he\she wants the contours to be trimmed, here is my code so far: (defun C:MySel ( / sel1 n PArea Bname) (terpri) (princ "Enter Layer Name: ") (setq LayName (getstring)) (princ "\n") (princ LayName) (setq sel1 (ssget "_X" '((0 . "*POLYLINE")(8 . "Buildings"))));layer Name does not accept variables (repeat(setq n (sslength sel1)) (setq Bname (cdr(assoc -1 (entget (ssname sel1 (setq n (- n 1)))))));;;get the entity name (command "._z" "_en" Bname "") (princ "\n") (princ n) (command "._TR" Bname "" pause ) ) (princ) ) when I changed "Buildings" into LayName I got the error ( error: bad SSGET list), Lee Mac may got that covered, I will work on that tonight and let you know if any success, Edited March 10 by morgos Quote
Lee Mac Posted March 10 Posted March 10 17 minutes ago, morgos said: when I changed "Buildings" into LayName I got the error ( error: bad SSGET list), Lee Mac may got that covered, I will work on that tonight and let you know if any success, See if you can work it out from my tutorial and come back if you require further nudges Quote
morgos Posted March 10 Author Posted March 10 (edited) thanks Lee, your tutorial is awesome, it looks that you wrote it just for me , here is my final Lisp: (defun C:MySel ( / sel1 n LayName Bname) (terpri) (if (snvalid (setq LayName (getstring t "\nSpecify layer: "))) (setq sel1 (ssget "_X" (list '(0 . "POLYLINE")(cons 8 LayName)))) ) (princ "\nOK") (princ (sslength sel1)) (repeat(setq n (sslength sel1)) (setq Bname (cdr(assoc -1 (entget (ssname sel1 (setq n (- n 1)))))));;;get the entity name (command "._z" "_en" Bname "") (princ "\n") (princ n) (command "._TR" Bname "" pause ) ) (princ) ) in a different issue, when I ( the user) clicks on the contour, the contours trims fine once then the building no longer selected, so if there are more than one contour inside the building the rest of them cannot be trimmed unless you run the lisp again until all the contours are trimmed, any idea how to keep the building selected until the user hits enter? Edited March 10 by morgos Quote
Lee Mac Posted March 10 Posted March 10 You're most welcome To continue the TRIM command, you can use something like: (command "_.trim" bname "") (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\") ) Note that the pause symbol evaluates to a backslash - I prefer to use the literal backslash as pause is not protected and has the potential to be redefined. Quote
BIGAL Posted March 10 Posted March 10 I normally use this for get layer name. (setq layname (cdr (assoc 8 (entget (car (entsel "\nPlease select object for layer ")))))) I would look at using "fence" in the trim can select multiple crossing lines. Quote
Lee Mac Posted March 11 Posted March 11 10 hours ago, morgos said: (setq Bname (cdr(assoc -1 (entget (ssname sel1 (setq n (- n 1)))))));;;get the entity name Note that the above is the same as: (setq bname (ssname sel1 (setq n (- n 1)))) Quote
morgos Posted March 11 Author Posted March 11 12 hours ago, Lee Mac said: You're most welcome To continue the TRIM command, you can use something like: (command "_.trim" bname "") (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\") ) Note that the pause symbol evaluates to a backslash - I prefer to use the literal backslash as pause is not protected and has the potential to be redefined. Lee: this is working exactly as mine, the trim command stays active, but my issue is the building ( the cutting edge ) is not selected any more after one click Quote
morgos Posted March 11 Author Posted March 11 hi Lee, sorry, discard my last comment, my bad, i loaded the wrong Lisp file, your last snippet worked exactly the way i wanted, problem solved, thanks for all your help Quote
morgos Posted March 11 Author Posted March 11 Bigal: I normally use this for get layer name. (setq layname (cdr (assoc 8 (entget (car (entsel "\nPlease select object for layer ")))))) i like that, picking from the screen instead of typing the layer name, thanks. Quote
morgos Posted March 11 Author Posted March 11 5 hours ago, Lee Mac said: Note that the above is the same as: (setq bname (ssname sel1 (setq n (- n 1)))) oh, nice ... Quote
morgos Posted March 11 Author Posted March 11 now it is working exactly the way i wanted, thanks everybody, you were wonderful, here is my final Lisp if anyone find it useful. please note that i am just a hobbyist, my code is fast and dirty, no error trapping: (defun C:MySel ( / sel1 n LayName Bname) (terpri) (setq LayName (cdr (assoc 8 (entget (car (entsel "\nPlease select object for layer ")))))) (setq sel1 (ssget "_X" (list '(0 . "POLYLINE")(cons 8 LayName)))) (princ "\nOK") (princ (sslength sel1)) (repeat(setq n (sslength sel1)) (setq Bname (ssname sel1 (setq n (- n 1)))) (command "._z" "_en" Bname "") (princ "\n") (princ n) (command "._TR" Bname "") (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\") ) ) Quote
ronjonp Posted March 11 Posted March 11 1 hour ago, morgos said: now it is working exactly the way i wanted, thanks everybody, you were wonderful, here is my final Lisp if anyone find it useful. please note that i am just a hobbyist, my code is fast and dirty, no error trapping: (defun C:MySel ( / sel1 n LayName Bname) (terpri) (setq LayName (cdr (assoc 8 (entget (car (entsel "\nPlease select object for layer ")))))) (setq sel1 (ssget "_X" (list '(0 . "POLYLINE")(cons 8 LayName)))) (princ "\nOK") (princ (sslength sel1)) (repeat(setq n (sslength sel1)) (setq Bname (ssname sel1 (setq n (- n 1)))) (command "._z" "_en" Bname "") (princ "\n") (princ n) (command "._TR" Bname "") (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\") ) ) You have a missing parenthesis in that snippet. Here's some simple refactoring for better error handling: (defun c:mysel (/ sel1 n layname bname) ;; Check that the selection is valid before using ENTGET (if (and (setq layname (car (entsel "\nPlease select object for layer "))) (setq layname (cdr (assoc 8 (entget layname)))) (setq sel1 (ssget "_X" (list '(0 . "POLYLINE") (cons 8 layname)))) ) (repeat (setq n (sslength sel1)) (setq bname (ssname sel1 (setq n (- n 1)))) (command "._z" "_en" bname "") (princ "\n") (princ n) (command "._TR" bname "") (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\")) ) ) ;; Exit quietly (princ) ) Quote
morgos Posted March 11 Author Posted March 11 6 hours ago, ronjonp said: You have a missing parenthesis in that snippet. Here's some simple refactoring for better error handling: (defun c:mysel (/ sel1 n layname bname) ;; Check that the selection is valid before using ENTGET (if (and (setq layname (car (entsel "\nPlease select object for layer "))) (setq layname (cdr (assoc 8 (entget layname)))) (setq sel1 (ssget "_X" (list '(0 . "POLYLINE") (cons 8 layname)))) ) (repeat (setq n (sslength sel1)) (setq bname (ssname sel1 (setq n (- n 1)))) (command "._z" "_en" bname "") (princ "\n") (princ n) (command "._TR" bname "") (while (= 1 (logand 1 (getvar 'cmdactive))) (command "\\")) ) ) ;; Exit quietly (princ) ) Thanks 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.