重定义块

AutoCAD ActiveX/VBA

 
重定义块
 
 
 

要重定义块,请使用 Block 对象的任何方法和特性。重定义块时,图形中对该块的所有参照也随即更新,以便反映新的定义。

重定义会影响以前和以后的块插入。固定属性会丢失,并且被新的固定属性所替换。即使新块不包含属性,可变属性也保持不变。

在块定义中重定义对象

本例创建一个块并向块定义中添加一个圆,然后将块作为块参照插入到图形中。块定义中的圆将被更新,块参照也会自动更新。

Sub Ch10_RedefiningABlock()
    ' 定义块
    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")
      
    ' 向块中添加圆
    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)
      
    ' 插入块
    Dim blockRefObj As AcadBlockReference
    insertionPnt(0) = 2
    insertionPnt(1) = 2
    insertionPnt(2) = 0
    Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock _
               (insertionPnt, "CircleBlock", 1#, 1#, 1#, 0)
    ZoomAll
      
    ' 重定义块中的圆,
    ' 并更新块参照
    circleObj.radius = 3
    blockRefObj.Update
End Sub