Jump to content

Recommended Posts

Posted

 

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)
)

 

Posted (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")))) `

 

image.png.0f5123c0fd2c3ca162021587a26b8688.png

 

 

Edited by BIGAL
Posted
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")))) `

 

image.png.0f5123c0fd2c3ca162021587a26b8688.png

 

 

 

Bigal thank you for answer, but I don't know lisp code. I want to learn but dont understand now

Posted (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 by BIGAL
Posted (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.

2020-06-26_10-46-41.png

Edited by bery35
Posted

The incorrect line is the one starting :

 

(setq co-ords (mapcar 'cdr ....

I think you need another ")" on the end

Posted (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 by BIGAL

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...