首页 > 其他分享 >025集——CAD中块(Block)和块参照——vba代码实现

025集——CAD中块(Block)和块参照——vba代码实现

时间:2024-08-15 17:53:02浏览次数:9  
标签:vba tempBlock 布局 IsLayout 025 中块 PAPER msg Block

VBA 类名

AcadBlock 

创建方法

Blocks.Add 

访问途径

Blocks.Item
Layout.Block 

块有三种类型:简单块, XRef 块 和布局块。

简单块是可以联合在一起形成单个对象或块定义的对象集合。用户可以在图形中插入、旋转对象以及调整对象的比例。用户可以把简单块炸开成组成对象、修改组成对象以及重新定义块。  简单块可以由当前图形中的几何形状来定义,也可以使用其他的AutoCAD 图形。当使用另外一个图形来创建块时,新的简单块会保存在当前图形数据库中;假如原始图形更改,它不会更新。将简单块的实例插入到当前的图形中会创建一个BlockReference 对象。

XRef 块是从其它图形到当前图形的外部连结。 由于 XRef 块代表的是对几何图形的连结而不是几何图形本身,因此会随着来源图形的修改而更新。将 XRef 块的实例插入当前的图形会创建一个ExternalReference 对象。

布局块代表模型空间与图纸空间布局中的几何图形。这些块具有一个与其相连的布局(Layout)对象,其中包含出图配置以及其他配置定义信息。激活的图纸空间的块名为*PAPER_SPACE。其他图纸空间的块名为*PAPER_SPACEn,其中 n为整数。 布局名从 *PAPER_SPACE0开始;每插入一个新的布局,整数加1。 

依照默认值,布局块具有下列名称:

块名

定义

*MODEL_SPACE 模型空间布局。每一个图形只有一个模型空间布局。这个块和 ModelSpace 集合相对应。
*PAPER_SPACE 创建的第一个图纸空间。假如模型空间布局当前激活,则块包含最后被激活的图纸空间布局。
这个块和 PaperSpace 集合相对应。
*PAPER_SPACE0 创建的第二个图纸空间。假如这个布局被激活,这个图块将更名为*PAPER_SPACE ,并且可以从 PaperSpace集合存取;第一个布局名被更改为 *PAPER_SPACE0。

当用户激活一个新的布局,它将与前面建立的布局交换名称。这样,当前激活的布局名称总为*PAPER_SPACE。例如,假设布局1被激活,布局2与名称为*PAPER_SPAC0的块相关联。假如用户激活布局2,那么它的块名更改为*PAPER_SPACE,布局1的块名则改为*PAPER_SPACE0。

动态块通过提高智能性和适应性来增强普通块的性能。动态块实例的内部几何图形的基本定义和其它情况均可单独调整。这些机动性是动态块的重要概念。将动态块插入到当前图形中创建的也是 BlockReference 对象。从该块参照中,用户可获取 DynamicBlockReferenceProperty 对象。

要识别块的类型,使用IsLayout和IsXRef 属性。

① 假如这两个属性都是 FALSE,则块为一个简单块。

② 假如IsXRef 属性为TRUE,则块是一个外部引用。

③ 假如IsLayout属性为TRUE,则块包含所有与块相关的几何图形。

块可含有的对象数量没有限制。

要插入普通块或XRef块到图形中,使用InsertBlock方法。要建立新的布局块,使用 Add方法加入新的布局到Layouts集合中。当新的布局建立后,与布局相关的块也被建立。

要编辑或查询块,使用以下方法和属性:

方法

Add3DFace

Add3DMesh

Add3DPoly

AddArc

AddAttribute

AddBox

AddCircle

AddCone

AddCustomObject

AddCylinder

AddDim3PointAngular

AddDimAligned

AddDimAngular

AddDimArc

AddDimDiametric

AddDimOrdinate

AddDimRadial

AddDimRadialLarge

AddDimRotated

AddEllipse

AddEllipticalCone

AddEllipticalCylinder

AddExtrudedSolidAlongPath

AddExtrudedSolid

AddHatch

AddLeader

AddLightweightPolyline

AddLine

AddMInsertBlock

AddMLine

AddMText

AddPoint

AddPolyfaceMesh

