microstation二次开发之实体布尔运算

实体布尔运算的三种方法

1并运算

SolidUnion (body1, body2)
body1 : SmartSolidElement.
body2 : SmartSolidElement.
return: SmartSolidElement
返回的对象为两个对象的并集

2交运算

SolidIntersect (body1, body2)
body1 : SmartSolidElement.
body2 : SmartSolidElement.
return: SmartSolidElement
返回的对象为两个对象的交集

3差运算

SolidSubtract (body1, body2)
body1 : SmartSolidElement.
body2 : SmartSolidElement.
return: SmartSolidElement
返回的对象为对象1减去对象2的剩余部分

窗体设计及参数

1 form.png

通用函数

'删除元素
Sub deleteAllElements()
   Dim myElement As Element
   Dim myEnum As ElementEnumerator
   Set myEnum = ActiveModelReference.Scan()
   On Error Resume Next
   Do While myEnum.MoveNext
      Set myElement = myEnum.Current
      ActiveModelReference.RemoveElement myElement
   Loop
End Sub


Function CreateSphere() As SmartSolidElement
   Dim x, y, z, r As Double
   Dim solid As SmartSolidElement
   Dim origin As Point3d
   
   x = Val(TextBox1.Value)
   y = Val(TextBox2.Value)
   z = Val(TextBox3.Value)
   r = Val(TextBox4.Value)
  
    '创建球体
    Set solid = SmartSolid.CreateSphere(Nothing, r)
    origin = Point3dFromXYZ(x, y, z)
    solid.Move origin
    Set CreateSphere = solid
End Function

Function CreateSlab() As SmartSolidElement
   Dim x, y, z, r As Double
  Dim origin As Point3d
   x = Val(TextBox5.Value)
   y = Val(TextBox6.Value)
   z = Val(TextBox7.Value)
   Width = Val(TextBox8.Value)
   Length = Val(TextBox9.Value)
   Height = Val(TextBox10.Value)
   Dim solid As SmartSolidElement
    '创建球体
    Set solid = SmartSolid.CreateSlab(Nothing, Width, Length, Height)
    origin = Point3dFromXYZ(x, y, z)
    solid.Move origin
    Set CreateSlab = solid
End Function

并运算代码

'并运算
Private Sub CommandButton1_Click()
   deleteAllElements
   Dim solid1, solid2, result As SmartSolidElement
  Set solid1 = CreateSphere()
  Set solid2 = CreateSlab()
  Set result = SmartSolid.SolidUnion(solid1, solid2)
  
    '添加至模型空间
   ActiveModelReference.AddElement result
   
End Sub

并运算效果

1union.png

交运算代码

'交运算
Private Sub CommandButton2_Click()
  deleteAllElements
   Dim solid1, solid2, result As SmartSolidElement
   Set solid1 = CreateSphere()
   Set solid2 = CreateSlab()
   Set result = SmartSolid.SolidIntersect(solid1, solid2)
  
    '添加至模型空间
    ActiveModelReference.AddElement result
End Sub

交运算效果

交运算

差运算代码

'差运算
Private Sub CommandButton3_Click()
  deleteAllElements
   Dim solid1, solid2, result As SmartSolidElement
   Set solid1 = CreateSphere()
   Set solid2 = CreateSlab()
   Set result = SmartSolid.SolidSubtract(solid1, solid2)
    '添加至模型空间
    ActiveModelReference.AddElement result
End Sub

差运算效果

1差.png

你可能感兴趣的:(microstation二次开发之实体布尔运算)