CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2024 开发者帮助

关于创建和命名图层 (VBA/ActiveX)

2024-5-18 19:06| 发布者: admin| 查看: 167| 评论: 0|原作者: admin|来自: AutoCAD

关于创建和命名图层 (VBA/ActiveX)

您可以创建新图层,并为这些图层指定颜色和线型属性。

每个单独的图层都是集合的一部分。使用该方法创建一个新图层并将其添加到集合中。LayersAddLayers

您可以在创建图层时为其指定名称。要在创建图层后更改图层的名称,请使用该属性。图层名称最多可以包含 31 个字符,并包含字母、数字和特殊字符美元符号 ($)、连字符 (-) 和下划线 (_),但不能包含空格。Name

创建一个新图层,为其指定红色,然后向该图层添加对象

以下代码创建一个圆圈和一个新图层。新图层被指定为红色。将圆圈分配给图层,并且圆圈的颜色会相应更改。

Sub Ch4_NewLayer()
  ' Create a circle
  Dim circleObj As AcadCircle
  Dim center(0 To 2) As Double
  Dim radius As Double
  center(0) = 2: center(1) = 2: center(2) = 0
  radius = 1
  Set circleObj = ThisDrawing.ModelSpace.AddCircle(center, radius)

  ' Create a color object
  Dim col As New AcadAcCmColor
  col.ColorMethod = AutoCAD.acColorMethodForeground

  ' Set the layer to the color
  Dim layColor As AcadAcCmColor
  Set layColor = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor." & _
                                                    Left(AcadApplication.Version, 2))
  Call layColor.SetRGB(122, 199, 25)
  ThisDrawing.ActiveLayer.TrueColor = layColor
  col.ColorMethod = AutoCAD.acColorMethodByLayer

  ' Assign the circle the color "ByLayer" so
  ' that the circle will automatically pick
  ' up the color of the layer on which it resides
  circleObj.Color = acByLayer
  circleObj.Update
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2025-3-28 16:52

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部