Jump to content
ktbjx

Select text below a LINE

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

Share this post


Link to post
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)

Share this post


Link to post
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 >.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
o you mean which are the ones i need to select?

Can not you see the red arrow?

Check the selection ".30 / 17.13"

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites
Yes! exactly what i need, i love it! at least selecting those text will be easier!

thank you so much!

 

You're welcome! :)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×