iCAx开思网

标题: vb编程求实体表面积 [打印本页]

作者: sqzpf    时间: 2008-3-11 12:33
标题: vb编程求实体表面积
大家好 ,
前段时间在论坛上看见关于求实体表面积的文章,受益匪浅.看完程序不知该程序如何获取到指定实体的表面积,还请大家帮忙指教一下哈,谢谢!


已有代码如下:
Option Explicit

Public Enum swBodyType_e
    swSolidBody = 0
    swSheetBody = 1
    swWireBody = 2
    swMinimumBody = 3
    swGeneralBody = 4
    swEmptyBody = 5
End Enum

Sub main()
    Dim swApp                   As SldWorks.SldWorks
    Dim swModel                 As SldWorks.ModelDoc2
    Dim swPart                  As SldWorks.PartDoc
    Dim vBody                   As Variant
    Dim swBody                  As SldWorks.body2
    Dim swFace                  As SldWorks.face2
    Dim i                       As Long
    Dim j                       As Long
    Dim nTotArea                As Double
    Dim nArea(5)                As Double
    Dim bRet                    As Boolean
   
    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc
    Set swPart = swModel
   
    For i = 0 To 5
        vBody = swPart.GetBodies(i)
        
        If Not IsEmpty(vBody) Then
            For j = 0 To UBound(vBody)
                Set swBody = vBody(j)
                Set swFace = swBody.GetFirstFace
                While Not swFace Is Nothing
                    nArea(i) = nArea(i) + swFace.GetArea
               
                    Set swFace = swFace.GetNextFace
                Wend
            Next j
        End If
        
        nTotArea = nTotArea + nArea(i)
    Next i
   
    Debug.Print "Total Area = " + Str(nTotArea) + " m^2"
    For i = 0 To 5
        Debug.Print "  Area(" + Str(i) + ") = " + Str(nArea(i)) + " m^2"
    Next i
End Sub




欢迎光临 iCAx开思网 (https://www.icax.net/) Powered by Discuz! X3.3