rcb007 Posted December 20 Posted December 20 I found this routine which will take mtext vaules, (with fields) to a mleader. I am having a hard time trying to figure out how to get this routine to work with dtext and dtexts which have a field value to them. I thought by removing the mtext, and replacing it with a *text; that would work. However, not the case. (setq oobj (vlax-ename->vla-object (car (entsel "\nSelect source text: ")) ) ) (setq ad (vla-get-ActiveDocument (vlax-get-acad-object))) (if (= (vlax-get-property oobj 'ObjectName) "AcDbMText,AcDbText");;????? (progn (if (not (setq nstrg (LM:FieldCode (vlax-vla-object->ename oobj))) ) (setq nstrg (vlax-get-property oobj 'TextString)) ) ;if ;2023/07/31 added Lee Mac routine to carryover the Fields. ;;Added Auto Regen ;;Need method to convert text to mtext then to a mleader. (defun c:mt2ml (/ oobj nobj nstrg ad Insertionpoint secondpoint oobj nobj mleader olderr) (vl-load-com) ;Important field extraction code by Lee Mac!! (defun LM:FieldCode (en / fd id) (cond ((and (wcmatch (cdr (assoc 0 (setq en (entget en)))) "*TEXT" ) (setq en (cdr (assoc 360 en))) (setq en (dictsearch en "ACAD_FIELD")) (setq en (dictsearch (cdr (assoc -1 en)) "TEXT")) (setq fd (entget (cdr (assoc 360 en)))) ) (if (vl-string-search "\\_FldIdx " (cdr (assoc 2 en))) (vl-string-subst (if (setq id (cdr (assoc 331 fd))) (vl-string-subst (strcat "ObjId " (itoa (vla-get-objectid (vlax-ename->vla-object id))) ) "ObjIdx 0" (cdr (assoc 2 fd)) ) (cdr (assoc 2 fd)) ) "\\_FldIdx 0" (cdr (assoc 2 en)) ) (cdr (assoc 2 en)) ) ) ) ); (setq oobj (vlax-ename->vla-object (car (entsel "\nSelect source text: ")) ) ) (setq ad (vla-get-ActiveDocument (vlax-get-acad-object))) (if (= (vlax-get-property oobj 'ObjectName) "AcDbMText") (progn (if (not (setq nstrg (LM:FieldCode (vlax-vla-object->ename oobj))) ) (setq nstrg (vlax-get-property oobj 'TextString)) ) ;if (setq InsertionPoint (getpoint "\nPick first point for MLeader: ") ) (setq SecondPoint (getpoint "\nPick next point for text location: ") ) (setq PointList (vlax-make-variant (vlax-safearray-fill (safearray vlax-vbdouble '(0 . 5)) (apply 'append (list InsertionPoint SecondPoint)) ) ) ) (setq mleader (vla-addMLeader (if (= 1 (vla-get-activespace ad)) (vla-get-modelspace ad) (if (= (vla-get-mspace ad) :vlax-true) (vla-get-modelspace ad) (vla-get-paperspace ad) ) ) ;if PointList 0 ) ;vla-addmleader ) ;setq (vlax-put-property mleader 'TextString nstrg) (vla-SetDogLegDirection mleader 0 (vlax-3D-point (list (if (< (car InsertionPoint) (car SecondPoint)) 1 -1 ) 0 0 ) ) ) (entdel (vlax-vla-object->ename oobj)) ;; (prompt "\nFIELDS require a REGEN to update the text.") (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (vla-Regen doc acAllViewports) );progn (progn (princ ;; "\nTry again with a TEXT or MTEXT entity. Press ENTER to try again." "\nTry again with a MTEXT entity. Press ENTER to try again." ) ) ) (princ) ) Thank you for the help. Quote
AlanGon3 Posted December 20 Posted December 20 Hey rcb007, When I create a dtext object (I have never used these before) it seems to be considered a regular text object, you may just need to iterate over all text objects running the "txt2mtext" command and then use your mt2ml command thereafter Let me know if I'm way off base and misunderstanding what you need - I figure worst case, it will help other people know what you need with a bit more clarity. Quote
AlanGon3 Posted December 20 Posted December 20 1 hour ago, rcb007 said: Hope this helps! mt2ml example.dwg 504.3 kB · 0 downloads After looking at the example drawing, and the way the command it used, you can just type "txt2mtxt" (a default autocad command) select the text object and then run your command, alternatively you could include an if statement that will run the command if the selected object is "TEXT" and otherwise run the code as normal. Quote
rcb007 Posted December 20 Author Posted December 20 That is a good point. I did try to do that, but the direct texts which have a field value to them, get transferred to Mtext without the field value. It becomes dumb text. Quote
AlanGon3 Posted December 20 Posted December 20 48 minutes ago, rcb007 said: That is a good point. I did try to do that, but the direct texts which have a field value to them, get transferred to Mtext without the field value. It becomes dumb text. When I use DXFLIST (by ronjonp) on one of the text entities; I get this output: (-1 . <Entity name: 21413207cd0>) (0 . "TEXT") (5 . "10DD") (102 . "{ACAD_XDICTIONARY") (360 . <Entity name: 21413207ce0>) (102 . "}") (330 . <Entity name: 2141b9ee1f0>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbText") (10 0.504506 11.3256 0.0) (40 . 2.4) (1 . "655.7974") (50 . 0.34982) (41 . 1.0) (51 . 0.0) (7 . "Standard") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0) (-3 ("AcadAnnotative" (1000 . "AnnotativeData") (1002 . "{") (1070 . 1) (1070 . 0) (1002 . "}"))) I'm guessing the (-3) stuff is what you need to keep right? Quote
BIGAL Posted December 20 Posted December 20 I did not try to fix but I think your mixing variables between entity and a VL object LM:FIELDCODE (car (entsel))) Select entity: "%<\\AcObjProp Object(%<\\_ObjId 1220827424>%).Area \\f \"%lu2\">%" (setq oobj (vlax-ename->vla-object (car (entsel "\nSelect source text: ")) ) ) (setq ad (vla-get-ActiveDocument (vlax-get-acad-object))) (if (= (vlax-get-property oobj 'ObjectName) "AcDbMText") So your asking to get an object oobj but then check is it mtext but its Text ? So I would remove the (IF checking type or use just that add (or check is it "AcDBText". Quote
AlanGon3 Posted December 21 Posted December 21 I've been trying to fix, albeit pretty unsuccessfully given my inexperience with the vla commands. I followed the Afralisp tutorials sometime back and just never seemed to have a practical application to use it for. Hoping to get better by looking into things like this ( so sorry to rcb if my suggestions aren't the most helpful - but I'm working on it) I found the vla-getxdata command and my idea was to extract the xdata, turn it to a list, and entmod it back onto the new mleader, but while trying to debug I realized this may just be confusing enough for me to need a break. vla-getxdata: https://adndevblog.typepad.com/autocad/2013/01/xdata-using-vla-get-and-vla-set.html Quote
hosneyalaa Posted December 21 Posted December 21 try ;2023/07/31 added Lee Mac routine to carryover the Fields. ;;Added Auto Regen https://www.cadtutor.net/forum/topic/95318-mleader-from-mtext/ ;;Need method to convert text to mtext then to a mleader. (defun c:tt2ml (/ oobj nobj nstrg ad Insertionpoint secondpoint oobj nobj mleader olderr) (vl-load-com) ;Important field extraction code by Lee Mac!! (setq en (vlax-vla-object->ename oobj) ) (defun LM:FieldCode (en / fd id) (cond ((and (wcmatch (cdr (assoc 0 (setq en (entget en)))) "*TEXT" ) (setq en (cdr (assoc 360 en))) (setq en (dictsearch en "ACAD_FIELD")) (setq en (dictsearch (cdr (assoc -1 en)) "TEXT")) (setq fd (entget (cdr (assoc 360 en)))) ) (if (vl-string-search "\\_FldIdx " (cdr (assoc 2 en))) (vl-string-subst (if (setq id (cdr (assoc 331 fd))) (vl-string-subst (strcat "ObjId " (itoa (vla-get-objectid (vlax-ename->vla-object id))) ) "ObjIdx 0" (cdr (assoc 2 fd)) ) (cdr (assoc 2 fd)) ) "\\_FldIdx 0" (cdr (assoc 2 en)) ) (cdr (assoc 2 en)) ) ) ) ); (setq oobj (vlax-ename->vla-object (setq ooe (car (entsel "\nSelect source text: "))) ) ) (setq ad (vla-get-ActiveDocument (vlax-get-acad-object))) (if (or (= (vlax-get-property oobj 'ObjectName) "AcDbMText")(= (vlax-get-property oobj 'ObjectName) "AcDbText") ) ;"AcDbMText" (progn (if (not (setq nstrg (LM:FieldCode (vlax-vla-object->ename oobj))) ) (setq nstrg (vlax-get-property oobj 'TextString)) ) ;if (setq nsextHeight (cdr (assoc 40 (entget ooe)))) (setq InsertionPoint (getpoint "\nPick first point for MLeader: ") ) (setq SecondPoint (getpoint "\nPick next point for text location: ") ) (setq PointList (vlax-make-variant (vlax-safearray-fill (safearray vlax-vbdouble '(0 . 5)) (apply 'append (list InsertionPoint SecondPoint)) ) ) ) (setq mleader (vla-addMLeader (if (= 1 (vla-get-activespace ad)) (vla-get-modelspace ad) (if (= (vla-get-mspace ad) :vlax-true) (vla-get-modelspace ad) (vla-get-paperspace ad) ) ) ;if PointList 0 ) ;vla-addmleader ) ;setq (vlax-put-property mleader 'TextString nstrg) (vlax-put-property mleader 'TextHeight nsextHeight) ;(vla-put-TextHeight dimObj 1) (vla-SetDogLegDirection mleader 0 (vlax-3D-point (list (if (< (car InsertionPoint) (car SecondPoint)) 1 -1 ) 0 0 ) ) ) (entdel (vlax-vla-object->ename oobj)) ;; (prompt "\nFIELDS require a REGEN to update the text.") (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (vla-Regen doc acAllViewports) );progn (progn (princ ;; "\nTry again with a TEXT or MTEXT entity. Press ENTER to try again." "\nTry again with a MTEXT entity. Press ENTER to try again." ) ) ) (princ) ) 1 Quote
Steven P Posted December 21 Posted December 21 Hosneyalaa had it I think. In your first code you might want to investigate what the output result of (vlax-get-property oobj 'ObjectName) is.... I don't think it is this string: "AcDbMText,AcDbText" (iin the " " it is seen as a single string and not a list) Might need an (OR ) statement in there somewhere.... Quote
rcb007 Posted December 21 Author Posted December 21 Thank you guys. @hosneyalaa. I think you are so close. I like the idea you took to extract the text. Carrying over the fields to the mleaders seemed to work. Only thing, I am trying to figure out the formatting as I try to click to the left side or the right side. Quote
christopher8642g Posted 12 hours ago Posted 12 hours ago (edited) On 12/20/2024 at 8:44 PM, rcb007 said: I found this routine which will take mtext vaules, (with fields) to a mleader. I am having a hard time trying to figure out how to get this routine to work with dtext and dtexts which have a field value to them. I thought by removing the mtext, and replacing it with a *text; that would work. However, not the case. (setq oobj (vlax-ename->vla-object (car (entsel "\nSelect source text: ")) ) ) (setq ad (vla-get-ActiveDocument (vlax-get-acad-object))) (if (= (vlax-get-property oobj 'ObjectName) "AcDbMText,AcDbText");;????? (progn (if (not (setq nstrg (LM:FieldCode (vlax-vla-object->ename oobj))) ) (setq nstrg (vlax-get-property oobj 'TextString)) ) ;if ;2023/07/31 added Lee Mac routine to carryover the Fields. ;;Added Auto Regen ;;Need method to convert text to mtext then to a mleader. (defun c:mt2ml (/ oobj nobj nstrg ad Insertionpoint secondpoint oobj nobj mleader olderr) (vl-load-com) ;Important field extraction code by Lee Mac!! (defun LM:FieldCode (en / fd id) (cond ((and (wcmatch (cdr (assoc 0 (setq en (entget en)))) "*TEXT" ) (setq en (cdr (assoc 360 en))) (setq en (dictsearch en "ACAD_FIELD")) (setq en (dictsearch (cdr (assoc -1 en)) "TEXT")) (setq fd (entget (cdr (assoc 360 en)))) ) (if (vl-string-search "\\_FldIdx " (cdr (assoc 2 en))) (vl-string-subst (if (setq id (cdr (assoc 331 fd))) (vl-string-subst (strcat "ObjId " (itoa (vla-get-objectid (vlax-ename->vla-object id))) ) "ObjIdx 0" (cdr (assoc 2 fd)) ) (cdr (assoc 2 fd)) ) "\\_FldIdx 0" (cdr (assoc 2 en)) ) (cdr (assoc 2 en)) ) ) ) ); (setq oobj (vlax-ename->vla-object (car (entsel "\nSelect source text: ")) ) ) (setq ad (vla-get-ActiveDocument (vlax-get-acad-object))) (if (= (vlax-get-property oobj 'ObjectName) "AcDbMText") (progn (if (not (setq nstrg (LM:FieldCode (vlax-vla-object->ename oobj))) ) (setq nstrg (vlax-get-property oobj 'TextString)) ) ;if (setq InsertionPoint (getpoint "\nPick first point for MLeader: ") ) (setq SecondPoint (getpoint "\nPick next point for text location: ") ) (setq PointList (vlax-make-variant (vlax-safearray-fill (safearray vlax-vbdouble '(0 . 5)) (apply 'append (list InsertionPoint SecondPoint)) ) ) ) (setq mleader (vla-addMLeader (if (= 1 (vla-get-activespace ad)) (vla-get-modelspace ad) (if (= (vla-get-mspace ad) :vlax-true) (vla-get-modelspace ad) (vla-get-paperspace ad) ) ) ;if PointList 0 ) ;vla-addmleader ) ;setq (vlax-put-property mleader 'TextString nstrg) (vla-SetDogLegDirection mleader 0 (vlax-3D-point (list (if (< (car InsertionPoint) (car SecondPoint)) 1 -1 ) 0 0 ) ) ) (entdel (vlax-vla-object->ename oobj)) ;; (prompt "\nFIELDS require a REGEN to update the text.") (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (vla-Regen doc acAllViewports) );progn (progn (princ ;; "\nTry again with a TEXT or MTEXT entity. Press ENTER to try again." "\nTry again with a MTEXT entity. Press ENTER to try again." ) ) ) (princ) ) Thank you for the help for vehiclecaraccident. Yah Edited 12 hours ago by christopher8642g 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.