Author Topic: Set MTEXT background fill color using VLA - RGB color  (Read 620 times)

0 Members and 1 Guest are viewing this topic.

MasterMiner

  • Mosquito
  • Posts: 6
  • Mining Engineer - English/Français
Set MTEXT background fill color using VLA - RGB color
« on: December 25, 2019, 08:11:42 AM »
Merry Christmas and Happy Holidays to all,

I have a specific use case where I am trying to set the background color of Mtext in such a way that it is white in both model and paper space. While one can set it to color 7 with the entmake, that color changes to black when switching to the paper space.

I tried to do the same thing as I did with a hatch in the same project, setting it to RGB 255, 255, 255 with ActiveX, but it seems the background fill color is either set differently or impossible to set with VLA.

My code:
Code - Auto/Visual Lisp: [Select]
  1. (defun putText (text centre / obj col ent)
  2.   (setq ent (entmakex (list
  3.              (cons 0 "MTEXT")
  4.              (cons 100 "AcDbEntity")
  5.              (cons 100 "AcDbMText")
  6.              (cons 7 "Standard")
  7.              (cons 8 (getvar "CLAYER"))
  8.              (cons 71 5)
  9.              (cons 72 5)
  10.              (cons 73 1)
  11.              (cons 10 centre)
  12.              (cons 11 (list 1.0 0.0 0.0))
  13.              (cons 50 0)
  14.              (cons 41 19.35)
  15.              (cons 40 0.75)
  16.              (cons 44 1.0)
  17.              (cons 1 text)
  18.              (cons 90 1)
  19.              (cons 62 5)
  20.              (cons 63 255)
  21.            )
  22.   ));_entmake and setq
  23.  
  24.  
  25.   (setq obj (vlax-ename->vla-object ent))
  26.   (setq col (vlax-create-object (strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2))))
  27.   (vla-setrgb col 255 255 255)
  28.   (vla-put-backgroundcolor obj col)
  29.  
  30.   (mip-mtext-wrap-BB (entlast))
  31.  
  32. );_defun
  33.  

The problem is that the vla-put-backgroundcolor command does not seem to work for MTEXT, and the color 255 shows up as a grey in paper space. Does anybody have an idea how I can achieve this?

Thank you,

MM
« Last Edit: December 25, 2019, 11:54:41 AM by MasterMiner »

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: Set MTEXT background fill color using VLA - RGB color
« Reply #1 on: December 25, 2019, 08:20:45 AM »
You could use my Background Mask program, or build your own custom program which calls the mask:maskentity function defined by the program to do the leg work for you.

The DXF group codes are essentially one more than those used for standard colour groups, i.e. 63, 421, & 431 instead of 62 (ACI), 420 (True Colour), & 430 (Colour Book).

MasterMiner

  • Mosquito
  • Posts: 6
  • Mining Engineer - English/Français
Re: Set MTEXT background fill color using VLA - RGB color
« Reply #2 on: December 25, 2019, 08:53:44 AM »
Lee,

Thanks a bunch for your response, I should have studied your example more intensely when I first looked through it. I was able to find a way to achieve what I wanted through that. A big thanks for putting all your code online as you do and responding to questions, your website is top notch with its formatting, as well. Have a great 25th!!

For all who may find this interesting, what I found interesting about the solution was the Entmake would not work with true color (421) without also using a base color (63) which is then overriden... strange. Anyways, here's my final code, I hope it can help someone else.

Code - Auto/Visual Lisp: [Select]
  1. (defun putText (text centre / ent)
  2.  
  3.   (setq ent (entmakex (list
  4.              (cons 0 "MTEXT")
  5.              (cons 100 "AcDbEntity")
  6.              (cons 100 "AcDbMText")
  7.              (cons 7 "Standard")
  8.              (cons 8 (getvar "CLAYER"))
  9.              (cons 71 5)
  10.              (cons 72 5)
  11.              (cons 73 1)
  12.              (cons 10 centre)
  13.              (cons 11 (list 1.0 0.0 0.0))
  14.              (cons 50 0)
  15.              (cons 41 19.35)
  16.              (cons 40 0.75)
  17.              (cons 44 1.0)
  18.              (cons 1 text)
  19.              (cons 62 5)
  20.              (cons 90 1)
  21.              (cons 63 7)
  22.              (cons 421 16777215)
  23.            )
  24.   ));_entmake and setq
  25.  
  26.   (mip-mtext-wrap-BB (entlast))
  27.  
  28. );_defun
  29.  
« Last Edit: December 25, 2019, 11:52:20 AM by MasterMiner »

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: Set MTEXT background fill color using VLA - RGB color
« Reply #3 on: December 25, 2019, 09:38:57 AM »
You're most welcome MasterMiner - thank you for your gratitude & positive feedback for my site, I really appreciate it.

Note that you could pass the entity name returned by entmakex directly to your mip-mtext-wrap-BB function, and quote a lot of the literal data:
Code - Auto/Visual Lisp: [Select]
  1. (defun putText ( text centre )
  2.     (mip-mtext-wrap-BB
  3.         (entmakex
  4.             (list
  5.                '(000 . "MTEXT")
  6.                '(100 . "AcDbEntity")
  7.                '(100 . "AcDbMText")
  8.                '(007 . "Standard")
  9.                 (cons 8 (getvar 'clayer))
  10.                '(071 . 5)
  11.                '(072 . 5)
  12.                '(073 . 1)
  13.                 (cons 10 centre)
  14.                '(011 1.0 0.0 0.0)
  15.                '(050 . 0)
  16.                '(041 . 19.35)
  17.                '(040 . 0.75)
  18.                '(044 . 1.0)
  19.                 (cons 1 text)
  20.                '(062 . 5)
  21.                '(090 . 1)
  22.                '(063 . 7)
  23.                '(421 . 16777215)
  24.             )
  25.         )
  26.     )
  27. )

Several of the DXF groups could also be omitted, as when omitted they will automatically default to the values that you have supplied.

MasterMiner

  • Mosquito
  • Posts: 6
  • Mining Engineer - English/Français
Re: Set MTEXT background fill color using VLA - RGB color
« Reply #4 on: December 25, 2019, 09:47:37 AM »
You do a great public service. And thanks for the reformatting, concise code is most definitely more beautiful code!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10388
Re: Set MTEXT background fill color using VLA - RGB color
« Reply #5 on: December 25, 2019, 11:30:27 AM »
You do a great public service.

I second that!  8)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: Set MTEXT background fill color using VLA - RGB color
« Reply #6 on: December 25, 2019, 03:44:08 PM »
You do a great public service.

I second that!  8)

Thank you both - that means a lot. :-)

Hope you both have a wonderful Christmas!