加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

SolidWorks二次开发:在程序中获取质量特征里的信息

发布时间:2020-12-16 22:53:10 所属栏目:大数据 来源:网络整理
导读:问题描述 :在SolidWorks中进行二次开发时,在程序中如何实现获得质量特性里的信息,如体积、表面积、重心等。 问题解决: 程序如下(语言类型是VB) Option Explicit Public Enum swMassPropertyMoment_e swMassPropertyMomentAboutCenterOfMass = 0 swMass

问题描述:在SolidWorks中进行二次开发时,在程序中如何实现获得质量特性里的信息,如体积、表面积、重心等。

问题解决:

程序如下(语言类型是VB)

Option Explicit

Public Enum swMassPropertyMoment_e

swMassPropertyMomentAboutCenterOfMass = 0

swMassPropertyMomentAboutCoordSys = 1

End Enum

Public Enum swMassPropertiesStatus_e

swMassPropertiesStatus_OK = 0

swMassPropertiesStatus_UnknownError = 1

swMassPropertiesStatus_NoBody = 2

End Enum

Public Enum swBodyType_e

swSolidBody = 0

swSheetBody = 1

swWireBody = 2

swMinimumBody = 3

swGeneralBody = 4

swEmptyBody = 5

End Enum

Public Enum swUserPreferenceDoubleValue_e

swMaterialPropertyDensity = 7

End Enum

Sub main()

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swDocExt As SldWorks.ModelDocExtension

Dim swMass As SldWorks.MassProperty

Dim swSelMgr As SldWorks.SelectionMgr

Dim swComp As SldWorks.Component2

Dim vBodyArr As Variant

Dim vCoM As Variant

Dim vMoI As Variant

Dim vPrinAoIx As Variant

Dim vPrinAoIy As Variant

Dim vPrinAoIz As Variant

Dim vPrinMoI As Variant

Dim nDensity As Double

Dim bRet As Boolean

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swDocExt = swModel.Extension

Set swMass = swDocExt.CreateMassProperty

Set swSelMgr = swModel.SelectionManager

Set swComp = swSelMgr.GetSelectedObjectsComponent2(1)

vBodyArr = swComp.GetBodies2(swSolidBody): Debug.Assert Not IsEmpty(vBodyArr)

bRet = swMass.AddBodies((vBodyArr)): Debug.Assert bRet

vCoM = swMass.CenterOfMass

vMoI = swMass.GetMomentOfInertia(swMassPropertyMomentAboutCenterOfMass)

vPrinAoIx = swMass.PrincipleAxesOfInertia(0)

vPrinAoIy = swMass.PrincipleAxesOfInertia(1)

vPrinAoIz = swMass.PrincipleAxesOfInertia(2)

vPrinMoI = swMass.PrincipleMomentsOfInertia

Debug.Print "File = " & swModel.GetPathName

Debug.Print " Comp = " & swComp.Name2

Debug.Print " Config = " & swComp.ReferencedConfiguration

Debug.Print " Density = " & swMass.Density & " kg/m^3"

Debug.Print ""

Debug.Print " CenterOfMass = (" & vCoM(0) * 1000# & "," & vCoM(1) * 1000# & "," & vCoM(2) * 1000# & ") mm"

Debug.Print " Volume = " & swMass.Volume * 1000000000# & " mm^3"

Debug.Print " Area = " & swMass.SurfaceArea * 1000000# & " mm^2"

Debug.Print " Mass = " & swMass.Mass & " kg"

Debug.Print ""

Debug.Print " Ix = (" & vPrinAoIx(0) & "," & vPrinAoIx(1) & "," & vPrinAoIx(2) & ")"

Debug.Print " Iy = (" & vPrinAoIy(0) & "," & vPrinAoIy(1) & "," & vPrinAoIy(2) & ")"

Debug.Print " Iz = (" & vPrinAoIz(0) & "," & vPrinAoIz(1) & "," & vPrinAoIz(2) & ")"

Debug.Print ""

Debug.Print " Px = " & vPrinMoI(0) & " kg*m^2"

Debug.Print " Py = " & vPrinMoI(1) & " kg*m^2"

Debug.Print " Pz = " & vPrinMoI(2) & " kg*m^2"

Debug.Print ""

Debug.Print " Lxx = " & vMoI(0) & " kg*m^2"

Debug.Print " Lxy = " & vMoI(1) & " kg*m^2"

Debug.Print " Lxz = " & vMoI(2) & " kg*m^2"

Debug.Print " Lyx = " & vMoI(3) & " kg*m^2"

Debug.Print " Lyy = " & vMoI(4) & " kg*m^2"

Debug.Print " Lyz = " & vMoI(5) & " kg*m^2"

Debug.Print " Lzx = " & vMoI(6) & " kg*m^2"

Debug.Print " Lzy = " & vMoI(7) & " kg*m^2"

Debug.Print " Lzz = " & vMoI(8) & " kg*m^2"

End Sub

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读