×
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

Adding Custom Properties

Adding Custom Properties

Adding Custom Properties

(OP)
I need to Add and Modify custom properties in Solidworks.  I am new to Solidworks, but experienced with VB and VBA.  Can anyone point me in the correct direction?

RE: Adding Custom Properties

Here is some sample code to get you started. Updates the active document (part, drawing or assembly).

Option Explicit

Const swCustomInfoText = 30
Const swCustomInfoNumber = 3

Sub CodeSamples()
    Dim swApp As Object
    Dim Part As Object
    Dim sConfig As String
    Dim s1 As String, s2 As String
    
    Set swApp = GetObject(, "SldWorks.Application")
    Set Part = swApp.ActiveDoc

    'Define the Configuration
    '  -Use the name of the config if not default
    '  -You can get a list of all configs using:
    '       Part.GetConfigurationCount
    '       Part.GetConfigurationNames
    sConfig = ""    'Default Config
    
    'Get Current Value of Property
    s1 = Part.CustomInfo2(sConfig, "RevNo")
    If Len(s1) = 0 Then
        MsgBox "RevNo is Not Set or Not Defined"
    Else
        MsgBox "RevNo: " & s1
    End If

    'Store the Custom Property
    '   AddCustomInfo3 returns True if Added
    '   if False, the property already exists
    '   In that case, just update the value
    s2 = "2"    'Define RevNo
    If Part.AddCustomInfo3(sConfig, "RevNo", swCustomInfoText, s2) = False Then
        Part.CustomInfo2(sConfig, "RevNo") = s2
    End If
    
    Set Part = Nothing
    Set swApp = Nothing

End Sub

Hope this helps...

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

RE: Adding Custom Properties

Oops!
Setting sConfig = "" in the above code will set the Custom Properties, not the Configuration Specific Properties. You'll note that there are two separate tabs on the File>Properties menu. If properties are defined in both windows, the Configuration Specific will be used.

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

RE: Adding Custom Properties

(OP)
Looks great.  Thanks a ton.  I have been fighting this for nearly a week now.

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