Jump to content

Select text below a LINE


ktbjx

Recommended Posts

is it possible on autolisp to select all text below the line? we always deal with data like these, and I'm just thinking maybe i could ask your help if it is possible to select all text below a line...

BTW, the dxf/dwg files are always in clockwise, and due north(270)

and all lines starts from north going down, so that all angles will never be GREATER THAN 270 OR LESSER THAN 90

i attached a sample dxf and that is just a tiny portion, does anyone know a way?

new block.dxf

Link to comment
Share on other sites

Try this

 

; look for text below a line
; by alan H Aug 2018
(defun c:test ( / ss sstxt endpt stpt pt pt2)
(setq ss (ssget (list (cons 0 "Line"))))
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq stpt   (vlax-curve-getstartPoint Obj)
   endpt  (vlax-curve-getEndPoint Obj)
ang (angle stpt endpt)
dist (/ (distance stpt endpt) 2.0)
)
(setq pt (polar stpt ang dist))
(setq pt (polar pt(+ ang (/ pi 2.0)) 0.001))
(setq pt2 (polar pt (+ ang (/ pi 2.0))0.5))
(setq sstxt (ssget "F" (list pt pt2) ))
(if (/= sstxt nil)
(progn
(setq obj (vlax-ename->vla-object(ssname sstxt 0)))
(if (= (vla-get-objectname obj)"AcDbText")
(alert (vla-get-textstring obj))
(alert (vla-get-objectname obj))
)
)
)
)
)
(c:test)

Link to comment
Share on other sites

Try this

 

; look for text below a line
; by alan H Aug 2018
(defun c:test ( / ss sstxt endpt stpt pt pt2)
(setq ss (ssget (list (cons 0 "Line"))))
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq stpt   (vlax-curve-getstartPoint Obj)
   endpt  (vlax-curve-getEndPoint Obj)
ang (angle stpt endpt)
dist (/ (distance stpt endpt) 2.0)
)
(setq pt (polar stpt ang dist))
(setq pt (polar pt(+ ang (/ pi 2.0)) 0.001))
(setq pt2 (polar pt (+ ang (/ pi 2.0))0.5))
(setq sstxt (ssget "F" (list pt pt2) ))
(if (/= sstxt nil)
(progn
(setq obj (vlax-ename->vla-object(ssname sstxt 0)))
(if (= (vla-get-objectname obj)"AcDbText")
(alert (vla-get-textstring obj))
(alert (vla-get-objectname obj))
)
)
)
)
)
(c:test)

 

 

BIGAL thank you! this is the one, though i only want to select them not prompt me the value.

i need to select them so i can do stuffs with them... sorry, that sounded weird >.

Link to comment
Share on other sites

In what form should the final result be?

nothing sir, i just want to select them so i could change, move rotate or anything

Link to comment
Share on other sites

Check this out:

o you mean which are the ones i need to select?

its the texts below

2vnlvva.jpg

 

no matter the orientation i need to select only the text below the lines

Link to comment
Share on other sites

Try this .. it's not perfect, but neither is the data.

(defun c:foo (/ _dxf _x c l r s tx x)
 ;; RJP » 2018-08-07
 ;; Finds text equal to a distance found to the closest line
 (defun _x (s) (cond ((= 'pickset (type s)) (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))))
 (defun _dxf (c e) (cdr (assoc c (entget e))))
 (setq r (ssadd))
 (cond
   ((and (setq s (_x (ssget "_X" '((0 . "line") (8 . "850L 802 AR CuAu")))))
  (setq tx (_x (ssget "_X" '((0 . "text") (8 . "850L 802 AR CuAu")))))
  (setq tx (mapcar '(lambda (x) (list (_dxf 10 x) x)) tx))
    )
    (foreach l	tx
      (setq c (mapcar '(lambda (x) (distance (car l) (vlax-curve-getclosestpointto x (car l)))) s))
      ;; If there is a line within 0.2 and 0.5 distance
      (if (equal (car (vl-sort c '(lambda (a b) (< a b)))) 0.35 0.15)
 ;; Add the text to the selection
 (ssadd (cadr l) r)
      )
    )
    (sssetfirst nil r)
   )
 )
 (princ)
)

2018-08-07_13-14-48.jpg

Link to comment
Share on other sites

Like all the posts here ktbjx you did not say what you wanted to actually do with what was picked hence I just displayed the value its was up to you to do something with it. like Ronjonp I had some problems with crossing data.

Link to comment
Share on other sites

Try this .. it's not perfect, but neither is the data.

(defun c:foo (/ _dxf _x c l r s tx x)
 ;; RJP » 2018-08-07
 ;; Finds text equal to a distance found to the closest line
 (defun _x (s) (cond ((= 'pickset (type s)) (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))))
 (defun _dxf (c e) (cdr (assoc c (entget e))))
 (setq r (ssadd))
 (cond
   ((and (setq s (_x (ssget "_X" '((0 . "line") (8 . "850L 802 AR CuAu")))))
  (setq tx (_x (ssget "_X" '((0 . "text") (8 . "850L 802 AR CuAu")))))
  (setq tx (mapcar '(lambda (x) (list (_dxf 10 x) x)) tx))
    )
    (foreach l	tx
      (setq c (mapcar '(lambda (x) (distance (car l) (vlax-curve-getclosestpointto x (car l)))) s))
      ;; If there is a line within 0.2 and 0.5 distance
      (if (equal (car (vl-sort c '(lambda (a b) (< a b)))) 0.35 0.15)
 ;; Add the text to the selection
 (ssadd (cadr l) r)
      )
    )
    (sssetfirst nil r)
   )
 )
 (princ)
)

 

 

Yes! exactly what i need, i love it! at least selecting those text will be easier!

thank you so much!

Link to comment
Share on other sites

Just another thought, but why don't you use an attributed block for this? It would make your drawings quite a bit more consistent.

Link to comment
Share on other sites

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