明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: 泉(Ango)

AutoCAD VBA判断指定图层是否存在,如不存在则新建.

  [复制链接]
发表于 2012-11-15 22:35:47 | 显示全部楼层
本帖最后由 yshf 于 2012-11-15 22:45 编辑


  1. Option Explicit
  2. Dim oldLayer As AcadLayer
  3. Dim NewLayer As AcadLayer

  4. Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
  5.    Debug.Print CommandName
  6.    Select Case CommandName
  7.    Case "DIMLINEAR", "DIMALIGNED", "DIMARC", "DIMORDINATE", "DIMRADIUS", "DIMJOGGED", "DIMDIAMETER", "DIMANGULAR", "QDIM", "DIMBASELINE", "DIMCONTINUE", "QLEADER"
  8.        Set oldLayer = ThisDrawing.ActiveLayer
  9.    
  10.       On Error Resume Next
  11.        Set NewLayer = ThisDrawing.Layers("DIM")
  12.        If Err Then
  13.           Err.Clear
  14.           Set NewLayer = ThisDrawing.Layers.Add("DIM")
  15.        End If

  16.        ThisDrawing.ActiveLayer = ThisDrawing.Layers.Item("DIM")
  17.    End Select
  18. End Sub

  19. Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
  20.     Select Case CommandName
  21.     Case "DIMLINEAR", "DIMALIGNED", "DIMARC", "DIMORDINATE", "DIMRADIUS", "DIMJOGGED", "DIMDIAMETER", "DIMANGULAR", "QDIM", "DIMBASELINE", "DIMCONTINUE", "QLEADER"
  22.         ThisDrawing.ActiveLayer = oldLayer
  23.     End Select
  24. End Sub
 楼主| 发表于 2012-11-18 15:15:40 | 显示全部楼层
谢谢大家的帮助......
发表于 2014-11-16 21:25:18 | 显示全部楼层
好像不管是否存在Dim图层,直接新建Dim图层并置为当前图层也不会出问题吧
像这样:
ThisDrawing.ActiveLayer = ThisDrawing.Layers.Add("Dim")
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-22 21:24 , Processed in 0.151286 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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