Jump to content

Recommended Posts

Posted

error:

Quote

(setq mp (mapcar '(lambda (a b) (/ (+ a b) 2.0)) minp maxp))

image.png.edb1c829b5e14550ba3daa543977bb98.png

 

Posted

I see Felix...

Error is actually little before :

In this line :

(mapcar 'set '(minp maxp) (list minp maxp))

It should be :

(mapcar 'set '(minp maxp) (mapcar 'safearray-value (list minp maxp)))

 

Change both mistakes - the error was at 2 places...

I'll update my code...

Posted

Excellent, it works very well but to be perfect it needs offset.

Posted

Felix, I've changed posted code, but like I said : If I was to use this routine, I'd rather tap ENTER and have offset = 0, then to allow CAD to decide what side to offset texts randomly - linear entities can be drawn in both directions - there are no rules here (logic) to be applied to texts last movement direction - some will be translated thoward linear objects and some will be translated away from them...

Posted

You are making a MOVE and not OFFSET from LINE.

See how the final position of the texts should be.

 

image.thumb.png.5e474b90b95c40acdc626ecb60d8f784.png

Posted
14 minutes ago, FELIXJM said:

You are making a MOVE and not OFFSET from LINE.

See how the final position of the texts should be.

 

image.thumb.png.5e474b90b95c40acdc626ecb60d8f784.png

 

 

OK Felix, I've updated again...

Check it now...

Posted

Updated once more... There are rabbit holes here...

I think that now it's covered all like I wanted...

But still offset option is not good approach if routine is to be used IMHO...

Posted

Now with OFFSET > 0 it was equal to C:FOO of RONJONP.

 

image.thumb.png.ce5eef2f40217eae739b1b657b8d9892.png

Posted

It is necessary to analyze the direction (clockwise or counterclockwise) of the LINE or POLYLINE to know if the TEXT or MTEXT is above or below and also the height of the TEXT or MTEXT. That way it will be perfect.

Posted
3 minutes ago, FELIXJM said:

Now with OFFSET > 0 it was equal to C:FOO of RONJONP.

 

image.thumb.png.ce5eef2f40217eae739b1b657b8d9892.png

 

 

Check it again, Felix...

There are rabbit holes here...

I think that it's not exactly like Ron's version...

My uses mp (boundingbox center) instead of p = (cdr (assoc 10 (entget txtent)))

and at the end it uses (angle (car l) mp) which is different than angle a in a way that it should move texts from lines toward initial mp points, which means toward starting positions of texts... It shouldn't be like middle picture - it should be like final right picture...

Posted

OK, I tested it again with more calm and it worked PERFECT, EXCELLENT, it was VERY GOOD, CONGRATULATIONS.
Tested with LINE and TEXTs worked.
Tested with LINE and MTEXTs it worked.
Tested with PLINE and TEXTs worked.
Tested with PLINE and MTEXTs worked.

Includes a line for lists to always start empty:

Quote

(SETQ TEXT '() LINES '())

 

Fix the line that asks for OFFSET as a comment and includes a snippet so that OFFSET is automatic using the height of the text:

Quote

(SETQ LX (ENTGET X))
(COND
((= (CDR (ASSOC 0 LX)) "TEXT") (SETQ D (CDR (ASSOC 40 LX))) (SETQ D (* D 0.9)) )
((= (CDR (ASSOC 0 LX)) "MTEXT") (SETQ BB (ACET-GEOM-TEXTBOX LX 0.0001)) (SETQ D (DISTANCE (CADR BB) (CADR (CDR BB)))) (SETQ D ( * D 0.7)) )
(T (SETQ D 0))
)

Here is the modified code:

Quote

(defun c:maketextreadable ( / _aap l lines p2 ss text dxf50 xx minp maxp mp pp d )

  (vl-load-com)

  ;; RJP » 2021-10-06
  ;; MR » 2021-01-11

  (defun _aap (ename pt / param)
    (if (and (not (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getendparam (list ename))))
             (setq param (vlax-curve-getparamatpoint ename pt))
        )
      (angle '(0 0) (vlax-curve-getfirstderiv ename param))
    )
  )

  (if (= 8 (logand 8 (getvar 'undoctl)))
    (vl-cmdf "_.UNDO" "_E")
  )
  (vl-cmdf "_.UNDO" "_M")
  (if (setq ss (ssget '((0 . "*polyline,Line,*Text"))))
    (progn
      ;
      ;;; FM » 2021-02-11
      ;(or (setq d (getdist "\nEnter offset distance <0> : ")) (setq d 0))
      (SETQ TEXT '() LINES '())
      ;;;
      ;
      (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
        (if (and (wcmatch (cdr (assoc 0 (setq xx (entget x)))) "*TEXT") (/= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" (cdr (assoc 8 xx))))))))
          (setq text (cons x text))
          (if (not (wcmatch (cdr (assoc 0 xx)) "*TEXT"))
            (setq lines (cons x lines))
          )
        )
      )
      (if lines
        (foreach x text
          (vla-getboundingbox (vlax-ename->vla-object x) 'minp 'maxp)
          (mapcar 'set '(minp maxp) (mapcar 'safearray-value (list minp maxp)))
          (setq mp (mapcar '(lambda (a b) (/ (+ a b) 2.0)) minp maxp))
          (setq
            l (mapcar
                '(lambda (x)
                   (list (setq p2 (vlax-curve-getclosestpointto x mp)) (distance mp p2) (_aap x p2))
                 )
                lines
              )
          )
          (setq l (car (vl-sort l '(lambda (a b) (< (cadr a) (cadr b))))))
          ;; Check that we have an angle assigned
          (if (caddr l)
            (progn
              (setq dxf50
                ((lambda (x)
                   (if (<= (* 0.5 pi) x (* 1.5 pi))
                     (+ x pi)
                     x
                   )
                 )
                 (caddr l)
                )
              )
              (entupd (cdr (assoc -1 (entmod (subst (cons 50 dxf50) (assoc 50 (setq xx (entget x))) xx)))))
              (vla-getboundingbox (vlax-ename->vla-object x) 'minp 'maxp)
              (mapcar 'set '(minp maxp) (mapcar 'safearray-value (list minp maxp)))
              (setq pp (mapcar '(lambda (a b) (/ (+ a b) 2.0)) minp maxp))
              (vla-move (vlax-ename->vla-object x) (vlax-3d-point pp) (vlax-3d-point mp))
              (vla-move (vlax-ename->vla-object x) (vlax-3d-point mp) (vlax-3d-point (car l)))
              ;
              ;;; FM » 2021-02-11
          (SETQ LX (ENTGET X))
          (COND
        ((= (CDR (ASSOC 0 LX))  "TEXT") (SETQ D (CDR (ASSOC 40 LX))) (SETQ D (* D 0.9)) )
        ((= (CDR (ASSOC 0 LX)) "MTEXT") (SETQ BB (ACET-GEOM-TEXTBOX LX 0.0001)) (SETQ D (DISTANCE (CADR BB) (CADR (CDR BB)))) (SETQ D (* D 0.7)) )
        ( T (SETQ D 0))
          )
          ;;;
          ;
              (vla-move (vlax-ename->vla-object x) (vlax-3d-point (car l)) (vlax-3d-point (polar (car l) (angle (car l) mp) D)))
            )
          )
        )
      )
    )
  )
  (vl-cmdf "_.UNDO" "_E")
  (princ)
)

 

  • Thanks 1
Posted

Before anyone comments on why I use uppercase I feel this is not correct here but after 48 years programming in uppercase it is very difficult to change, sorry.
OK.

  • 1 year later...
Posted

ronjonp / marko_ribar - Thank you for the Amazing Lisp and thanks to everyone who helped to achieve it.

I've been looking for such a long time to find something that is able to align / offset text to 3D Poly in AutoCAD and marko-ribar 's lisp finally does it. The lisp is really appreciated.

Posted
On 12/9/2022 at 4:36 AM, Marius C said:

ronjonp / marko_ribar - Thank you for the Amazing Lisp and thanks to everyone who helped to achieve it.

I've been looking for such a long time to find something that is able to align / offset text to 3D Poly in AutoCAD and marko-ribar 's lisp finally does it. The lisp is really appreciated.

Glad to help! Welcome to the forum. 🍻

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