zhuquanmao 发表于 2014-10-18 16:41:12

【请问怎么获取图中各图层的状态】

请问怎么获取图中各图层的状态。
比如我获取图中各图层的状态,然后把状态保存。再把所有图层全部解锁或打开,然后再执行某个命令后,再把图层恢复到之前的状态。

zzyong00 发表于 2014-10-18 17:15:15

你这说的都autocad基本功能呀

zhuquanmao 发表于 2014-10-22 19:34:43

zzyong00 发表于 2014-10-18 17:15 static/image/common/back.gif
你这说的都autocad基本功能呀

啥意思?
我是想把状态保存到一个参数里而不只是显示出来哟

Gu_xl 发表于 2014-10-22 20:11:08

提供两个图层状态存储和恢复的函数如下:
;;By 明经通道 Gu_xl
;;(gxl-layer-Save name Mask) 保存图层状态,成功返回T,否则返回nil
;|
name 图层状态的名称
Mask 参数值如下:
acLsAll All layer properties
acLsColor Color
acLsFrozen Frozen or thawed
acLsLineType Linetype
acLsLineWeight Lineweight
acLsLocked Locked or unlocked
acLsNewViewport New viewport layers frozen or thawed
acLsNone None
acLsOn On or off
acLsPlot Plotting on or off
acLsPlotStyle Plot style
|;
;;使用示例: (gxl-layer-Save "图层状态1" nil)
(defun gxl-layer-Save(name Mask / lm acad)
(if (null Mask)
    (setq Mask aclsall))
(setq        lm
       (vla-GetInterfaceObject
           (setq acad (vlax-get-acad-object))
           (strcat "AutoCAD.AcadLayerStateManager."
                   (substr (getvar 'acadver) 1 2)
                   )
           )
        )
(vla-SetDatabase lm (vla-get-Database (vla-get-ActiveDocument acad)))
(if (VL-CATCH-ALL-ERROR-P
        (VL-CATCH-ALL-APPLY 'vla-save (list lm name mask))
        )
    (progn
      (VL-CATCH-ALL-APPLY 'vla-delete (list lm name))
      (not
        (VL-CATCH-ALL-ERROR-P
          (VL-CATCH-ALL-APPLY 'vla-save (list lm name mask))
          )
        )
      )
    t
    )
)
;;(gxl-layer-Restore name delflag) 恢复图层状态,成功返回T,否则返回nil
;;name 要恢复的图层状态的名称
;;delflag 是否删除该图层状态
;;使用示例: (gxl-layer-Restore "图层状态1" t)
(defun gxl-layer-Restore(name delflag / lm rtn acad)
(setq        lm
       (vla-GetInterfaceObject
           (setq acad (vlax-get-acad-object))
           (strcat "AutoCAD.AcadLayerStateManager."
                   (substr (getvar 'acadver) 1 2)
                   )
           )
        )
(vla-SetDatabase lm (vla-get-Database (vla-get-ActiveDocument acad)))
(setq        rtn
       (not
           (VL-CATCH-ALL-ERROR-P
             (VL-CATCH-ALL-APPLY 'vla-Restore (list lm name))
             )
           )
        )
(if delflag
    (VL-CATCH-ALL-APPLY 'vla-delete (list lm name)))
rtn
)

ivde 发表于 2014-10-22 20:49:49

Saves a layer state in the current drawing

(layerstate-save layerstatename mask viewport)
Arguments

layerstatename
A string specifying the name of the layer state to save.

mask
An integer sum designating which properties in the layer state are to be restored.

1- Restore the saved On or Off value

2- Restore the saved Frozen or Thawed value

4- Restore the saved Lock value

8- Restore the saved Plot or No Plot value

16- Restore the saved VPVSDFLT value

32- Restore the saved Color

64- Restore the saved LineType

128- Restore the saved LineWeight

viewport
An ename (ads_name) of the viewport whose VPLAYER setting is to be captured. If nil, the layer state will be saved without VPLAYER settings.

Return Values

T if the save is successful; otherwise nil

Examples

(layerstate-save “myLayerState“ 21 viewportId)
T
(layerstate-save “myLayerState“ nil nil)
nil


Restores a layer state into the current drawing

(layerstate-restore layerstatename viewport
)
Arguments

layerstatename
A string specifying the name of the layer to restore.

viewport
An ename (ads_name) of the viewport to which layerstatename should be restored. If viewport is nil, the layer state is restored to model space.

restoreflags
Optional integer sum affecting how the layer state is restored.

1- Turn off all layers not in the restored layer state

2- Freeze all layers not in the restored layer state

4- Restore the layer state properties as viewport overrides (requires viewport to be not a nil value).

Return Values

nil if the layer state does not exist or contains no layers; otherwise, returns a list of layer names.

Examples

(layerstate-restore “myLayerState“ viewportId 5)
(“Layername1” “Layername2“)

zhuquanmao 发表于 2014-10-25 17:28:37

Gu_xl 发表于 2014-10-22 20:11 static/image/common/back.gif
提供两个图层状态存储和恢复的函数如下:


膜拜中

窗外流逝的时光 发表于 2016-5-4 00:05:28

想学习下,看不到啊

lxw320 发表于 2016-5-5 21:22:57

手机能看,电脑看不了

htxhtx 发表于 2019-7-12 10:51:19

好帖子 谢谢i!

渠辉 发表于 2019-8-25 17:28:09

好东西。谢谢LZ的分享
页: [1] 2
查看完整版本: 【请问怎么获取图中各图层的状态】