brams Posted June 8, 2012 Posted June 8, 2012 I use 2 methods: 1. (setq ss1 (ssget '((0 . "point")))) and (setq ss2 (ssget '((0 . "TEXT")))) to create 2 separate selection sets 2. (setq ss1 (ssget '((0 . "point,text")))) , and then i use repeat... to make 2 lists, 1 for texts and one for points. Is it possible to make 2 selection sets only by using 1 time ssget function? My question seems stupid...sorry... Thanks! Quote
pBe Posted June 8, 2012 Posted June 8, 2012 AFAIK, you're second option is the only way you can do such a task. at any rate. it would be better to process the objects while inside the repeat loop using IF/COND to eliminate the need to create another selection set. Quote
BlackBox Posted June 8, 2012 Posted June 8, 2012 (edited) [font=monospace](defun _GetSelPoints (/ *error*) (defun *error* (msg) (and oldNomutt (setvar 'nomutt oldNomutt)) (cond ((not msg)) ; Normal exit ((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit) ((princ (strcat "\n** Error: " msg " ** ")))) ; Fatal error, display it (if result result (princ))) ((lambda (oldNomutt / startPoint endPoint result) (if (and (not (prompt "\nSelect objects: ")) (setvar 'nomutt 1) (not (initget 1024)) (setq startPoint (getpoint)) (not (initget 1056)) (setq endPoint (getcorner startPoint))) (progn (setq result (list startPoint endPoint)) (*error* nil)) (*error* "Nothing selected"))) (getvar 'nomutt))) [/font] Linky: http://www.theswamp.org/index.php?topic=41872.msg469927#msg469927 Edited June 8, 2012 by BlackBox Quote
brams Posted June 8, 2012 Author Posted June 8, 2012 A little help, please... for a new autolisp user Seems to be what i'm searching for. Please, an example how to use your function together with ssget... to make 2 selection sets of points and texts, selecting objects only one time - i mean, a single "rectangle". <li style="">([url="http://www.theswamp.org/%7Ejohn/avlisp/#defun"][color=#4D4DFF][b]defun[/b][/color][/url] _GetSelPoints ([color=#008000]/[/color] [color=#4D4DFF][i]*error*[/i][/color]) <li style=""> <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#defun"][color=#4D4DFF][b]defun[/b][/color][/url] [color=#4D4DFF][i]*error*[/i][/color] (msg) <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#and"][color=#4D4DFF][b]and[/b][/color][/url] oldNomutt ([url="http://www.theswamp.org/%7Ejohn/avlisp/#setvar"][color=#4D4DFF][b]setvar[/b][/color][/url] 'nomutt oldNomutt)) <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#cond"][color=#4D4DFF][b]cond[/b][/color][/url] (([url="http://www.theswamp.org/%7Ejohn/avlisp/#not"][color=#4D4DFF][b]not[/b][/color][/url] msg)) [color=#666666][i]; Normal exit[/i][/color] <li style=""> (([url="http://www.theswamp.org/%7Ejohn/avlisp/#member"][color=#4D4DFF][b]member[/b][/color][/url] msg '([color=#FF0000]"Function cancelled"[/color] [color=#FF0000]"quit / exit abort"[/color]))) [color=#666666][i]; <esc> or (quit)[/i][/color] <li style=""> (([url="http://www.theswamp.org/%7Ejohn/avlisp/#princ"][color=#4D4DFF][b]princ[/b][/color][/url] ([url="http://www.theswamp.org/%7Ejohn/avlisp/#strcat"][color=#4D4DFF][b]strcat[/b][/color][/url] [color=#FF0000]"[color=#000099][b]\n[/b][/color]** Error: "[/color] msg [color=#FF0000]" ** "[/color])))) [color=#666666][i]; Fatal error, display it[/i][/color] <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#if"][color=#4D4DFF][b]if[/b][/color][/url] result result ([url="http://www.theswamp.org/%7Ejohn/avlisp/#princ"][color=#4D4DFF][b]princ[/b][/color][/url]))) <li style=""> <li style=""> (([url="http://www.theswamp.org/%7Ejohn/avlisp/#lambda"][color=#4D4DFF][b]lambda[/b][/color][/url] (oldNomutt [color=#008000]/[/color] startPoint endPoint result) <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#if"][color=#4D4DFF][b]if[/b][/color][/url] ([url="http://www.theswamp.org/%7Ejohn/avlisp/#and"][color=#4D4DFF][b]and[/b][/color][/url] ([url="http://www.theswamp.org/%7Ejohn/avlisp/#not"][color=#4D4DFF][b]not[/b][/color][/url] ([url="http://www.theswamp.org/%7Ejohn/avlisp/#prompt"][color=#4D4DFF][b]prompt[/b][/color][/url] [color=#FF0000]"[color=#000099][b]\n[/b][/color]Select objects: "[/color])) <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#setvar"][color=#4D4DFF][b]setvar[/b][/color][/url] 'nomutt [color=#0000dd]1[/color]) <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#not"][color=#4D4DFF][b]not[/b][/color][/url] ([url="http://www.theswamp.org/%7Ejohn/avlisp/#initget"][color=#4D4DFF][b]initget[/b][/color][/url] [color=#0000dd]1024[/color])) <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#setq"][color=#4D4DFF][b]setq[/b][/color][/url] startPoint ([url="http://www.theswamp.org/%7Ejohn/avlisp/#getpoint"][color=#4D4DFF][b]getpoint[/b][/color][/url])) <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#not"][color=#4D4DFF][b]not[/b][/color][/url] ([url="http://www.theswamp.org/%7Ejohn/avlisp/#initget"][color=#4D4DFF][b]initget[/b][/color][/url] [color=#0000dd]1056[/color])) <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#setq"][color=#4D4DFF][b]setq[/b][/color][/url] endPoint ([url="http://www.theswamp.org/%7Ejohn/avlisp/#getcorner"][color=#4D4DFF][b]getcorner[/b][/color][/url] startPoint))) <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#progn"][color=#4D4DFF][b]progn[/b][/color][/url] ([url="http://www.theswamp.org/%7Ejohn/avlisp/#setq"][color=#4D4DFF][b]setq[/b][/color][/url] result ([url="http://www.theswamp.org/%7Ejohn/avlisp/#list"][color=#4D4DFF][b]list[/b][/color][/url] startPoint endPoint)) ([color=#4D4DFF][i]*error*[/i][/color] [color=#4D4DFF][i]nil[/i][/color])) <li style=""> ([color=#4D4DFF][i]*error*[/i][/color] [color=#FF0000]"Nothing selected"[/color]))) <li style=""> ([url="http://www.theswamp.org/%7Ejohn/avlisp/#getvar"][color=#4D4DFF][b]getvar[/b][/color][/url] 'nomutt))) Quote
pBe Posted June 8, 2012 Posted June 8, 2012 FWIW (defun c:sepsel () (setq textsel (ssadd) PointSel (ssadd) ss (ssget '((0 . "POINT,TEXT")))) (while (setq e (ssname ss 0)) (if (eq (cdr (assoc 0 (entget e))) "POINT") (ssadd e PointSel)(ssadd e textsel)) (ssdel e ss))) Quote
MSasu Posted June 8, 2012 Posted June 8, 2012 @brams: What editor are you using? Seems that you pasted some control tags along AutoLISP code. Or did you tried to number the lines?!? Quote
brams Posted June 8, 2012 Author Posted June 8, 2012 I copied from here http://www.theswamp.org/index.php?to...9927#msg469927 Quote
pBe Posted June 8, 2012 Posted June 8, 2012 Nice, Pbe! You are welcome, IMO, intead of separating the slection into two, might as well process the entities inside the while/repeat loop. What is the code all about anyway? can you share it with us, maybe there's a more efficient way of accomplishing your goal. Quote
brams Posted June 8, 2012 Author Posted June 8, 2012 I can share my "masterpiece" , no problem... This code have to move points and texts at the correct elevation. I select points and texts - texts that have the same x and y with point ... should be pairs .If the text is 209.324, then i will move the point at this elevation, and also i will move the point - that has the same x value and y value-at this elevation. Is about land surveyor "masterpiece" - wrong elevation for points. My code seems to work ok if i select points and texts that are pairs (same x and y), but when i select texts and points that are not pairs, some errors...i don't know why - please help if possible. Sorry for the code, looks bad - still in work.... (defun c:pz (/ ldata layer punct) (princ "\nSELECTEAZA PUNCTELE SI TEXTELE") (setq ss (ssget '((0 . "POINT,TEXT")))) (setq i 0) (repeat (sslength ss) (setq ename (ssname ss i)) (setq data (entget ename)) (setq entName (cdr (assoc -1 data))) (setq Nume (cdr (assoc 0 data))) (setq ldata (cons data ldata)) (setq i (1+ i)) ) ;_ end of repeat (setq ltest ldata) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq i 0) (setq listat nil) (repeat (length ldata) (setq entName (cdr (assoc -1 (nth i ldata)))) (setq Nume (cdr (assoc 0 (nth i ldata)))) (if (= Nume "TEXT") (progn (setq pct (cdr (assoc 10 (nth i ldata)))) (setq z (atof (cdr (assoc 1 (nth i ldata))))) (setq ztext (caddr pct)) (setq listat (cons (list pct z ztext entName) listat)) ) ;_ end of progn ) ;_ end of if (setq i (1+ i)) ) ;_ end of repeat ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq i 0) (setq listap nil) (repeat (length ldata) (setq entName (cdr (assoc -1 (nth i ldata)))) (setq Nume (cdr (assoc 0 (nth i ldata)))) (if (= Nume "POINT") (progn (setq punct (cdr (assoc 10 (nth i ldata)))) (setq layer (cdr (assoc 8 (nth i ldata)))) (setq culoare (cdr (assoc 62 (nth i ldata)))) (setq listap (cons (list punct layer culoare entName) listap)) ) ;_ end of progn ) ;_ end of if (setq i (1+ i)) ) ;_ end of repeat ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq listam nil) (setq listaep nil) (setq listaet nil) (setq i 0) (repeat (length listap) (setq text (nth i listat)) (foreach punct listap (if (and (= (car (car text)) (car (car punct))) (= (cadr (car text)) (cadr (car punct))) ) ;_ end of and (setq p (list (list (car (car punct)) (cadr (car punct)) (cadr text) ) ;_ end of list (setq la (cadr punct)) (setq cul (caddr punct)) (setq entitatep (cadddr punct)) (setq entitatet (cadddr text)) (setq pt (car text)) ) ;_ end of list ) ;_ end of setq ) ;_ end of if ) ;_ end of foreach (setq listam (cons p listam)) (setq listaep (cons entitatep listaep)) (setq listaet (cons entitatet listaet)) (setq i (1+ i)) ) ;_ end of repeat ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq i 0) (repeat (length listam) (entmake (list (cons 0 "POINT") (cons 8 (cadr (nth i listam))) (if (/= (caddr (nth i listam)) nil) (cons 62 (caddr (nth i listam))) (cons 62 256) ) ;_ end of if (cons 10 (car (nth i listam))) ) ;_ end of list ) ;_ end of entmake ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (command "_.move" (cadddr (cdr (nth i listam))) "" (setq pti (cadddr (cdr (cdr (nth i listam))))) (setq ptf (car (nth i listam))) (list (car (car (nth i listat))) (cadr (car (nth i listat))) (cadr (nth i listat)) ) ;_ end of list ) ;_ end of command (setq i (1+ i)) ) ;_ end of repeat ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq sse (ssadd)) (foreach ent listaep (ssadd ent sse)) (command "erase" sse "") (princ) ) ;_ end of defun Quote
brams Posted June 8, 2012 Author Posted June 8, 2012 So, now, i suppose Pbe won't ask me again to show my code . You like it, Pbe? The best code on the site! Quote
pBe Posted June 8, 2012 Posted June 8, 2012 So, now, i suppose Pbe won't ask me again to show my code Not at all brams You like it, Pbe? The best code on the site! The idea is ok, just needs fine tuning. Look into this _GetClosestTextTo sub-function: Renderman HTH Quote
BlackBox Posted June 8, 2012 Posted June 8, 2012 A little help, please... for a new autolisp user Seems to be what i'm searching for. Please, an example how to use your function together with ssget... to make 2 selection sets of points and texts, selecting objects only one time - i mean, a single "rectangle". @brams: What editor are you using? Seems that you pasted some control tags along AutoLISP code. Or did you tried to number the lines?!? I've copied the code that I previously linked here. FWIW (defun c:sepsel () (setq textsel (ssadd) PointSel (ssadd) ss (ssget '((0 . "POINT,TEXT")))) (while (setq e (ssname ss 0)) (if (eq (cdr (assoc 0 (entget e))) "POINT") (ssadd e PointSel)(ssadd e textsel)) (ssdel e ss))) Perhaps localized variables would be useful? Otherwise running the code multiple times would provide some interesting results. Look into this _GetClosestTextTo sub-function: Renderman Cheers, Pbe Quote
Stefan BMR Posted June 9, 2012 Posted June 9, 2012 Brams, this is what you need? (defun C:PZ ( / *error* ss i en el p p1 echo) (setq echo (getvar 'cmdecho)) (setvar 'cmdecho 0) (command "UNDO" "BE") (defun *error* (msg) (if msg (princ msg)) (command "UNDO" "E") (setvar 'cmdecho echo) (princ) ) (princ "\nSELECTEAZA PUNCTELE SI TEXTELE") (if (setq ss (ssget '((0 . "TEXT,POINT") (8 . "Puncte,Cote")))) ; <- de modificat numele layerelor (repeat (setq i (sslength ss)) (setq en (ssname ss (setq i (1- i)))) (if (setq z (cdr (assoc 1 (setq el (entget en))))) (progn (setq p (assoc 10 el) p1 (list 10 (cadr p) (caddr p) (atof z)) ) (entmake (list '(0 . "POINT") '(8 . "Puncte") p1)) (entmod (subst p1 p el)) ) (entdel en) ) ) ) (*error* nil) (princ) ) 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.