Apprecaite your help I am trying to write a macro to overwrite Flat pattern feature name using by custom properties. I am struggling retrieving the custom properties. this is what I have so far.
Option Explicit
Sub RenameFlatPatternFeatures()
' Declare SolidWorks application objects
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeature As SldWorks.Feature
Dim partNumber As String
Dim revisionNumber As String
Dim featureName As String
Dim newFeatureName As String
Dim flatPatternCount As Integer
Dim customPropMgr As SldWorks.CustomPropertyManager
Dim resolvedValue As String
Dim errors As Long
' Get the active SolidWorks application
Set swApp = Application.SldWorks
' Get the active model document
Set swModel = swApp.ActiveDoc
' Ensure a document is open
If swModel Is Nothing Then
MsgBox "No document is active!", vbCritical, "Error"
Exit Sub
End If
' Get the custom property manager for the active model
Set customPropMgr = swModel.Extension.CustomPropertyManager("")
' Retrieve the custom properties
'customPropMgr.Get2 "PartNo", resolvedValue, errors
'partNumber = resolvedValue
partNumber = "replace"
'customPropMgr.Get2 "DWRevisionNumber", resolvedValue, errors
'revisionNumber = resolvedValue
revisionNumber = "me"
' Initialize flat pattern count
flatPatternCount = 0
' Get the first feature
Set swFeature = swModel.FirstFeature
' Loop through all features in the model
Do While Not swFeature Is Nothing
' Check if the feature is a flat pattern
If swFeature.GetTypeName2 = "FlatPattern" Then
flatPatternCount = flatPatternCount + 1
' Get the original feature name
featureName = swFeature.Name
' Create the new feature name using the specified format
If Len(featureName) >= 2 Then
newFeatureName = partNumber & "-" & Left(featureName, 2) & "-R" & revisionNumber
Else
newFeatureName = partNumber & "-" & featureName & "-R" & revisionNumber ' Fallback if the feature name is too short
End If
' Rename the flat pattern feature
swFeature.Name = newFeatureName
End If
' Move to the next feature
Set swFeature = swFeature.GetNextFeature
Loop
' Notify user of changes made
'MsgBox flatPatternCount & " flat pattern features renamed.", vbInformation, "Renaming Complete"
End Sub
