Hello everyone
I created a program for myself that sends tables to Excel. For me it works great.
While formatting cells in Excel, I wanted to have fun with colors and I found out how to color the cell contents with basic VBA colors [(vlax-put (vlax-get cell 'Font) 'ColorIndex NoColor)).]
https://learn.microsoft.com/en-us/office/vba/api/excel.colorindex
However, this color set is incompatible with autocad colors and I wanted to switch to the RGB color set.
I think, I can use:
a) (vlax-put (vlax-get cell 'Font) 'RGB ???)
or
b) (vlax-put (vlax-get cell 'Font) 'Interior.Color ???)
but unfortunately I don't know what to put instead ??? - my English is insufficient.
Maybe one of you knows how to do it.
Jerzy
Solved! Go to Solution.
Solved by MunteanStefan. Go to Solution.
@jerzy.bajor wrote:However, this color set is incompatible with autocad colors and I wanted to switch to the RGB color set.
Have a look here --> Colour Conversion Functions : Lee Mac and let us know how it goes.
What is shown there are activities within AutoCAD. I'm talking about changing the color to RGB in an Excel cell.
Jerzy
@jerzy.bajor wrote:
I created a program for myself that sends tables to Excel. For me it works great.
Are you running this program in AutoCAD?
Just so you know, RGB codes are universal. You can pass the value to your program as an argument for the color assignment.
I don't want to change the standard color to RGB in AutoCAD, but give the cell an RGB color from AutoCAD/Lisp
@jerzy.bajor wrote:
I don't want to change the standard color to RGB in AutoCAD, but give the cell an RGB color from AutoCAD/Lisp
Are you running this program in AutoCAD/lisp?
Yes. I collect information about tables contained in a dwg file and export them to Excel.
@jerzy.bajor wrote:
Yes. I collect information about tables contained in a dwg file and export them to Excel.
@jerzy.bajor wrote:
...but unfortunately I don't know what to put instead ??
Post your code then. we will fil in the blanks for you.
The program works as you can see in the attachment.
I have the text colors of each cell.
With the help of (vlax-put (vlax-get cell 'Font) 'ColorIndex NoColor)), where NoColor is the color number according to VBA, gives the cell a color.
The problem is that VBA has 56 colors and Autocad has 256 colors.
I know how to switch from AutoCAD color to RGB. I just don't know how to transfer this color to Excel.
RGB is in general represented by 3 bytes, but some applications use them in reverse order.
This function will change the color of the interior of a cell in the specified RGB values.
(defun set_cell_RGB (cell r g b / interior)
(if
(setq interior (vlax-get-property cell "Interior"))
(vlax-put-property
interior
"color"
(apply 'logior
(mapcar 'lsh
(list r g b)
(list 0 8 16)
)
)
)
)
)
The same transformation can be used to apply a color in Autocad, but one of the last 2 lists must be reversed.
For example, for R=80, G=208, B=146, there are the color codes in Excel and Autocad
_$ (apply 'logior (mapcar 'lsh '(80 208 146) '(0 8 16)))
9621584 - Excel color
_$ (apply 'logior (mapcar 'lsh '(80 208 146) '(16 8 0)))
5296274 - AutoCAD color
_$
@jerzy.bajor wrote:
The program works as you can see in the attachment.
Neat program you have there. .NET? or Lisp?
@jerzy.bajor wrote:The problem is that VBA has 56 colors and Autocad has 256 colors.
And of this 56 colors does not even match the color index number in AutoCAD
Are these colors will always be the same?
Are you saying you CAN assign a color using an index number but no luck with an RGB color? or not even with an index number?
It would be interesting to write this in Vlisp alone but i think its doable. I'll investigate further.
@MunteanStefan wrote:_$ (apply 'logior (mapcar 'lsh '(80 208 146) '(0 8 16))) 9621584 - Excel color _$ (apply 'logior (mapcar 'lsh '(80 208 146) '(16 8 0))) 5296274 - AutoCAD color _$
Well there you go 👍
Program written in Vlips.
I can color the text in the cell, but only the color of the text in VBA.
This is great. However, I wanted to change color the contents of the cell, not the cell itself.
Jerzy
@jerzy.bajor wrote:This is great. However, I wanted to change color the contents of the cell, not the cell itself.
Jerzy
Change "Interior" with "Font". Or better, create a new function just for "Font" property of a cell.
Can't find what you're looking for? Ask the community or share your knowledge.