CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2023 开发者帮助

Layer 属性 (ActiveX)

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

Layer 属性 (ActiveX)

指定对象的图层。

支持的平台:仅限 Windows

签名

VBA:

object.Layer
对象

类型:所有绘图对象AttributeReferenceGroupSubDMeshEdgeSubDMeshFaceSubDMeshVertexSubEntitySubEntSolidEdgeSubEntSolidFaceSubEntSolidNodeSubEntSolidVertex

此属性应用于的对象。

属性值

只读:不;除了只写对象Group

类型:字符串

图层的名称。

言论

所有对象都有一个关联的层。文档始终包含至少一个图层(图层 0)。与线型一样,您可以为对象指定图层。如果未指定图层,则当前活动图层将用于新对象。如果为对象指定了图层,则忽略当前活动图层。使用该属性可设置或查询当前活动图层。ActiveLayer

每个图层都有关联的属性,可以通过对象进行设置和查询。Layer

例子

VBA:

Sub Example_Layer()
    ' This example creates a new layer named "ABC" (colored blue).
    ' It then creates a circle and assigns it to layer "ABC"

    ' Create new layer
    Dim layerObj As AcadLayer
    Set layerObj = ThisDrawing.Layers.Add("ABC")
    Dim color As AcadAcCmColor
	   Set color = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor." & Left(AcadApplication.Version, 2))
    Call color.SetRGB(80, 100, 244)
    layerObj.TrueColor = color
    
    ' Create Circle
    Dim circleObj As AcadCircle
    Dim center(0 To 2) As Double
    Dim radius As Double
    center(0) = 3: center(1) = 3: center(2) = 0
    radius = 1.5
    Set circleObj = ThisDrawing.ModelSpace.AddCircle(center, radius)
    ZoomAll
    MsgBox "The circle has been created on layer " & circleObj.Layer, , "Layer Example"
        
    ' Set the layer of new circle to "ABC"
    circleObj.Layer = "ABC"

    ' Refresh view
    ThisDrawing.Regen (True)
    MsgBox "The circle is now on layer " & circleObj.Layer, , "Layer Example"
    
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_Layer()
    ;; This example creates a new layer named "ABC" (colored blue).
    ;; It then creates a circle and assigns it to layer "ABC"
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
 
    ;; Create new layer
    (setq layerObj (vla-Add (vla-get-Layers doc) "ABC"))
    (setq color (vlax-create-object (strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2))))
    (vla-SetRGB color 80 100 244)
    (vla-put-TrueColor layerObj color)
    
    ;; Create Circle
    (setq center (vlax-3d-point 3 3 0)
          radius 1.5)
    (setq modelSpace (vla-get-ModelSpace doc))  
    (setq circleObj (vla-AddCircle modelSpace center radius))
    (vla-ZoomAll acadObj)
    (alert (strcat "The circle has been created on layer " (vla-get-Layer circleObj)))
        
    ;; Set the layer of new circle to "ABC"
    (vla-put-Layer circleObj "ABC")

    ;; Refresh view
    (vla-Regen doc :vlax-true)
    (alert (strcat "The circle is now on layer " (vla-get-Layer circleObj)))

    (vlax-release-object color)
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-12-15 11:27

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部