Changing Mtext background in Mleader via dxf code

Changing Mtext background in Mleader via dxf code

opadraftingsolutions
Participant Participant
37 Views
3 Replies
Message 1 of 4

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
38 Views
3 Replies
Replies (3)
Message 2 of 4

Moshe-A
Mentor
Mentor

@opadraftingsolutions hi,

 

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

 

enjoy

Moshe

0 Likes
Message 3 of 4

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 4

В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