Set text to center on circle by lisp

Set text to center on circle by lisp

ramoneramone
Enthusiast Enthusiast
2,022 Views
8 Replies
Message 1 of 9

Set text to center on circle by lisp

ramoneramone
Enthusiast
Enthusiast

I 'd like to set text to center on circle by lisp.

I tried it,but failed. Anyone teach how to?

 

1. select text

2. select circle for getting x.y.z

3. set text to center on circle

 

(progn

(setq sourceobj (entget (car (entsel "select text"))))

(setq circle(entget(car(entsel "select circle"))))

(setq var (cdr (assoc 10 circle)))

(entmod (subst (cons 11 var)(assoc 11 sourceobj) sourceobj))

(entmod (subst (cons 73 4)(assoc 73 sourceobj) sourceobj))

)

 

0 Likes
2,023 Views
8 Replies
Replies (8)
Message 2 of 9

paullimapa
Mentor
Mentor
Accepted solution

this should take care of Text various insertion points:

(if(and(zerop (cdr (assoc 72 sourceobj)))(zerop (cdr (assoc 73 sourceobj))))
  (progn ; then, it's left-justified, so 
   (entmod (subst (cons 10 var)(assoc 10 sourceobj) sourceobj)) ; (cdr(assoc 10 sourceobj)) is the insertion point...
  )
  (progn ; ...else, it's some other justification, so
   (entmod (subst (cons 11 var)(assoc 11 sourceobj) sourceobj)) ; (cdr (assoc 11 sourceobj)) is the insertion point...
  )
) ; if

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 9

Sea-Haven
Mentor
Mentor
Accepted solution

Try this also resets text to Middle centre.

 

(defun c:wow (/ ss p11 circle pc sourceobj)
(setq sourceobj (car (entsel "select text")))
(setq ss (ssadd))
(setq ss (ssadd sourceobj ss))
(acet-tjust ss "MC")
(setq p11 (cdr (assoc 11 (entget sourceobj))))
(setq circle (entget (car (entsel "select circle"))))
(setq pc (cdr (assoc 10 circle)))
(command "move" sourceobj "" p11 pc)
(princ)
)
(c:wow)

 

Message 4 of 9

ramoneramone
Enthusiast
Enthusiast

I have solved.

Thanks 

0 Likes
Message 5 of 9

ВeekeeCZ
Consultant
Consultant

@ramoneramone wrote:

I 'd like to set text to center on circle by lisp.

I tried it,but failed. Anyone teach how to?

 

1. select text

2. select circle for getting x.y.z

3. set text to center on circle

 

(progn

(setq sourceobj (entget (car (entsel "select text"))))

(setq circle(entget(car(entsel "select circle"))))

(setq var (cdr (assoc 10 circle)))

(entmod (setq sourceobj (subst (cons 11 var)(assoc 11 sourceobj) sourceobj)))

(entmod (subst (cons 73 4)(assoc 73 sourceobj) sourceobj))

)

 


 

Aside other issues mentioned above, note that you need to SAVE the definition with the blue change otherwise the red change is applied to the original definition (without blue change).

Message 6 of 9

Sea-Haven
Mentor
Mentor
Accepted solution

That explains why the text was jumping to wrong place when setting assoc 11.

Message 7 of 9

komondormrex
Mentor
Mentor
Accepted solution
(defun c:m_text_center_circle (/ m_text_object circle_object)
  (prompt "\nPick M_Text: ")
  (setq m_text_object (vlax-ename->vla-object (ssname (ssget "_:S+." '((0 . "*text"))) 0)))
  (prompt "\nPick circle: ")
  (setq circle_object (vlax-ename->vla-object (ssname (ssget "_:S+." '((0 . "circle"))) 0)))
  (mapcar 'vlax-put (list m_text_object m_text_object)
    (if (= "AcDbText" (vla-get-objectname m_text_object))
     (list 'Alignment 'TextAlignmentPoint)
    (list 'Attachmentpoint 'InsertionPoint)
          )
           (if (= "AcDbText" (vla-get-objectname m_text_object))
         (list 4 (vlax-get circle_object 'center))
       (list 5 (vlax-get circle_object 'center))
          )
  )
)
Message 8 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

If it's of any interest, this can certainly be done without changing the justification, by using the bounding box.

Kent Cooper, AIA
Message 9 of 9

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

If it's of any interest, this can certainly be done without changing the justification, by using the bounding box.


In which case, you can use it for Text or Mtext if you want, without caring about justification, but also for any other kind of object:

 

(defun C:O2CC (/ ent cir); = Object {to} Circle's Center
  (if
    (and
      (setq esel (entsel "\nSelect object to center in Circle: "))
      (setq csel (entsel "\nSelect Circle to center it in: "))
      (member '(0 . "CIRCLE") (setq cdata (entget (car csel))))
    ); and
    (progn ; then
      (setq ent (car esel))
      (vla-getboundingbox (vlax-ename->vla-object ent) 'minpt 'maxpt)
      (command "_.move" ent ""
        "_non" (mapcar '/ (mapcar '+ (vlax-safearray->list minpt) (vlax-safearray->list maxpt)) '(2 2 2))
        "_non" (cdr (assoc 10 cdata))
      )
    ); progn
    (prompt "\nMissed in selection, or second object was not a Circle.")
  ); if
  (prin1)
)

It could pretty easily be enhanced to let you select a Circle that's nested in a Block or Xref, if that's needed.

 

Kent Cooper, AIA