Offset Text to Line

Offset Text to Line

Anonymous
Not applicable
3,315 Views
5 Replies
Message 1 of 6

Offset Text to Line

Anonymous
Not applicable

I need a function (lsp or scr) that aligns the text with a line with certain offset horisiontelly.

Here all red texts should be aligned to the red line and green ones to green line and so on...with offset 0.1.

 

The texts are exicting so Copy/Array/Divide/Measure/TEXTALIGN or Express Tools etc would not work the way I want!

 

0 Likes
Accepted solutions (1)
3,316 Views
5 Replies
Replies (5)
Message 2 of 6

Sea-Haven
Mentor
Mentor

It should be pretty easy just get text insertion pt look for same color line, then getclosestpointto check if 0.1 if not move text. Just need some time.

Message 3 of 6

Sea-Haven
Mentor
Mentor
Accepted solution

Try this, no error checking just select all the text . Note you have plines not lines, but will work with either.

 

; https://forums.autodesk.com/t5/forums/replypage/board-id/130/message-id/397664

; adjust text to match a line by color
; By AlanH March 2020 info@alanh.com.au

; replace this below for BRISCAD (command "polygon" 20 pt (polar pt 0.0 rad)) ; Briscad

;;-------------------=={ Parse Numbers }==--------------------;;`
;;                                                            ;;
;;  Parses a list of numerical values from a supplied string. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s - String to process                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;

(defun LM:ParseNumbers ( s )
  (
    (lambda ( l )
      (read
        (strcat "("
          (vl-list->string
            (mapcar
              (function
                (lambda ( a b c )
                  (if
                    (or
                      (< 47 b 58)
                      (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                      (and (= 46 b) (< 47 a 58) (< 47 c 58))
                    )
                    b 32
                  )
                )
              )
              (cons nil l) l (append (cdr l) (list nil))
            )
          )
          ")"
        )
      )
    )
    (vl-string->list s)
  )
)

(defun c:toff ( / offd oldsnap ss ss2 obj ins rad col colnum co-ord obj obj2 obj3 dist ang pt)
(setq offd 0.1) ; change to (setq offd (getreal "\nEnter offset"))
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq ss (ssget (list (cons 0 "*TEXT"))))

(repeat (setq x (sslength ss))
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
  (setq ins (vlax-get Obj 'insertionPoint))
  (setq rad (* 1.5 (vlax-get Obj 'Height)))
  (setq col (vlax-get Obj 'Plotstylename))
  (setq colnum (car (LM:ParseNumbers col)))
  
  (command "polygon" 20 ins "I" rad) ;Autocad
  (setq obj2 (entlast))
  (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget obj2))))
  (command "erase" obj2 "")
  
  (setq ss2 (ssget "F" co-ord (list (cons 0 "*LINE")(cons 62 colnum))))
  
  (setq obj3 (vlax-ename->vla-object(ssname ss2 0)))
  (setq pt (vlax-curve-getclosestpointto obj3 ins))
  
  (setq dist (distance pt ins))
  (setq ang (angle pt ins))
  (setq pt (polar pt ang offd))
	
  (vlax-put Obj 'insertionPoint pt)
)
(setvar 'osmode oldsnap)
(princ)
)

 

0 Likes
Message 4 of 6

Anonymous
Not applicable

Thanks a lot!

It works well! A few problems but it works!

0 Likes
Message 5 of 6

ВeekeeCZ
Consultant
Consultant

HERE is shown trick how to match y coord quickly. Posting just because its good to know in case you don't.

Message 6 of 6

Anonymous
Not applicable

Hi!

I would like to be able to pick a line to align to and the offset.

Input from the user will look like this:

 

Select the line/polyline to offset to:

Specify offset distance:

 

Thanks a lot!!!

0 Likes