编辑三维实体

AutoCAD ActiveX/VBA

 
编辑三维实体
 
 
 

创建实体之后,可以通过组合实体来创建更复杂的形状。可以合并这些实体、获得它们的差集或找出实体的公用(重叠)部分。可以使用 Boolean 或 CheckInterference 方法完成这些组合。

通过获取实体的二维相交截面或将实体剖切为两个部分,可以进一步修改实体。可以使用 SectionSolid 方法找出实体的相交截面,使用 SliceSolid 方法将实体剖切为两部分。

找出两个实体之间的干涉

本样例在模型空间中创建一个长方体和一个圆柱体,然后找出这两个实体之间的干涉,并由干涉创建一个新的实体。为便于查看,将长方体着色为白色,圆柱体着色为青色,得到的干涉实体为红色。

Sub Ch8_FindInterferenceBetweenSolids()
    ' 定义长方体
    Dim boxObj As Acad3DSolid
    Dim length As Double
    Dim width As Double
    Dim height As Double
    Dim center(0 To 2) As Double
    center(0) = 5: center(1) = 5: center(2) = 0
    length = 5
    width = 7
    height = 10
      
    ' 在模型空间中创建长方体对象
    ' 并着色为白色
    Set boxObj = ThisDrawing.ModelSpace. _
                AddBox(center, length, width, height)
    boxObj.Color = acWhite
      
    ' 定义圆柱体
    Dim cylinderObj As Acad3DSolid
    Dim cylinderRadius As Double
    Dim cylinderHeight As Double
    center(0) = 0: center(1) = 0: center(2) = 0
    cylinderRadius = 5
    cylinderHeight = 20
      
    ' 创建圆柱体并
    ' 着色为青色
    Set cylinderObj = ThisDrawing.ModelSpace.AddCylinder _
                   (center, cylinderRadius, cylinderHeight)
    cylinderObj.Color = acCyan
      
    ' 找出两个实体之间的干涉
    ' 并由干涉创建新的实体。新实体
    ' 着色为红色。
    Dim solidObj As Acad3DSolid
    Set solidObj = boxObj.CheckInterference(cylinderObj, True)
    solidObj.Color = acRed
    ZoomAll
End Sub

将实体剖切为两个实体

本样例在模型空间中创建一个长方体,然后基于由三个点定义的平面剖切该长方体。剖切后的结果作为 3DSolid 返回。

Sub Ch8_SliceABox()
    ' 创建长方体对象
    Dim boxObj As Acad3DSolid
    Dim length As Double
    Dim width As Double
    Dim height As Double
    Dim center(0 To 2) As Double
    center(0) = 5#: center(1) = 5#: center(2) = 0
    length = 5#: width = 7: height = 10#
      
    ' 在模型空间中创建长方体 (3DSolid) 对象
    Set boxObj = ThisDrawing.ModelSpace. _
                AddBox(center, length, width, height)
    boxObj.Color = acWhite
      
    ' 用三点定义剖切平面
    Dim slicePt1(0 To 2) As Double
    Dim slicePt2(0 To 2) As Double
    Dim slicePt3(0 To 2) As Double
      
    slicePt1(0) = 1.5: slicePt1(1) = 7.5: slicePt1(2) = 0
    slicePt2(0) = 1.5: slicePt2(1) = 7.5: slicePt2(2) = 10
    slicePt3(0) = 8.5: slicePt3(1) = 2.5: slicePt3(2) = 10
      
     ' 剖切长方体并将新实体着色为红色
    Dim sliceObj As Acad3DSolid
    Set sliceObj = boxObj.SliceSolid _
                    (slicePt1, slicePt2, slicePt3, True)
    sliceObj.Color = acRed
    ZoomAll
End Sub