指定块中是否具有任何属性。 支持的平台:仅窗口 属性值只读:是的 类型:布尔
言论如果块参照包含任何可编辑或常量(不可编辑)属性,则此属性为。是如果没有属性。TrueFalse 要返回与块关联的对象数组,请使用该方法。AttributeGetAttributes 例子工 务 局: Sub Example_HasAttributes()
' This example first creates a block without attributes.
' It then inserts the block and checks whether it has attributes.
' It then adds attributes to the block and inserts it again.
' Then it checks the new block reference for attributes.
' Create the block
Dim blockObj As AcadBlock
Dim insertionPnt(0 To 2) As Double
insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#
Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, "CircleBlock")
' Add a circle to the block
Dim circleObj As AcadCircle
Dim center(0 To 2) As Double
Dim radius As Double
center(0) = 0: center(1) = 0: center(2) = 0
radius = 1
Set circleObj = blockObj.AddCircle(center, radius)
' Insert the block
Dim blockRefObj As AcadBlockReference
insertionPnt(0) = 2#: insertionPnt(1) = 2#: insertionPnt(2) = 0
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "CircleBlock", 1#, 1#, 1#, 0)
ThisDrawing.Application.ZoomAll
MsgBox "This block reference " & IIf(blockRefObj.HasAttributes, "has attributes.", "does not have attributes."), , "Has Attributes Example"
' Add attributes to the block definition.
' Define the attribute definition.
Dim attributeObj As AcadAttribute
Dim height As Double
Dim mode As Long
Dim prompt As String
Dim insertionPoint(0 To 2) As Double
Dim tag As String
Dim value As String
height = 1#
mode = acAttributeModeVerify
prompt = "Attribute Prompt"
insertionPoint(0) = 1#: insertionPoint(1) = 1#: insertionPoint(2) = 0
tag = "Attribute_Tag"
value = "Attribute Value"
' Create the attribute definition
Set attributeObj = blockObj.AddAttribute(height, mode, prompt, insertionPoint, tag, value)
' Insert the block again
Dim blockRefObj2 As AcadBlockReference
insertionPnt(0) = 3#: insertionPnt(1) = 3#: insertionPnt(2) = 0
Set blockRefObj2 = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "CircleBlock", 1#, 1#, 1#, 0)
ZoomAll
MsgBox "The first block reference " & IIf(blockRefObj.HasAttributes, "has attributes.", "does not have attributes.") & vbCrLf & _
"The second block reference " & IIf(blockRefObj2.HasAttributes, "has attributes.", "does not have attributes."), , "Has Attributes Example"
End Sub
Visual LISP: (vl-load-com)
(defun c:Example_HasAttributes()
;; This example first creates a block without attributes.
;; It then inserts the block and checks whether it has attributes.
;; It then adds attributes to the block and inserts it again.
;; Then it checks the new block reference for attributes.
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
;; Create the block
(setq insertionPnt (vlax-3d-point 0 0 0))
(setq blockObj (vla-Add (vla-get-Blocks doc) insertionPnt "CircleBlock"))
;; Add a circle to the block
(setq center (vlax-3d-point 0 0 0))
(setq radius 1)
(setq circleObj (vla-AddCircle blockObj center radius))
;; Insert the block
(setq insertionPnt (vlax-3d-point 2 2 0))
(setq modelSpace (vla-get-ModelSpace doc))
(setq blockRefObj (vla-InsertBlock modelSpace insertionPnt "CircleBlock" 1 1 1 0))
(vla-ZoomAll acadObj)
(alert (strcat "This block reference " (if (= (vla-get-HasAttributes blockRefObj) :vlax-true) "has attributes." "does not have attributes.")))
;; Add attributes to the block definition.
;; Define the attribute definition.
(setq insertionPoint (vlax-3d-point 1 1 0)
attHeight 1
attMode acAttributeModeVerify
attPrompt "Attribute Prompt"
attTag "Attribute_Tag"
attValue "Attribute Value")
;; Create the attribute definition
(setq attributeObj (vla-AddAttribute blockObj attHeight attMode attPrompt insertionPoint attTag attValue))
;; Insert the block again
(setq insertionPnt (vlax-3d-point 3 3 0))
(setq blockRefObj2 (vla-InsertBlock modelSpace insertionPnt "CircleBlock" 1 1 1 0))
(vla-ZoomAll acadObj)
(alert (strcat "The first block reference " (if (= (vla-get-HasAttributes blockRefObj) :vlax-true) "has attributes." "does not have attributes.")
"\nThe second block reference " (if (= (vla-get-HasAttributes blockRefObj2) :vlax-true) "has attributes." "does not have attributes.")))
)
|
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-28 23:37
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.