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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 运算符是处理数据的基本方法,用来从现有的值得到新的值。JavaScript 提供了多种运算符,本章逐一介绍这些运算...
    徵羽kid阅读 715评论 0 0
  • 一、Python简介和环境搭建以及pip的安装 4课时实验课主要内容 【Python简介】: Python 是一个...
    _小老虎_阅读 5,822评论 0 10
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,146评论 1 32
  • 概要 64学时 3.5学分 章节安排 电子商务网站概况 HTML5+CSS3 JavaScript Node 电子...
    阿啊阿吖丁阅读 9,342评论 0 3
  • 面向对象主要针对面向过程。 面向过程的基本单元是函数。 什么是对象:EVERYTHING IS OBJECT(万物...
    sinpi阅读 1,096评论 0 4