SWVB101
Mechanical
- Jun 25, 2003
- 85
Is Their A Simpler Way To Programmatically Obtain the Mass Properties Of A Model, Given A View In A Drawing, WithOUT physically opening the Model In A new window...?
I know this is possible with Assemblies...
I don't see why it would be impossible with a drawing...
This is A Sample Senario of what I am trying to do...
Assuming the Current View in an Active Drawing is the view I want to retrieve the Mass Properties From...
And the Assembly Method (using component objects)...
If you have any Ideas, or if you see something I missed, please let me know...
I know this is possible with Assemblies...
I don't see why it would be impossible with a drawing...
This is A Sample Senario of what I am trying to do...
Assuming the Current View in an Active Drawing is the view I want to retrieve the Mass Properties From...
Code:
Dim swApp As Object, Model As Object, View As Object
Dim data1 As Variant, data2 As Variant, data3 As Variant
Dim mass As Double
Const swDocPART = 1, swDocASSEMBLY = 2, swDocDRAWING = 3
Set swApp = CreateObject("SldWorks.Application")
Set Model = swApp.ActiveDoc
Set View = Model.GetFirstView
Set View = Model.GetNextView
s$ = View.GetReferencedModelName()
drawname$ = Model.GetPathName() 'Store current Doc
Set Model = swApp.ActivateDoc(s$)
data1 = Model.GetMassProperties()
massp = round(data1(5) * 2.2046, 2)
MP_Volume = round(data1(3) * 61023.74, 3)
MP_Density = round(massp / MP_Volume, 3)
'...Able to Change Density Here
mass = Round(MP_Volume * MP_Density, 2)
Set Model = swApp.ActivateDoc(drawname$) 'reStore Doc
And the Assembly Method (using component objects)...
Code:
Set Configuration = Model.GetActiveConfiguration()
Set Component = Configuration.GetRootComponent()
If Component Is Nothing Then ' If no component, then exit
Exit Sub
End If
componentName = Component.Name ' Get the component name
Set modelD = Component.GetModelDoc()
Data1 = Component.GetModelDoc().GetMassProperties()
massp = Round((Data1(5) * 2.2046, 2)
MP_Volume = Round((Data1(3) * 61023.74, 3)
MP_Density = Round((massp / MP_Volume, 3)
s1$ = " Mass:" + Str(massp)
s2$ = ", Volume:" + Str(MP_Volume)
s3$ = ", Density:" + Str(MP_Density)
If you have any Ideas, or if you see something I missed, please let me know...