×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

MassProperties X VBA X Configurations

MassProperties X VBA X Configurations

MassProperties X VBA X Configurations

(OP)
I am writing a VBA program to read and write custom properties of parts. These parts can have configurations. I use EXCEL, list the custom properties in rows and the configurations (if they exist) of the part in columns. Everything works fine except for MassProperties (weight and volume). I can only retrieve the mass properties of the active configuration. I have made some tests, including try to change the active configuration with the program, but I think that it only works with assemblies. Can anyone give me a hint about how can I read, using VBA, the custom properties of several configurations of a part?
I am working with sw2001 SP11.

RE: MassProperties X VBA X Configurations

You may have to loop through the configurations, activating each and reading the mass properties. Then populate your excel file with the value rather than maintaining the link. Here is some code to get you through the configurations and get the mass properties:

Option Explicit

Const KGtoLB = 2.204622

Dim swApp As Object
Dim Part As Object

Sub GetMassOfEachConfig()
    Dim iConfigs As Long
    Dim ConfigNames As Variant
    Dim ConfigWgt() As Single
    Dim v1 As Variant, lStatus As Long
    Dim sTmp As String, i As Long
    
    'Get SolidWorks
    Set swApp = GetObject(, "SldWorks.Application")
    Set Part = swApp.ActiveDoc
    
    'Get a list of Configurations for active part
    iConfigs = Part.GetConfigurationCount
    ConfigNames = Part.GetConfigurationNames
    
    'Traverse through the configurations
    ReDim ConfigWgts(iConfigs)
    For i = 0 To (iConfigs - 1)
        Part.ShowConfiguration ConfigNames(i)
        v1 = Part.GetMassProperties2(lStatus)
        ConfigWgts(i) = v1(5) * KGtoLB
    Next

    'Report Results
    For i = 0 To (iConfigs - 1)
        sTmp = sTmp & ConfigNames(i) & ": " & ConfigWgts(i) & " lbs." & vbCrLf
    Next
    
    MsgBox sTmp
    
End Sub

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

RE: MassProperties X VBA X Configurations

(OP)
dsi

Thank you for your very useful answer. After reading it, I realised that I was not declaring and using the variable lStatus in the proper way. Every time that EXCEL reached my previous line MassProp = Part.GetMassProperties2(....) the result was:
- a VBA error message, or
- the values of the active configuration's mass properties were repeated for all configurations.
Now, after correcting the program based in your answer, everything is working fine!

Best Regards

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources