Changing Mtext background in Mleader via dxf code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
(defun c:MLeaderMasked nil (command-s "_.MLEADER") (setpropertyvalue (entlast) "MText/BackgroundFill" 1) (princ) )
I have the above property value change "entlast" tagged at the end of a Mleader automation LISP that works perfectly in AutoCAD environments.
Unfortunately there are a number of users on my network that are using no-AD products.
I've been trying, mightily, to access the dxf codes for the Mtext in the Mleader and change it to on "1".
I can see the dxf code under CONTEXT_DATA (I think) but I cant seem to access this directly. In the context_data section "292" is the .dxf code for Mtext background 0/1, but if I use the naked "292" in e.g.
(PROGN
(setq EDATA (entget e))
(SETQ OLDTHING (ASSOC 292 EDATA))
(SETQ NEWTHING 1)
(PROGN
(SETQ EDATA (SUBST (CONS 292 NEWTHING) (ASSOC 292 OLDTHING) EDATA))
(ENTMOD EDATA)
)
)
(defun c:ChangeMtextDxf ( / mleaderObj mtextObj dxfList txtCode replacementCode newDxfString )
;; Prompt user to select the Mleader object
(setq mleaderObj (vlax-ename->vla-object (car (entsel "\nSelect Mleader: "))))
;; Get the Mtext object from the Mleader
(if (vlax-property-available-p mleaderObj 'GetMtext) ; Check if the Mtext property exists
(progn
(setq mtextObj (vla-GetMtext mleaderObj))
(setq dxfList (entget (vlax-vla-object->ename mtextObj)))
;; Find the DXF code for the text content (e.g., code 1)
;; Assuming the Mtext content is in a DXF code 1 or similar
;; You may need to adjust this based on the Mleader's specific DXF structure
(setq txtCode (assoc 292 dxfList))
(if txtCode
(progn
;; Define the DXF code to be replaced and its replacement
(setq replacementCode (strcat "0" " " "1")) ; Placeholder for actual codes
;; Modify the text string to replace the DXF codes
(setq newDxfString (vl-string-subst 1 txtCode (cdr txtCode))) ; Replace placeholder
;; Create the updated DXF list
(setq newDxfString (list (cons 292 newDxfString))) ; Update the text string for DXF code 292
(setq dxfList (append (vl-remove txtCode dxfList) newDxfString)) ; Replace the old code with the new
;; Update the Mtext entity
(entmod dxfList)
)
(princ "\nMtext content not found.")
)
)
(princ "\nSelected object is not a valid Mleader or does not have Mtext content.")
)
(princ)
)
but there's definitions for variables that aren't used and it keeps kicking me a nope error message, so not sure if the code is even close.
Is there a way to set the Mtext dxf code to "on" via LISP or am I in a dead end?
Apparently remembering to Qselect all Mleaders and turn on the background mask is the worst thing in the world 😕
TY in advance