本帖最后由 njcknfy 于 2023-7-10 15:24 编辑
分享个如何获取对象RGB颜色列表和给对象添加RGB颜色的LISP方法
以下是获取对象的RGB颜色列表
- (defun Get_TXSTRGBCOLOR (TXST_NAME)
- ;;;获取对象的RGB颜色列表
- ;;;(Get_TXSTRGBCOLOR TXST_NAME)
- ;;;参数: TXST_NAME 对象是 ENAME 或者 VLA-OBJECT
- ;;;(setq TXST_NAME(car(entsel)))
- (cond ((= (type TXST_NAME) 'VLA-OBJECT)
- (progn (setq TXST_OBJ TXST_NAME
- oColor (vlax-get-property TXST_OBJ 'TrueColor)
- clrR (vlax-get-property oColor 'Red)
- clrG (vlax-get-property oColor 'Green)
- clrB (vlax-get-property oColor 'Blue))
- (setq TXSTRGB_LIST (list clrR clrG clrB))))
- ((= (type TXST_NAME) 'ENAME)
- (progn (setq TXST_OBJ (vlax-ename->vla-object TXST_NAME))
- (setq oColor (vlax-get-property TXST_OBJ 'TrueColor)
- clrR (vlax-get-property oColor 'Red)
- clrG (vlax-get-property oColor 'Green)
- clrB (vlax-get-property oColor 'Blue))
- (setq TXSTRGB_LIST (list clrR clrG clrB))))
- (t (setq TXSTRGB_LIST nil)))
- TXSTRGB_LIST)
以下是给对象添加RGB颜色列表的方法
- (defun Put_TXSTRGBCOLOR (TXST_NAME TXSTRGB_LIST)
- ;;;修改对象RGB颜色值
- ;;;(Put_TXSTRGBCOLOR TXST_NAME TXSTRGB_LIST)
- ;;;参数: TXST_NAME-对象是 ENAME 或者 VLA-OBJECT, TXSTRGB_LIST-对象实体的RGB颜色列表(R G B)
- ;;;(setq TXST_NAME(car(entsel)) TXSTRGB_LIST (list 140 30 252))
- (cond ((= (type TXST_NAME) 'VLA-OBJECT)
- (progn (setq TXST_OBJ TXST_NAME
- oColor (vlax-get-property TXST_OBJ 'TrueColor))
- (vlax-invoke-method oColor
- 'SetRGB
- (car TXSTRGB_LIST)
- (cadr TXSTRGB_LIST)
- (caddr TXSTRGB_LIST))
- (vlax-put-property TXST_OBJ 'TrueColor oColor)
- (vla-update TXST_OBJ)))
- ((= (type TXST_NAME) 'ENAME)
- (progn (setq TXST_OBJ (vlax-ename->vla-object TXST_NAME))
- (setq oColor (vlax-get-property TXST_OBJ 'TrueColor))
- (vlax-invoke-method oColor
- 'SetRGB
- (car TXSTRGB_LIST)
- (cadr TXSTRGB_LIST)
- (caddr TXSTRGB_LIST))
- (vlax-put-property TXST_OBJ 'TrueColor oColor)
- (vla-update TXST_OBJ)
- (setq TXST_NAME (vlax-vla-object->ename TXST_OBJ))))
- (t TXST_NAME))
- TXST_NAME)
|