Jonathan Handojo Posted Monday at 11:58 AM Posted Monday at 11:58 AM Changing the text's basepoint to middle center is definitely the way to go, because if there's ever a change needed in the text, it will stay centered to the circle. It's also the easiest to code from this way. However, if circumstances do not allow you to change the base point of the text, then it's not like it still can't be done: Use the textbox function to determine the boundary points of the text. Include the text style and height so the calculations are correct. (unless vla-GetBoundingBox alone can calculate the bounding of MTEXT without taking into consideration the mtext width). Use the midpoint of the coordinates returned to place it in the center of the circle. It involves a bit of calculation, so I'll leave it to the other programmers to write it up. 1 Quote
Steven P Posted Monday at 06:08 PM Posted Monday at 06:08 PM I temporarily change the base point to middle centre, then align the text and then reset to as it was - I think the code is a bit long winded but it works 1 Quote
Nikon Posted Monday at 07:47 PM Author Posted Monday at 07:47 PM 1 hour ago, Steven P said: Я временно меняю базовую точку на центральную, затем выравниваю текст, а потом возвращаюсь к исходному состоянию. Думаю, код немного длинноват, но он работает Where's the code? Quote
Steven P Posted 13 hours ago Posted 13 hours ago Perhaps not the cleanest code, this returns the alignment of a selected text, which you can apply to your selected texts in the codes above, (defun gettextalign ( txtset / txtset Edata ptx_old pty_old pty_new ptx_new mycons) ;; (setq txtset (ssget '((0 . "*TEXT")))) (setq Edata (entget (ssname txtset 0))) (setq mycons 10) (if (/= 0 (nth 1 (cdr (assoc 11 Edata))))(setq mycons 11)) (setq ptx_old (nth 1 (assoc mycons Edata))) (setq pty_old (nth 2 (assoc mycons Edata))) (command "_.justifytext" txtset "" "MC") (setq Edata (entget (ssname txtset 0))) (setq ptx_new (nth 1 (assoc mycons Edata))) (setq pty_new (nth 2 (assoc mycons Edata))) (if (< ptx_old ptx_new)(setq alignx "L")) (if (> ptx_old ptx_new)(setq alignx "R")) (if (= ptx_old ptx_new)(setq alignx "C")) (if (> pty_old pty_new)(setq aligny "T")) (if (< pty_old pty_new)(setq aligny "B")) (if (= pty_old pty_new)(setq aligny "M")) (setq xyalign (strcat aligny alignx)) (command "_.justifytext" txtset "" xyalign) xyalign ) 1 Quote
Nikon Posted 6 hours ago Author Posted 6 hours ago The mtext moves to the center of the circle, but when you select the text, the code returns an error. Select the text (Text or MText): ; error: no function definition: VLA-GET-JUSTIFY How can this be fixed? (defun c:CentCircleTxt (/ enCircle enText objCircle objText center objName) (vl-load-com) (setq enCircle (car (entsel "\nSelect a circle: "))) (if (not enCircle) (progn (princ "\nThe circle is not selected.") (exit)) ) (setq objCircle (vlax-ename->vla-object enCircle)) (setq center (vla-get-center objCircle)) (setq enText (car (entsel "\nSelect the text (Text or MText): "))) (if (not enText) (progn (princ "\nThe text is not selected.") (exit)) ) (setq objText (vlax-ename->vla-object enText)) (setq objName (vla-get-ObjectName objText)) (cond ((= objName "AcDbText") (if (/= (vla-get-Justify objText) acJustifyMiddleCenter) (vla-put-Justify objText acJustifyMiddleCenter) ) (vla-put-AlignmentPoint objText center) ) ((= objName "AcDbMText") (if (/= (vla-get-AttachmentPoint objText) acAttachmentPointMiddleCenter) (vla-put-AttachmentPoint objText acAttachmentPointMiddleCenter) ) (vla-put-InsertionPoint objText center) ) (t (princ (strcat "\nThe selected object is not supported: " objName)) ) ) (vla-Update objText) (princ "\nThe center of the text is the same as the center of the circle.") (princ) ) Quote
ronjonp Posted 4 hours ago Posted 4 hours ago (edited) @nikon The text within circles looks like you should be using a block with an attribute rather than two separate objects. Edited 4 hours ago by ronjonp Quote
Recommended Posts
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.