明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1582|回复: 4

[求助]如何取真彩色的数值?

[复制链接]
发表于 2009-4-21 07:27:00 | 显示全部楼层 |阅读模式

如下图所示,如何取真彩色的数值?又如何进行反操作?!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2009-4-21 16:24:00 | 显示全部楼层
[Post=10]一个图元的dxf表中的420是truecolor 数值,
  1. ;;;===============
  2. ;;;把truecolordlg
  3. ;;;420构成的数值返
  4. ;;;回RGB列表.     
  5. ;;;===============
  6. (defun Number->RGB (C)
  7.   (list (lsh C -16)
  8.         (lsh (lsh C 16) -24)
  9.         (lsh (lsh C 24) -24)
  10.   )
  11. )
  12. ;;;逆转换
  13. (defun RGB->Number (lst)
  14.   (+ (lsh (car lst) 16) (lsh (cadr lst) 8) (caddr lst))
  15. )
  16. ;;;===============
  17. ;;;RGB转化成索引号
  18. ;;;===============
  19. (defun RGB->Index (colRGB / acadver colorObj)
  20.   (vl-load-com)
  21.   (setq acadver (getvar "acadver"))
  22.   (setq acadver (strcat "AutoCAD.AcCmColor." (substr acadver 1 2)))
  23.   (setq colorObj (vla-getinterfaceobject (vlax-get-acad-object) acadver))
  24.   (vla-setRGB colorobj (car colRGB) (cadr colRGB) (caddr colRGB))
  25.   (vla-get-ColorIndex colorobj)
  26. )
  27. ;;;===============
  28. ;;;索引号转化成RGB
  29. ;;;===============
  30. (defun Index->RGB (ci / acadver colorObj)
  31.   (vl-load-com)
  32.   (setq acadver (getvar "acadver"))
  33.   (setq acadver (strcat "AutoCAD.AcCmColor." (substr acadver 1 2)))
  34.   (setq colorObj (vla-getinterfaceobject (vlax-get-acad-object) acadver))
  35.   (vla-put-ColorIndex  colorobj ci)
  36.   (list (vla-get-red   colorobj)
  37.         (vla-get-green colorobj)
  38.         (vla-get-blue  colorobj)
  39.   )
  40. )
另外autodesk公司提供了样例函数,你不妨参考它。
X:\Program Files\AutoCAD 2006\Sample\VisualLISP\color-util.lsp
[/Post]
 楼主| 发表于 2009-4-21 21:39:00 | 显示全部楼层

谢谢! highflybir

highflybir,以下返回值有偏差,有没有办法返回真正的值?!

;--------------------------------------

(Index->RGB (cdr (assoc 62 (tblsearch "layer" "COL-T3"))))

返回:(47 76 38)   实际值:(49 75 38)

(Index->RGB (cdr (assoc 62 (tblsearch "layer" "COL-T1"))))

返回:(255 127 0)   实际值:(255 121 0)

发表于 2009-4-22 09:45:00 | 显示全部楼层
回复: 我的方法实际上也是autodesk的方法,我以前也发现了这样的偏差问题,在某些数值上有偏差,但很接近,在颜色上很难分别出来。
如果楼主有空,不妨把这个bug在autodesk论坛上贴出来。
下面是color-util.lsp的方法,可以看出我的方法就是它的方法。
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;; TrueColor-split - takes a TrueColor number and returns a list of integers the form '(red green blue)
  3. ;;
  4. (defun TrueColor-split ( c / )
  5. (list (lsh (fix c) -16)
  6.        (lsh (lsh (fix c) 16) -24)
  7.        (lsh (lsh (fix c) 24) -24)
  8. )
  9. );defun TrueColor-split
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11. ;; TrueColor-make - takes TrueColor components (red green blue) and creates a single TrueColor integer
  12. ;;
  13. (defun TrueColor-make ( r g b /  )
  14. (+ (lsh (fix r) 16)
  15.     (lsh (fix g) 8)
  16.     (fix b)
  17. )
  18. );defun TrueColor-make
 楼主| 发表于 2009-4-22 19:02:00 | 显示全部楼层

存在这样的BUG, 有点遗憾!有空我在贴贴吧!

谢谢!

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-2-25 09:00 , Processed in 0.744293 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表