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?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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