找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 554|回复: 0

[他山之石] 使用Visual Lisp 修改 TrueColor 特性

[复制链接]
发表于 2013-5-27 07:47:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
Accessing the TrueColor property using Visual LISP                                                        By Philippe Leefsma
  Q:
  How to access the TrueColor property of an entity in AutoCAD? Also, is there a way to set an object's color back to "ByLayer"?
  
  A:
  First, it is necessary to access the object's TrueColor property, using vlax-get-property.  The RGB (Red, Green and Blue) values of TrueColor are read-only, so you can not individually modify them.  You must invoke the SetRGB method and set all three values at once.  Then, using vlax-put-property, you can set the object's TrueColor property to reflect the new RGB values.  You will notice that an object whose color is "ByLayer" returns RGB values of R=0, G=0, B=0.  However, setting these values explicitly, with SetRGB, will not restore the color to "ByLayer".  To reset the color to "ByLayer", it is necessary to set TrueColor's ColorIndex property to acBylayer.  The example below creates a line, whose color is initially "ByLayer".  We then change it to blue, and finally back to ByLayer:
  1. (defun c:TestTrueClr()
  2.    (vl-load-com)
  3.    (setq oApp (vlax-get-Acad-Object)
  4.            oDoc (vla-get-ActiveDocument oApp)
  5.            oMSp (vla-get-ModelSpace oDoc)
  6.    )
  7.    ;; Add a Line
  8.    (setq oLine (vla-AddLine oMSp  (vlax-3d-point '(1.0 1.0 0.0))  (vlax-3d-point '(10.0 10.0 0.0))))
  9.     (vla-update oLine)

  10.    ;; Get the current color values
  11.    (setq oColor (vlax-get-property oLine 'TrueColor)
  12.            clrR (vlax-get-property oColor 'Red)
  13.            clrG (vlax-get-property oColor 'Green)
  14.            clrB (vlax-get-property oColor 'Blue)
  15.    )
  16.    (alert (strcat "Old Color - Red: " (itoa clrR) " Green: " (itoa clrG) " Blue: " (itoa clrB)))

  17.    ;; Set TrueColor to blue (R=0, G=101, B=204)
  18.    (vlax-invoke-method oColor 'SetRGB 0 101 204)
  19.    (vlax-put-property oLine 'TrueColor oColor)
  20.    (vla-update oLine)

  21.    ;; Inspect the new color values
  22.    (setq oColor (vlax-get-property oLine 'TrueColor)
  23.            clrR (vlax-get-property oColor 'Red)
  24.            clrG (vlax-get-property oColor 'Green)
  25.            clrB (vlax-get-property oColor 'Blue)
  26.    )
  27.    (alert (strcat "New Color - Red: " (itoa clrR) " Green: " (itoa clrG) " Blue: " (itoa clrB)))
  28.   
  29.    ;; Reset color to acBylayer
  30.    (vlax-put-property oColor 'ColorIndex acByLayer)
  31.    (vlax-put-property oLine 'TrueColor oColor)
  32.    (vla-update oLine)

  33.    ;; Inspect the color values
  34.    (setq oColor (vlax-get-property oLine 'TrueColor)
  35.            clrR (vlax-get-property oColor 'Red)
  36.            clrG (vlax-get-property oColor 'Green)
  37.            clrB (vlax-get-property oColor 'Blue)
  38.    )
  39.    (alert (strcat "New Color - Red: " (itoa clrR) " Green: " (itoa clrG) " Blue: " (itoa clrB)))
  40. )


评分

参与人数 1D豆 +3 收起 理由
xshrimp + 3 很给力!经验;技术要点;资料分享奖!

查看全部评分

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-25 14:33 , Processed in 0.318578 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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