Jump to content

AutoLISP functio to move selected text to them nearest point or vertex where the text is not intersected by a single line or


Recommended Posts

Posted

It's a bit complicated for me to explain this.
In this case, numbers should be selected and moved to the nearest point or vertex, and when moved, the text should not intersect any lines or polygons. Moving isn't that much of a problem, but the latter is.

My idea is to create a rectangle around the text using the TCIRCLE function and then move the rectangle along the edge of the circle (where the center of the circle is the moving point) of some radius until it is not intersected by lines, if there is no such place then the radius increases by some value, it doesn't matter which one.

Anyway, maybe I'm asking to much let me know guys if you have a suggestion. 

THANKS

 

Screenshot 2024-07-16 at 17.43.47.png

Posted

We have a similar issue. We have to insert labels in arbitrary spots, then adjust them so they don't overlap certain features. It gets complicated in a hurry.

 

Have you tried using a background mask? Is that even an option? If not, there may be a coding solution.

Posted

Moving text to be readable has been a challenge since CAD was introduced, on Civil plans with lots of points it's a nightmare. 

 

Just a comment Re image above yes a polygon surrounding the text then test does it touch if so move towards geometric centre a small amount till SSget "CP" pts no longer works. Need polygon not a Circle say 10 sides.

 

(setq ptc (osnap (vlax-curve-getStartPoint obj) "gcen"))

 

Need a true dwg to test on note where 2 polygons touch and have a common point ? No idea as no test dwg.

Posted

This is very rough so give it a try. Very limited testing.

 

; https://www.cadtutor.net/forum/topic/88192-autolisp-functio-to-move-selected-text-to-them-nearest-point-or-vertex-where-the-text-is-not-intersected-by-a-single-line-or/
; primitive move text inside a polygon
; By AlanH July 2024

(defun c:movtxt ( / poly10 ss ss2 lst pt ptt ang ang2 plent co-ord obj ptc inc dist)

(defun poly10 ( / )
 (setq lst '())
 (setq ang2 ang)
 (repeat 11
  (setq pt (polar ptt ang2 dist))
  (setq lst (cons pt lst))
  (setq ang2 (+ ang2 inc))
 )
 (setq ss2 (ssget "F" lst'((0 . "LWPolyLINE"))))
 (if (= ss2 nil)
  (princ (setq found "yes"))
  (setq ptt (polar ptt ang (/ dist 10.)))
)
(princ)
)

(setq plent (car (entsel "\nSelect a pline object ")))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent))))
(setq co-ord (cons (last co-ord) co-ord))
(setq obj (vlax-ename->vla-object plent))
(setq ptc (osnap (vlax-curve-getStartPoint obj) "gcen"))
(setq ss (ssget "CP" co-ord '((0 . "TEXT"))))

(if (= ss nil)
(progn (alert "There are no touching text's \nWill now exit ")(exit))
)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)

(setq inc (/ (* 2 pi) 10))

(repeat (setq x (sslength ss))
  (setq obj2 (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
  (vla-GetBoundingBox obj2 'minpoint 'maxpoint)
  (setq pointmin (vlax-safearray->list minpoint))
  (setq pointmax (vlax-safearray->list maxpoint))
  (setq mp (mapcar '* (mapcar '+ pointmin pointmax) '(0.5 0.5)))
  (setq ptt mp)
  (setq ang (angle mp ptc))
  (setq dist (distance mp pointmax))
  (setq found "no")
  (while (= found "no")
   (poly10)
  )
  (Vla-move obj2 mp ptt)
)

(princ)
)

(c:movtxt)

 

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