bery35 Posted June 22, 2020 Posted June 22, 2020 I have a question. How do I select the nearest line when I click on any text. I have a code, but this code select single line. I want to select multiple text(or single text but I want to select the lines next to the text with the same content) then lisp select lines. I'm adding a video about how it works. (defun c:sl (/ ns sc ss n m p ls) (vl-load-com) (if (setq ns (ssget ":s" '((0 . "text"))) sc (ssadd) ss (ssget "x" '((0 . "line")))) (progn (repeat (setq n (sslength ss)) (setq n (1- n) m (ssname ss n) p (cdr (assoc 10 (entget (ssname ns 0)))) ls (cons (list m (distance p (vlax-curve-getclosestpointto (vlax-ename->vla-object m) p))) ls))) (sssetfirst nil (ssadd (caar (vl-sort ls '(lambda(a b) (< (cadr a) (cadr b))))) sc)) ) ) (princ) ) Quote
BIGAL Posted June 23, 2020 Posted June 23, 2020 (edited) The possible easier way is take text selection only and do repeat and search for a line within a crossing window it should return 1 line but you can check if multiple do again. Note Bricscad does polygon differently. ; pt is insert point of text (command "polygon" 10 pt "I" 10) (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast))))) (command "erase" (entlast) "") ; polygon not required (setq ssL (ssget "cp" co-ordsxy (list (cons 0 "Line")))) ` Edited June 23, 2020 by BIGAL Quote
bery35 Posted June 24, 2020 Author Posted June 24, 2020 On 6/23/2020 at 3:18 AM, BIGAL said: The possible easier way is take text selection only and do repeat and search for a line within a crossing window it should return 1 line but you can check if multiple do again. Note Bricscad does polygon differently. ; pt is insert point of text (command "polygon" 10 pt "I" 10) (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (entlast))))) (command "erase" (entlast) "") ; polygon not required (setq ssL (ssget "cp" co-ordsxy (list (cons 0 "Line")))) ` Bigal thank you for answer, but I don't know lisp code. I want to learn but dont understand now Quote
BIGAL Posted June 25, 2020 Posted June 25, 2020 (edited) Will find an example. maybe this (setq oldsnap (getvar 'osmode)) ; save current osnaps (setvar 'osmode 0) ; turn off osnaps (setq ent (entget (car (entsel "\nPick text for layer and value")))) ; select a text obect (setq lay (cdr (assoc 8 ent))) ; get object layer dxf code 8 (setq ss (ssget (list (cons 0 "*TEXT") (cons 8 lay)))) ; get objects that are text on layer (setq lst '()) ; set list to blank in case exists already (repeat (setq x (sslength ss)) ; do for every text in slection (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1))))) ; get each item in selection set (setq ins (vlax-get Obj 'insertionPoint)) ; get text insertion point (setq rad (* 1.5 (vlax-get Obj 'Height))) ; dummy value for a polygon to look for a nearby Circle (command "polygon" 20 ins "I" rad) ;Autocad Note briscad is different (setq obj2 (entlast)) ; save the name of the last object created (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget obj2)))) ; loops through the pline vertice points (command "erase" obj2 "") ; no longer required as needed points (setq ss2 (ssget "F" co-ord (list (cons 0 "Line")))) ; looks for lines that touch the polygon (if (/= ss2 nil) ; do your thing ) Edited June 26, 2020 by BIGAL Quote
bery35 Posted June 26, 2020 Author Posted June 26, 2020 (edited) I test code but there is an error; malformed list on input. I search and try something but I couldn't solve. How can I solve this error. Edited June 26, 2020 by bery35 Quote
dlanorh Posted June 26, 2020 Posted June 26, 2020 The incorrect line is the one starting : (setq co-ords (mapcar 'cdr .... I think you need another ")" on the end Quote
BIGAL Posted June 26, 2020 Posted June 26, 2020 (edited) It was sample code not a actual "use this" (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget obj2)))) is ok The If has no close bracket and the repeat is missing close bracket problem when cut something out of other code can miss something like the repeat close bracket which is way further down in original code. Updated code above. (if (/= ss2 nil) ; do your thing ) Bery35 I use Notepad++ it has bracket checking built in would have exposed the IF problem straight away, thats how I found the repeat problem. Edited June 26, 2020 by BIGAL 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.