Changing Mtext background in Mleader via dxf code

Changing Mtext background in Mleader via dxf code

opadraftingsolutions
Participant Participant
64 Views
5 Replies
Message 1 of 6

Changing Mtext background in Mleader via dxf code

opadraftingsolutions
Participant
Participant
(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)
)
 )
 
I think I can only access the Mleader dxf code and when I use the above a weirdly defined text frame appears, which I believe is code 292 for the Mleader not the Mleader Mtext section "Enable Frame Text" code.
 
In desperation I got this from AI:
 
(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

 

 

0 Likes
65 Views
5 Replies
Replies (5)
Message 2 of 6

Moshe-A
Mentor
Mentor

@opadraftingsolutions hi,

 

You can get some ideas from >> Lee Mac MaskV1-5.lsp << 

 

enjoy

Moshe

0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant

You may need to work with multiple DXF code values.  From the DXF Reference's MLeader Context Data Group Codes page:

Kent1Cooper_0-1759407816333.png

 

Kent Cooper, AIA
0 Likes
Message 4 of 6

ВeekeeCZ
Consultant
Consultant

I have no experience with clones, but... MULTILEADERs are fairly new entities. I'm not sure if they were added before or after the split. In other words, each clone may require a different approach.

0 Likes
Message 5 of 6

AdammReilly
Collaborator
Collaborator

Part of your underlying issue might also be in this code: 

(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)
)
 )

 

During your (SETQ OLDTHING (ASSOC 292 EDATA)) you are storing the entire list associated to the 292 code, that variable will end up being the value of "(292 . 1)" then you are trying to substitute that by using (ASSOC 292 OLDTHING) again. You should just use (ASSOC 292 EDATA) in the SUBST line because you're not going to find "(292 . 1)" as the dxf code.

You're essentially doing this (and probably getting an error similar to):

(assoc 292 (assoc 292 (entget (car (entsel)))))
Select object: ; error: bad association list: (292 . 0.0)

 

Adam Reilly

Civil 3D 2026
Creator A16 AI+ A3HVFG
Windows 11 Pro
AMD Ryzen AI 9 365 w/ Radeon 880M
LinkedIn


Group Leader badge

Austin CADD User Group

LinkedIn | Discord


Please select the Accept as Solution button if my post solves your issue or answers your question.
0 Likes
Message 6 of 6

komondormrex
Mentor
Mentor

to switch on/off mleader text mask only. 

(defun c:mleader_mask_on_off (/ mld_dxf 1_2_dxf 2_2_dxf)
  (setq mld_dxf (entget (car (entsel "\nPick Mleader: "))))
  (setq 1_2_dxf (member '(302 . "LEADER{") (reverse mld_dxf)))
  (setq 1_2_dxf (reverse (cdr 1_2_dxf)))
  (setq 2_2_dxf (member '(302 . "LEADER{") mld_dxf))
  (entmod (setq mld_dxf (append (subst (cons 292 (if (zerop (cdr (assoc 292 1_2_dxf))) 1 0)) (assoc 292 1_2_dxf) 1_2_dxf) 2_2_dxf)))
  (if (equal '(141 . 0.0) (assoc 141 mld_dxf)) (entmod (subst '(141 . 1.5) '(141 . 0.0) mld_dxf)))
  (princ)
)

 

0 Likes