AddPolyline

AddRaster

AddRay

AddRegion

AddRevolvedSolid

AddShape

AddSolid

AddSphere

AddSpline

AddTable

AddText

AddTolerance

AddTorus

AddTrace

AddWedge

AddXLine

AttachExternalReference

Bind

Delete

Detach

GetXData

InsertBlock

Item

Reload

SetXData

Unload 

属性

Application

BlockScaling

Comments

Count

Document

Explodable

Handle

HasExtensionDictionary

IsDynamicBlock

IsLayout

IsXRef

Layout

Name

ObjectID

Origin

OwnerID

Path

Units

XRefDatabase  

事件

Modified  

IsLayout 属性

确定给定的块是否为布局块。

语法

object.IsLayout

object

Block
使用该属性的对象。

IsLayout

Boolean[布尔值]; 只读

TRUE: 块为布局。

FALSE: 块不是布局。

说明

IsLayout 属性与 IsXRef 属性一起使用,如果两个属性均为 FALSE,则块为普通的块。如果 IsXRef 属性为 TRUE,则块为外部参照。如果 IsLayout 属性为 TRUE,则包含了与布局相关联的所有几何图形。

''版权@qq443440204,支持cad二次开发、插件编写。
For Each myb In ThisDrawing.Blocks
If myb.IsLayout Then
MsgBox myb.Name
End If
Next myb
版权@qq443440204,支持cad二次开发、插件编写。
Sub Example_IsLayout()
    ' This example cycles through each Block object in a drawing
    ' and determines whether style of each Block by accessing the
    ' IsLayout and IsXRef properties.  A Block
    ' object is also added at runtime so the results are mixed and do not only
    ' come from the default Blocks.
    
    Dim circleObj As AcadCircle
    Dim centerPoint(0 To 2) As Double, InsertPoint(0 To 2) As Double
    Dim radius As Double
    Dim newBlock As AcadBlock, insertedBlock As AcadBlockReference
    Dim tempBlock As AcadBlock
    Dim msg As String
    
    ' Define the Circle object that will be inserted into the block
    centerPoint(0) = 0: centerPoint(1) = 0: centerPoint(2) = 0
    InsertPoint(0) = 1: InsertPoint(1) = 1: InsertPoint(2) = 0
    radius = 0.5
    
    ' Create a new block to hold the Circle object
    Set newBlock = ThisDrawing.Blocks.Add(centerPoint, "CBlock")
    
    ' Add the Circle object to the new block object
    Set circleObj = ThisDrawing.Blocks("CBlock").AddCircle(centerPoint, radius)
    
    ' Add the new block to model space
    Set insertedBlock = ThisDrawing.ModelSpace.InsertBlock(InsertPoint, "CBlock", 1, 1, 1, 0)
        
    ThisDrawing.Application.ZoomAll
    
    msg = vbCrLf & vbCrLf
    
    For Each tempBlock In ThisDrawing.Blocks
        If Not (tempBlock.IsLayout) And Not (tempBlock.IsXRef) Then
            ' Block is simple
            msg = msg & tempBlock.name & ": Simple"
        ElseIf tempBlock.IsXRef Then
            ' Block is an external reference
            msg = msg & tempBlock.name & ": External Reference"
            If tempBlock.IsLayout Then
                ' Block also contains layout geometry
                msg = msg & tempBlock.name & " and Contains Layout Geometry"
            End If
        ElseIf tempBlock.IsLayout Then
            ' Block contains layout geometry
            msg = msg & tempBlock.name & ": Contains Layout Geometry"
        End If
        
        msg = msg & vbCrLf      ' Move to next line
    Next
        
    ' Display Block information for this drawing
    MsgBox "Blocks in this drawing have the following styles: " & msg

End Sub

 

说明

版权@qq443440204,支持cad二次开发、插件编写。

该对象在 2006 版本中支持动态块,增加了 AddDimArcAddDimRadialLarge 方法和 BlockScalingCommentsExplodableIsDynamicBlockUnits 属性。

标签:vba,tempBlock,布局,IsLayout,025,中块,PAPER,msg,Block
From: https://blog.csdn.net/yongshiqq/article/details/141227794

相关文章