Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, the following code converts text objects to Mleaders, however after each execution, it returns the following line " Select source text: Unknown command "\" " and shows the mleader text as "\". selecting the created Mleader afterwards fixes it. Can anyone help troubleshoot please:
(defun c:t2ml ( / oobj nobj nstrg oheight tScale overallScale oWidth)
(vl-load-com) ; Load the Visual LISP extensions
(setq oobj (vlax-ename->vla-object (car (nentsel "\nSelect source text: "))))
(cond
((= (vlax-get-property oobj 'ObjectName) "AcDbMText") ; Check if it's MText
(setq nstrg (vlax-get-property oobj 'TextString))
(setq oheight (vlax-get-property oobj 'Height)) ; Get the text height
(setq oWidth (vlax-get-property oobj 'Width)) ; Get the text width from MText
)
((= (vlax-get-property oobj 'ObjectName) "AcDbText") ; Check if it's DText
(setq nstrg (vlax-get-property oobj 'TextString))
(setq oheight (vlax-get-property oobj 'Height)) ; Get the text height
; For DText, width is not applicable as DText is a single line of text, hence no width property
)
(t
(exit) ; Exit if it's neither MText nor DText
)
)
(command "_MLEADER") ; Start MLEADER command
(while (= 1 (logand (getvar "CMDACTIVE") 1)) (command PAUSE)) ; Wait for MLEADER command to finish
(setq nobj (vlax-ename->vla-object (entlast))) ; Get the last created entity, which should be the MLeader
(if (= (vlax-get-property nobj 'ObjectName) "AcDbMLeader") ; Check if it's MLeader
(progn
(setq tScale (vlax-get-property nobj 'TextHeight)) ; Get the text height of MLeader
(setq overallScale (/ oheight tScale)) ; Compute the overall scale based on height
(vla-put-ScaleFactor nobj overallScale) ; Set the overall scale of MLeader
(vla-put-TextWidth nobj oWidth) ; Set the width of the MLeader to match MText's width
(vlax-put-property nobj 'TextString nstrg) ; Set the text of MLeader
)
)
(entdel (vlax-vla-object->ename oobj)) ; Delete the original text object
(princ) ; Clean exit
)
Solved! Go to Solution.