Adding a background mask to mleader routine

Adding a background mask to mleader routine

robw
Advocate Advocate
2,771 Views
18 Replies
Message 1 of 19

Adding a background mask to mleader routine

robw
Advocate
Advocate

Hi, I've made a simple routine that draws a multileader on a layer.


What I don't know how to do is add a background mask to it.

I'd also like to be able to create different variations of the routine to change the background color and text frame size.

 

What I have so far:


(defun c:mleaderA1 (/)
  (command "-layer" "m" "TEXT-LEADERS" "c" "t" "0,0,0" "" "" "cmleaderstyle" "Standard")
  (command ".mleader")
)

 

I know - good eh...? lol

 

Any ideas?

 

Thanks

 

0 Likes
2,772 Views
18 Replies
Replies (18)
Message 2 of 19

ВeekeeCZ
Consultant
Consultant

 

; for AutoCAD 2016+

(defun c:MleaderA1 ( / m l e)

  (setq m (getvar 'cmleaderstyle)
	l (getvar 'clayer))
  (setvar 'cmleaderstyle "STANDARD")
  (command "_.-LAYER" "_T" "TEXT-LEADERS" "_M" "TEXT-LEADERS" "_C" "_T" "0,0,0" "" "")

  (setq e (entlast))
  (command-s "_.MLEADER")
  (if (not (equal e (setq e (entlast))))
    (setpropertyvalue e "MText/BackgroundFill" 1))

  (setvar 'cmleaderstyle m)
  (setvar 'clayer l)
  (princ)
  )

 

0 Likes
Message 3 of 19

robw
Advocate
Advocate

Hey, thanks for this.

 

Is there any way to set the color as well?

0 Likes
Message 4 of 19

ВeekeeCZ
Consultant
Consultant

Color of what? A background?

Post a dwg with example.

0 Likes
Message 5 of 19

ronjonp
Mentor
Mentor

Try THIS.

0 Likes
Message 6 of 19

robw
Advocate
Advocate

Very good - thanks.
I'll give it a go

0 Likes
Message 7 of 19

robw
Advocate
Advocate

Overall vision: 

Click on custom button on my ribbon. It starts the multileader object.

I choose the point of the arrow first, then where to place the text.

I enter my text, hit return to finish.

The routine automatically adds a text background mask, with a fill color and border offset specified within the routine.

Hey presto finished mutlileader.

 

Reason being I  wanted different routines for different text styles and sizes, so I'd need to be able to adjust them.

 

Thanks again

0 Likes
Message 8 of 19

robw
Advocate
Advocate

Hi, something like the attached.

Thanks

0 Likes
Message 9 of 19

ВeekeeCZ
Consultant
Consultant

Well, just you to know, setting a color to mleader, a TrueColor specifically, is not so a simple task.

And I really don't want to play with this so much... so I used some portions of the Lees code.

 

When you will do a clones, use the Lees routine to get the setting of color! Read the note. Watch the format... add an apostrophe!

 

(vl-load-com)
; for AutoCAD 2016+


(defun c:MleaderA1 ( / m l e mask:main mask:maskentity mask:substonce)
  
  
  ;; from "\n:: Mask.lsp | Version 1.5 | (c) Lee Mac "
  
  (defun mask:main ( ent msk off trn col )
    (mask:maskentity ent (= "1" msk) off (= "1" trn) col))
  
  ;;----------------------------------------------------------------------;;
  
  (defun mask:maskentity ( ent msk off trn col / enx )
    (setq enx (entget ent))
    (entmod (mask:substonce enx (if msk
				  (list (cons 091 (mask:color->mleadercolor (if trn '((62 . 256)) col)))
					(cons 141 off)
					(if trn '(291 . 1) '(291 . 0))
					'(292 . 1)
					)
				  '((292 . 0)))))
    (vla-put-textlinespacingfactor (vlax-ename->vla-object ent) (cdr (assoc 045 enx)))) ;; AutoCAD bug
  
  ;;----------------------------------------------------------------------;;
  
  (defun mask:substonce ( enx lst )
    (mapcar
      '(lambda ( dxf / itm )
	 (cond ((setq itm (assoc (car dxf) lst))
		(setq lst (vl-remove itm lst))
		itm)
	       (dxf)))
      enx))
  
  
  ; ----------------------------------------------------------------------------
  ; BeekeeCZ
  
  (setq m (getvar 'cmleaderstyle)
	l (getvar 'clayer))
  (setvar 'cmleaderstyle "STANDARD")
  (command "_.-LAYER" "_T" "TEXT-LEADERS" "_M" "TEXT-LEADERS" "_C" "_T" "0,0,0" "" "")
  
  (setq e (entlast))
  (command-s "MLEADER")
  (if (not (equal e (setq e (entlast))))
    (mask:main e "1" 1.6 "0" '((62 . 160) (420 . 19455))))      ; <---- to get this line run Lee's routine where 
  								; add this line: (print (cons sel tmp))    prior to this line (apply 'mask:main (cons sel tmp))
  (setvar 'cmleaderstyle m)
  (setvar 'clayer l)
  (princ)
  )

 

 
0 Likes
Message 10 of 19

robw
Advocate
Advocate

Ok, the good ship Lisp has sailed well beyond my understanding horizon. 

I had hoped it would be fairly straight forward. I certainly didn't want anyone spending too long helping me. 

Maybe I'll just carry on matching properties to an existing mleader.

 

Thanks for your efforts/time.

 

0 Likes
Message 11 of 19

ronjonp
Mentor
Mentor

Your sample drawing already has different mleader styles in it. Why does this not work for you?

 

All you need to do is set the correct CMLEADERSTYLE variable before starting the mleader command.

0 Likes
Message 12 of 19

ВeekeeCZ
Consultant
Consultant

Can be a background color (mask) part of style? 

0 Likes
Message 13 of 19

ВeekeeCZ
Consultant
Consultant

@robw wrote:

...

Maybe I'll just carry on matching properties to an existing mleader.

...

 


 

Don't you dare! At least don't tell me.

Message 14 of 19

robw
Advocate
Advocate

I wanted each mleader style on a button on a custom ribbon, so when I install the ribbon on someone else's AutoCAD they don't have to do multiple steps to get the mleader to look correct. They just press the 'Woodland' mleader button and off they go.

0 Likes
Message 15 of 19

ronjonp
Mentor
Mentor

@ВeekeeCZ wrote:

Can be a background color (mask) part of style? 


I thought so .. but after checking nope! 🤓

0 Likes
Message 16 of 19

robw
Advocate
Advocate

Yeah, there's nothing about it inside the mleader dialog.

To me, it's more of a mtext function.

0 Likes
Message 17 of 19

ВeekeeCZ
Consultant
Consultant

Here's version formatted a bit differently... to make clones easier. You still need to run Lee's routine when setting the color number.

 

 

(vl-load-com)
; for AutoCAD 2016+

;                     	 		style 	  layer         laycolor    mask offset color-index color-number  
(defun c:MLeaderA1 () (MleaderCustom "STANDARD" "TEXT-LEADERS"   "0,0,0"    T	1.6	160		19455)		(princ))
(defun c:MLeaderA2 () (MleaderCustom "woodland" "MLEDER WOODLAND" "1,150,0" nil 1.6	160		19455)		(princ))



; <---- to get last color number  run Lee's routine where
; add this line: (print (cons sel tmp))    prior to this line (apply 'mask:main (cons sel tmp))

(defun MleaderCustom (stl lay lct mas ofs mci mcn / m l e mask:main mask:maskentity mask:substonce)
  
  
  ;; from "\n:: Mask.lsp | Version 1.5 | (c) Lee Mac "
  
  (defun mask:main ( ent msk off trn col )
    (mask:maskentity ent (= "1" msk) off (= "1" trn) col))
  
  ;;----------------------------------------------------------------------;;
  
  (defun mask:maskentity ( ent msk off trn col / enx )
    (setq enx (entget ent))
    (entmod (mask:substonce enx (if msk
				  (list (cons 091 (mask:color->mleadercolor (if trn '((62 . 256)) col)))
					(cons 141 off)
					(if trn '(291 . 1) '(291 . 0))
					'(292 . 1)
					)
				  '((292 . 0)))))
    (vla-put-textlinespacingfactor (vlax-ename->vla-object ent) (cdr (assoc 045 enx)))) ;; AutoCAD bug
  
  ;;----------------------------------------------------------------------;;
  
  (defun mask:substonce ( enx lst )
    (mapcar
      '(lambda ( dxf / itm )
	 (cond ((setq itm (assoc (car dxf) lst))
		(setq lst (vl-remove itm lst))
		itm)
	       (dxf)))
      enx))
  
  
  ; ----------------------------------------------------------------------------
  ; BeekeeCZ
  
  (setq m (getvar 'cmleaderstyle)
	l (getvar 'clayer))
  (setvar 'cmleaderstyle stl)
  (setvar 'cmdecho 0)
  (command "_.-LAYER" "_T" lay "_M" lay "_C" "_T" lct "" "")
  (setvar 'cmdecho 1)
  
  (setq e (entlast))
  (command-s "MLEADER")
  (if (not (equal e (setq e (entlast))))
    (mask:main e T ofs nil (list (cons 62 mci) (cons 420 mcn))))     
  (setvar 'cmleaderstyle m)
  (setvar 'clayer l)
  (princ)
  )
0 Likes
Message 18 of 19

ВeekeeCZ
Consultant
Consultant

@ronjonp wrote:

@ВeekeeCZ wrote:

Can be a background color (mask) part of style? 


I thought so .. but after checking nope! 🤓


Well, I thought that the mask setting is just on/off for mleaders. Did not know that color setting is buried somewhere in mtext ribbon. We all learn.

0 Likes
Message 19 of 19

ronjonp
Mentor
Mentor

Maybe try this to quickly set the current mleader style:

 

(defun c:foo (/ ml)
  ;; RJP » 2020-10-08
  ;; Set current mleaderstyle
  (if (setq ml (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE"))
    (progn (setq ml (mapcar 'cdr (vl-remove-if '(lambda (x) (/= 3 (car x))) ml)))
	   (or *glbl* (setq *glbl* (car ml)))
	   (setq ml (mapcar '(lambda (x) (strcat (vl-string-translate " " "+" x) " ")) ml))
	   (initget 0 (apply 'strcat ml))
	   (setq
	     *glbl* (cond ((getkword (strcat "\n["
					     (apply 'strcat (mapcar '(lambda (x) (strcat x "/")) ml))
					     "]: <"
					     *glbl*
					     ">: "
				     )
			   )
			  )
			  (*glbl*)
		    )
	   )
	   (setvar 'cmleaderstyle (vl-string-translate "+" " " *glbl*))
    )
  )
  (princ)
)

ronjonp_0-1602187326598.png

 

 

0 Likes