Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Custom Properties 1

Status
Not open for further replies.

JpPhysics

Mechanical
Mar 25, 2002
35
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?
 
Replies continue below

Recommended for you

Here is some sample code to get you started. Updates the active document (part, drawing or assembly).
Code:
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.
 
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.
 
Looks great. Thanks a ton. I have been fighting this for nearly a week now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor