TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: XXL66 on October 28, 2015, 04:40:18 AM
-
hello,
i have colors in an XML file in hexadecimal format
f.e.
"0xFF00A0"
"0x000000"
"0x20FF00"
is it possible to translate these into an autocad color ?
thanks !
-
(defun hex2true ($ / )
(LM:RGB->True (HexadecimalToInteger (substr $ 3 2)) (HexadecimalToInteger (substr $ 5 2)) (HexadecimalToInteger (substr $ 7 2)))
)
(defun LM:RGB->True ( r g b )
(logior (lsh (fix r) 16) (lsh (fix g) 8) (fix b))
)
(defun HexadecimalToInteger (strHexadecimal / intInteger intAscii)
(setq intInteger 0)
(foreach intAscii (vl-string->list (strcase strHexadecimal))
(setq intInteger (+ (lsh intInteger 4)
(- intAscii
(if (<= intAscii 57) 48 55)
)
)
)
)
)
i think i'm close, but lines that are purple become blue, something must be wrong...
i think i'm close, but lines that are purple become blue, something must be wrong...
-
I see nothing wrong with the code, and in my testing the following will create a line with colour 255,0,160 as expected:
_$ (entmake (list '(0 . "LINE") '(10 0 0 0) '(11 1 0 0) (cons 420 (hex2true "0xFF00A0"))))
((0 . "LINE") (10 0 0 0) (11 1 0 0) (420 . 16711840))
-
hi thx
indeed, but i use polylines. It seems bcad adds the 62 dxf group code also with my entmake (header + vertices)... i think 62 is used instead of dxf 420...
any idea what i'm doing wrong ?
ty !
-
The presence of gc 62 is to be expected for elements with a true color.
Perhaps you are also supplying gc 62 in your code? It is best to leave it out.
If both gc 62 and 420 are present in the entmake list the last entry takes precedence.
True color rejected:
'(
(0 . "LWPOLYLINE")
(8 . "0")
(420 . 16711840)
(62 . 16711840)
...
)
)
True color accepted:
'(
(0 . "LWPOLYLINE")
(8 . "0")
(62 . 16711840)
(420 . 16711840)
...
)
)
-
hi roy,
I do not supply 62. i didn't notice that 62 was also added to a 'simple' line.
I tried changing into BGR instead of RGB also but it still isn't correct.
It seems there is a bug in the software i import the data from, the color on the screen does not match the output. So it is someone elses problem now ;-)
thanks you guys !
-
is there a color code for BYLAYER for DXF group code 420 ?
when i select an object it shows 62 192 192 in true color, however when adding this value this doesn't result in bylayer.
i have to use 256 in code dxf group 62 ?
-
i have to use 256 in code dxf group 62 ?
I would suggest this, yes.
-
ok thx !