- ;功能 : 设置图层的透明度
- ;参数:
- ; layername : 图层名称
- ; value : 设置值0~100的值
- ;函数:无
- ;示例:(yd-layer-transparency "0" 0)
- (defun yd-layer-transparency(layername value /
- ent Objlayer transparency data data-3
- )
- (if (and
- (<= 0 value 100)
- (tblsearch "layer" layername)
- )
- (progn
- (setq
- ent (tblobjname "layer" layername)
- Objlayer (vlax-ename->vla-object ent)
- transparency (+ (lsh 2 56) (fix (* 255(- 1 (* value 0.01) ))))
- data (entget (tblobjname "layer" layername) '("*"))
- data-3 (cdr (assoc -3 data))
- )
- (if (/= (assoc "AcCmTransparency" (cdr (assoc -3 data))) nil)
- (progn
- (setq
- data-3 (if (= value 0) (vl-remove (assoc "AcCmTransparency" data-3) data-3) (subst (list "AcCmTransparency" (cons 1071 transparency)) (assoc "AcCmTransparency" data-3) data-3))
- data (subst (cons -3 data-3) (assoc -3 data) data)
- )
- (entmod data)
- )
- (progn
- (setq
- data-3 (if (= value 0) data-3 (cons (list "AcCmTransparency" (cons 1071 transparency)) data-3))
- data (subst (cons -3 data-3) (assoc -3 data) data)
- )
- (entmod data)
- )
- )
-
- (vla-put-layeron Objlayer (vla-get-layeron Objlayer))
- ;更新图层(vla-regen (vla-get-activedocument(vlax-get-acad-object)) 1),不知道vla-regen和redraw方法哪个速度更快
- (redraw ent)
- )
- )
- (princ)
- )
|