Jonathan Handojo Posted February 10 Posted February 10 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 February 10 Posted February 10 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 February 10 Author Posted February 10 1 hour ago, Steven P said: Я временно меняю базовую точку на центральную, затем выравниваю текст, а потом возвращаюсь к исходному состоянию. Думаю, код немного длинноват, но он работает Where's the code? Quote
Steven P Posted February 11 Posted February 11 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 February 11 Author Posted February 11 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 February 11 Posted February 11 (edited) @nikon The text within circles looks like you should be using a block with an attribute rather than two separate objects. Edited February 11 by ronjonp 1 Quote
Nikon Posted February 12 Author Posted February 12 (edited) On 09.02.2025 at 16:59, Lee Mac said: The code is not made to order; it is a starting point from which you can learn and modify it to suit your requirements. I'm wondering how many program options there can be... I'm adding one line to the Lee Mac code: (setq ss (ssget ":L" '((0 . "*TEXT")))) (vl-cmdf "_justifytext" ss "" "_mc") but you need to select objects twice: select - enter, select - enter again... Conveniently, you can select multiple objects using the frame... How can I avoid repeating "enter"? ;; Text 2 Point - Lee Mac 2012 ;; Prompts for a selection of Text and Point entities and moves ;; each Text entity to the nearest (2D distance) Point entity in the set. ;; https://www.cadtutor.net/forum/topic/37515-moving-text-block-to-adjacent-point/#comment-306285 ;; Retains existing Text elevation. ;; Binding the center of the text to the center of the circle (defun c:txt2pt-circle ( / _textinsertion di1 di2 dxf ent inc ins lst mpt pnt sel txt ) (setq ss (ssget ":L" '((0 . "*TEXT")))) (vl-cmdf "_justifytext" ss "" "_mc") ; ??? (defun _textinsertion ( elist ) (if (and (zerop (cdr (assoc 72 elist))) (zerop (cdr (assoc 73 elist))) ) (cdr (assoc 10 elist)) (cdr (assoc 11 elist)) ) ) ; (if (setq sel (ssget "_:L" '((0 . "POINT,TEXT")))) (if (setq sel (ssget "_:L" '((0 . "CIRCLE,TEXT")))) (progn (repeat (setq inc (sslength sel)) (setq ent (entget (ssname sel (setq inc (1- inc))))) ; (if (eq "POINT" (cdr (assoc 0 ent))) (if (eq "CIRCLE" (cdr (assoc 0 ent))) (setq lst (cons (cdr (assoc 10 ent)) lst)) (setq txt (cons (cons (_textinsertion ent) ent) txt)) ) ) (foreach ent txt (setq ins (list (caar ent) (cadar ent))) (if (setq pnt (vl-some '(lambda ( pnt ) (equal ins (list (car pnt) (cadr pnt)) 1e-8)) lst)) (setq lst (vl-remove pnt lst)) (progn (setq di1 (distance ins (list (caar lst) (cadar lst))) mpt (car lst) ) (foreach pnt (cdr lst) (if (< (setq di2 (distance ins (list (car pnt) (cadr pnt)))) di1) (setq di1 di2 mpt pnt ) ) ) (setq pnt (list (car mpt) (cadr mpt) (caddar ent)) dxf (cdr ent) dxf (subst (cons 10 pnt) (assoc 10 dxf) dxf) dxf (subst (cons 11 pnt) (assoc 11 dxf) dxf) ) (entmod dxf) (setq lst (vl-remove mpt lst)) ) ) ) ) ) (princ) ) (vl-load-com) (princ) Edited February 12 by Nikon Quote
GLAVCVS Posted February 13 Posted February 13 (edited) A variation of the original (defun c:AlignTxtToCircleAllDrawing (/ n conj conj1 ent ent1 lstent pto rad pt1 pt2 x pto selEnt distMin AlignTxtToCircle 1x1? osmant) (defun AlignTxtToCircle (circle textObj / mtextObj centerPoint textHeight circles texts opt centroTexto ) (defun centroTexto (lstent / cajatx difx dify SO SE NE NO ptC) (if (= (cdr (assoc 0 lstent)) "MTEXT") (setq NO (cdr (assoc 10 lstent)) ptC (list (+ (car NO) (/ (cdr (assoc 41 lstent)) 2.0)) (- (cadr NO) (/ (cdr (assoc 40 lstent)) 2.0)) ) ) (setq cajatx (textbox lstent) difx (- (car (cadr cajatx)) (car (car cajatx))) dify (- (cadr (cadr cajatx)) (cadr (car cajatx))) SO (polar (cdr (assoc 10 lstent)) (- (cdr (assoc 50 lstent)) (/ pi 2)) (abs (cadr (car cajatx))) ) NE (polar (polar so (cdr (assoc 50 lstent)) difx) (+ (cdr (assoc 50 lstent)) (/ pi 2)) dify) ptC (polar SO (angle SO NE) (/ (distance SO NE) 2.0)) ) ) ptC ) (defun obj->txMC (ent / lstent tipObj vlaEnt texto estilo capa ang ptins altura) (cond ((= (setq tipObj (cdr (assoc 0 (setq lstent (entget ent))))) "TEXT" ) (vlax-put-property (vlax-ename->vla-object ent) "Alignment" 10 ) (vlax-put-property (vlax-ename->vla-object ent) "TextAlignmentPoint" (VLAX-3D-POINT (cdr (assoc 10 lstent))) ) ent ) ((= tipObj "MTEXT") (setq texto (if (setq pos (vl-string-search ";" (cdr (assoc 1 lstent))) ) (if (setq pos (vl-string-search "}" (setq texto (substr (cdr (assoc 1 lstent)) (+ pos 2) ) ) ) ) (substr texto 1 pos) texto ) (cdr (assoc 1 lstent)) ) estilo (cdr (assoc 7 lstent)) capa (cdr (assoc 8 lstent)) ang (cdr (assoc 50 lstent)) ptins (cdr (assoc 10 lstent)) altura (cdr (assoc 40 lstent)) vlaEnt (vla-AddText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object) ) ) texto (VLAX-3D-POINT ptins) altura ) ) (vlax-put vlaEnt "ROTATION" ang) (vlax-put vlaEnt "LAYER" capa) (vlax-put vlaEnt "STYLENAME" estilo) (vlax-put-property vlaEnt "Alignment" 10) (vlax-put-property vlaEnt "TextAlignmentPoint" (VLAX-3D-POINT ptins) ) (vla-delete (vlax-ename->vla-object ent)) (vlax-vla-object->ename vlaEnt) ) (T (alert "Tipo de objeto no es TEXT ni MTEXT") nil ) ) ) (redraw selEnt 3) (if 1x1? (grdraw (centroTexto (entget selEnt)) (cdr (assoc 10 (entget ent))) 1 2 ) ) (initget 1 "SKIP SELECT YES") (if (or (not 1x1?) (member (setq opt (strcase (getstring "\n*** Align this text? [sKip/Select other/<Yes>] : "))) '("Y" "") ) ) (if (or (and selEnt (setq textObj (obj->txMC selEnt))) (and (setq selEnt (car (entsel "\nText not found. Select text..."))) (wcmatch (cdr (assoc 0 (entget selEnt))) "*TEXT") (setq textObj (obj->txMC selEnt))) ) (vl-cmdf "_move" textObj "" (cdr (assoc 11 (entget textObj))) (cdr (assoc 10 (entget ent))) ) (princ "\n*** OMITED ***") ) (if (and (not (redraw selEnt 4)) (member opt '("S" "SELECT")) ) (if (and (setq selEnt (car (entsel))) (wcmatch (cdr (assoc 0 (entget selEnt))) "*TEXT") ) (if (and (not (redraw selEnt 3)) (setq textObj (obj->txMC selEnt)) ) (vl-cmdf "_move" textObj "" (cdr (assoc 11 (entget textObj))) (cdr (assoc 10 (entget ent))) ) ) ) ) ) (redraw selEnt 4) ) (setq n 0 osmant (getvar "OSMODE")) (setvar "OSMODE" 0) (princ "\nSelect circles...") (if (setq conj (ssget '((0 . "CIRCLE") (8 . "*")))) (progn (initget 1 "NO YES") (setq 1x1? (getkword "\nDo you want analyze circle by circle? [No/<Yes>]: ")) (if (= 1x1? "YES") (setq 1x1? T) (setq 1x1? nil) ) (while (setq ent (ssname conj n)) (setq lstent (entget ent) pto (cdr (assoc 10 lstent)) rad (cdr (assoc 40 lstent)) selEnt nil distMin nil n (+ n 1) ) (if 1x1? (vl-cmdf "_zoom" (setq pt1 (list (- (car pto) (* rad 10.0)) (- (cadr pto) (* rad 10.0)))) (setq pt2 (list (+ (car pto) (* rad 10.0)) (+ (cadr pto) (* rad 10.0))))) (setq pt1 (list (- (car pto) (* rad 10.0)) (- (cadr pto) (* rad 10.0))) pt2 (list (+ (car pto) (* rad 10.0)) (+ (cadr pto) (* rad 10.0))) ) ) (if (setq conj1 (ssget "_W" pt1 pt2 '((0 . "*TEXT")))) (progn (foreach ent1 (mapcar 'cadr (vl-remove-if-not (function (lambda (x) (member (car x) '(0 2 3)))) (ssnamex conj1))) (if distMin (if (< (setq dist (distance pto (setq pto1 (cdr (assoc 10 (entget ent1)))))) distmin) (setq selEnt ent1 distMin dist) ) (setq distMin (distance pto (cdr (assoc 10 (entget ent1)))) selEnt ent1 ) ) ) (AlignTxtToCircle ent selEnt) (redraw) ) ) ) ) ) (setvar "OSMODE" osmant) (redraw) (princ) ) Edited February 14 by GLAVCVS 1 Quote
Nikon Posted February 14 Author Posted February 14 (edited) On 2/13/2025 at 11:44 PM, GLAVCVS said: A variation on your original program @GLAVCVS many thanks! Your code splits the mtext, align the mc, but does not place it in the center of the circle... If it were possible to combine codes for text (txt 2 pt-circle) and mtext (mtxt-circle-centre), but they work well individually. But you have to select objects twice... I really like the Lee Mac code "Text 2 Point" - just change POINT to CIRCLE. (defun c:mtxt-circle-centre ( / ss i_textinsertion di1 di2 dxf ent inc ins lst mpt pnt sel txt ) (setq ss (ssget '((0 . "MTEXT"))) old_sett (getvar 'CMDECHO) doc (vla-get-activedocument (vlax-get-acad-object)) ) ;_ end setq (vla-StartUndoMark doc) (setvar 'CMDECHO 0) (if ss (repeat (setq i (sslength ss)) (vl-cmdf "_.EXPLODE" (ssname ss (setq i (1- i)))) (vl-cmdf "_justifytext" "_P" "" "_mc") ) ) (defun _textinsertion ( elist ) (if (and (zerop (cdr (assoc 72 elist))) (zerop (cdr (assoc 73 elist))) ) (cdr (assoc 10 elist)) (cdr (assoc 11 elist)) ) ) (if (setq sel (ssget "_:L" '((0 . "CIRCLE,TEXT")))) (progn (repeat (setq inc (sslength sel)) (setq ent (entget (ssname sel (setq inc (1- inc))))) ; (if (eq "POINT" (cdr (assoc 0 ent))) (if (eq "CIRCLE" (cdr (assoc 0 ent))) (setq lst (cons (cdr (assoc 10 ent)) lst)) (setq txt (cons (cons (_textinsertion ent) ent) txt)) ) ) (foreach ent txt (setq ins (list (caar ent) (cadar ent))) (if (setq pnt (vl-some '(lambda ( pnt ) (equal ins (list (car pnt) (cadr pnt)) 1e-8)) lst)) (setq lst (vl-remove pnt lst)) (progn (setq di1 (distance ins (list (caar lst) (cadar lst))) mpt (car lst) ) (foreach pnt (cdr lst) (if (< (setq di2 (distance ins (list (car pnt) (cadr pnt)))) di1) (setq di1 di2 mpt pnt ) ) ) (setq pnt (list (car mpt) (cadr mpt) (caddar ent)) dxf (cdr ent) dxf (subst (cons 10 pnt) (assoc 10 dxf) dxf) dxf (subst (cons 11 pnt) (assoc 11 dxf) dxf) ) (entmod dxf) (setq lst (vl-remove mpt lst)) ) ) ) ) ) (princ) ) (vl-load-com) (princ) Edited Sunday at 06:43 PM by Nikon Quote
GLAVCVS Posted February 14 Posted February 14 Are you sure it doesn't work? Maybe I don't understand you well. Anyway, copy the code again and try it: I changed something 1 Quote
GLAVCVS Posted February 14 Posted February 14 In any case, there are some things you should improve in your code. For example, replacing the calls to 'command' with other, more efficient methods. It is better for you to learn to do these small improvements yourself, little by little. 1 Quote
Nikon Posted February 14 Author Posted February 14 (edited) 40 minutes ago, GLAVCVS said: In any case, there are some things you should improve in your code. For example, replacing the calls to 'command' with other, more efficient methods. It is better for you to learn to do these small improvements yourself, little by little. It seems to me that your code is a bit complicated, there is probably an easier way, like the Lee Mac program Text 2 Point. ;; Text 2 Point - Lee Mac 2012 ;; Prompts for a selection of Text and Point entities and moves ;; each Text entity to the nearest (2D distance) Point entity in the set. ;; Retains existing Text elevation. (defun c:txt2pt.... The <Yes> option doesn't work here: Do you want analyze circle by circle? [No/<Yes>]: The texts are positioned incorrectly. Edited February 14 by Nikon Quote
GLAVCVS Posted February 14 Posted February 14 There's something fishy here. I've tried it with justified texts in various ways and with MTEXTs and it works fine Attach that drawing I'll take a look at it this afternoon Quote
Nikon Posted February 14 Author Posted February 14 (edited) 6 hours ago, GLAVCVS said: There's something fishy here. tried it with justified texts in various ways and with MTEXTs and it works fine Attach that drawing I'll take a look at it this afternoon Try the two codes mtxt-circle-centre and txt2pt-circle, they work as they should, with minor limitations... AlignTxtToCircleAllDrawing.dwg Edited February 14 by Nikon Quote
Steven P Posted February 14 Posted February 14 (edited) This is a bit longer than it needs to be, should align text to a circle and 'MC' the text, works with MText, Text and Attributes Command txt2circ Also include txt2rect (centres text between 2 points) txt2cent (centres text in centroid of closed polygon, also circles) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun rectcentre ( / pt1 pt2 ptx pty ptz ptc) ; Returns centre of a rectangle (2 points) (setq pt1 (getpoint "\nPick Corner 1")) (setq pt2 (getpoint "\nPick Corner 2")) (setq ptx (+ (nth 0 pt1) (/ (- (nth 0 pt2)(nth 0 pt1)) 2)) ) ;; do these 3 lines with mapcar (setq pty (+ (nth 1 pt1) (/ (- (nth 1 pt2)(nth 1 pt1)) 2)) ) (setq ptz (+ (nth 2 pt1) (/ (- (nth 2 pt2)(nth 2 pt1)) 2)) ) (setq ptc (list ptx pty ptz)) ptc ) (defun circcentre ( / circ ent ptc enttype) ; returns centre of a circle (princ "\nSelect Circle") (while (/= enttype "CIRCLE") (setq circ (car (entsel ""))) (setq ent (entget circ)) (setq enttype (cdr (assoc 0 ent))) ) (setq ptc (assoc 10 ent)) (setq ptc (list (nth 1 ptc)(nth 2 ptc)(nth 3 ptc))) ptc ) (defun cent (/ obj rgn pt) ;;https://www.cadtutor.net/forum/topic/71044-center-of-polygon/ (if (and (setq obj (car (entsel "\nSelect object to calculate centroid: "))) (setq spc (vlax-ename->vla-object (cdr (assoc 330 (entget obj))))) (setq obj (vlax-ename->vla-object obj)) (= 'list (type (setq rgn (vl-catch-all-apply 'vlax-invoke (list spc 'addregion (list obj)))))) ) (progn (setq pt (vlax-get (setq rgn (car rgn)) 'centroid)) (vl-catch-all-apply 'vla-delete (list rgn)) ) ) pt ) (defun c:txt2rect ( / ptc centretext) ; Place text between 2 points (setq ptc (rectcentre)) (txt2centre ptc) ) (defun c:txt2circ ( / ptc) ; place text in centre of circle (setq ptc (circcentre)) (txt2centre ptc) ) (defun c:txt2cent ( / ptc) ; place text in middle of centroid (setq ptc (cent)) (txt2centre ptc) ) (defun txt2centre ( ptc / txtset alignment myrotation Edata ptx pty mycons NewInsData NewData entlist entwidth newwidth elist sel endloop enttype txt) ;;;;;;;; Sub routines ;;;;;;;;; ;; From Box Text LISP ;; Text Box - gile / Lee Mac ;; Returns an OCS point list describing a rectangular frame surrounding ;; the supplied text or mtext entity with optional offset ;; enx - [lst] Text or MText DXF data list ;; off - [rea] offset (may be zero) (defun text-box-off ( enx off / bpt hgt jus lst ocs org rot wid ) (cond ( (= "TEXT" (cdr (assoc 00 enx))) (setq bpt (cdr (assoc 10 enx)) rot (cdr (assoc 50 enx)) lst (textbox enx) lst (list (list (- (caar lst) off) (- (cadar lst) off)) (list (+ (caadr lst) off) (- (cadar lst) off)) (list (+ (caadr lst) off) (+ (cadadr lst) off)) (list (- (caar lst) off) (+ (cadadr lst) off)) ) ) ) ( (= "MTEXT" (cdr (assoc 00 enx))) (setq ocs (cdr (assoc 210 enx)) bpt (trans (cdr (assoc 10 enx)) 0 ocs) rot (angle '(0.0 0.0) (trans (cdr (assoc 11 enx)) 0 ocs)) wid (cdr (assoc 42 enx)) hgt (cdr (assoc 43 enx)) jus (cdr (assoc 71 enx)) org (list (cond ((member jus '(2 5 8)) (/ wid -2.0)) ((member jus '(3 6 9)) (- wid)) (0.0)) (cond ((member jus '(1 2 3)) (- hgt)) ((member jus '(4 5 6)) (/ hgt -2.0)) (0.0)) ) lst (list (list (- (car org) off) (- (cadr org) off)) (list (+ (car org) wid off) (- (cadr org) off)) (list (+ (car org) wid off) (+ (cadr org) hgt off)) (list (- (car org) off) (+ (cadr org) hgt off)) ) ) ) ) (if lst ( (lambda ( m ) (mapcar '(lambda ( p ) (mapcar '+ (mxv m p) bpt)) lst)) (list (list (cos rot) (sin (- rot)) 0.0) (list (sin rot) (cos rot) 0.0) '(0.0 0.0 1.0) ) ) ) ) ; end textboxoff (defun gettextalign ( txtset / txtset Edata ptx_old pty_old pty_new ptx_new mycons) (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) ;; remove this line to leave MC aligned xyalign ) ;;;;;;;;;; End sub routines ;;;;;;;;;;; (setq thisdrawing (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark thisdrawing) (princ "\nSelect Text") (while (and (/= enttype "TEXT")(/= enttype "MTEXT")(/= enttype "ATTDEF")) (setq txt (car (entsel ""))) (setq Edata (entget txt)) (setq enttype (cdr (assoc 0 Edata))) ) (setq txtset (ssadd)) (setq txtset (ssadd txt txtset)) (setq myrotation (cdr (assoc 50 Edata))) (setq Newdata (subst (cons 50 0) (assoc 50 Edata) Edata) ) (entmod Newdata) (setq alignment (gettextalign txtset)) (setq ptx (nth 0 (assoc 10 Edata))) (setq pty (nth 1 (assoc 10 Edata))) (command "_.justifytext" txtset "" "MC") (setq Edata (entget (ssname txtset 0))) (setq mycons 10) (if (/= 0 (nth 1 (cdr (assoc 11 Edata))))(setq mycons 11)) (setq NewInsData (cons mycons ptc) ) (setq Newdata (subst NewInsdata (assoc mycons Edata) Edata) ) (if (= "TEXT" (cdr (assoc 0 Edata))) (progn (setq Newdata (subst (cons 50 myrotation)(assoc 50 Newdata) Newdata)) (entmod Newdata) ) ) (if (= "ATTDEF" (cdr (assoc 0 Edata))) (progn (entmod Newdata) ) ) (if (= "MTEXT" (cdr (assoc 0 Edata))) ;;mtext etc. (progn (setq entlist Edata) ;;could be Edata (setq entwidth entlist) (setq newwidth (cdr (assoc 42 entlist))) ;;text line width assoc 41 for mtext 'box' width (if (< newwidth (cdr (assoc 42 entwidth)))(setq newwidth (+ MWidth newwidth))) (if (= (cdr (assoc 41 entlist)) 0)(setq newwidth 0)) ;;fix for zero width mtexts (setq elist (subst (cons 41 newwidth)(assoc 41 Edata) Edata)) ;;if txt this is width factor, mtext its text width (setq elist (subst (cons mycons ptc)(assoc mycons elist) elist)) (setq elist (subst (cons 50 myrotation)(assoc 50 elist) elist)) (entmod elist) ) ) (setq alignment "MC") (command "_.justifytext" txtset "" alignment) (vla-endundomark thisdrawing) (princ) ) Edited February 14 by Steven P 1 Quote
Nikon Posted February 14 Author Posted February 14 46 minutes ago, Steven P said: This is a bit longer than it needs to be, should align text to a circle and 'MC' the text, works with MText, Text and Attributes Thank you, everyone! You give such complex codes, but the task is quite simple... @Steven P, I haven't been able to get the code to work yet, but I'm still testing... Quote
Steven P Posted February 14 Posted February 14 Save it all as in a single LISP file and see - might be I need to include another sub function Quote
Saxlle Posted February 14 Posted February 14 On 11/02/2025 at 22:12, ronjonp said: The text within circles looks like you should be using a block with an attribute rather than two separate objects Totally agree with this. Quote
Isaac26a Posted February 14 Posted February 14 3 hours ago, Nikon said: 4 hours ago, GLAVCVS said: In any case, there are some things you should improve in your code. For example, replacing the calls to 'command' with other, more efficient methods. It is better for you to learn to do these small improvements yourself, little by little. It seems to me that your code is a bit complicated, there is probably an easier way, like the Lee Mac program Text 2 Point. ;; Text 2 Point - Lee Mac 2012 It seems that you have the text moved to where you want, just have to use the properties panel to change the alignment to midcenter. 1 Quote
Nikon Posted February 14 Author Posted February 14 (edited) 2 hours ago, Saxlle said: On 2/12/2025 at 12:12 AM, ronjonp said: The text within circles looks like you should be using a block with an attribute rather than two separate objects Totally agree with this. There are no attributes, just text and a circle. 1 hour ago, Isaac26a said: It seems that you have the text moved to where you want, just have to use the properties panel to change the alignment to midcenter. I don't want to use the toolbar, I only need the center alignment... Without a choice... Edited February 14 by Nikon 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.