using api function FlatPatternFeatureData.SimplifyBends
using api function FlatPatternFeatureData.SimplifyBends
(OP)
I want to change the flatpattern option "simplified bends" from a sheet metal part by means of a visual basic program.
This does not work.
Sample of the code used:
This does not work.
Sample of the code used:
CODE
Option Explicit
Public SwApp As SldWorks.SldWorks
Public swDoc As ModelDoc2
Public SettingsStored As Boolean
Private Sub Form_Load()
Dim DocType As Integer
Dim strDXFLocation As String
Dim CompPathName As String
Dim ConfigName As String
Dim strOrigFile As String
Dim strFileToDxf As String
Dim blConvertedAllFeatures As Boolean
Dim featureCount As Long
Dim Feature As Feature
Dim featureName As String
Dim FeatureType As String
Dim swFlatPattern As FlatPatternFeatureData
'--check if document open
CheckForSWDocument
ProgressInfo ("Connecting to SolidWorks")
If InitSolidWorks(SwApp) Then
'## Retieving active Document ##
ProgressInfo ("Retrieving active document")
Set swDoc = SwApp.ActiveDoc
If Not swDoc Is Nothing Then
DocType = swDoc.GetType
'## Auto Converter works only on Parts ##
ProgressInfo ("Checking open document type")
If (DocType = swDocPART) Then
'## Resolve lightweight components ##
CheckForLightWeightComponents
'## Retrieving information from active document ##
ProgressInfo " Document naam = " & GetDocName(swDoc.GetPathName) & " Configuratie = " & swDoc.GetActiveConfiguration.Name
Else
ProgressInfo "AutoDXFConverter works only on Parts."
Exit Sub
End If
End If
Else
ProgressInfo ("Could not connect to SolidWorks")
End If
'--check if it is a sheet metal part
Dim swBendState As Integer
swBendState = swDoc.GetBendState
If swBendState = swSMBendStateNone Then
EndProgram
ProgressInfo ("This is NO sheetmetal part.")
Exit Sub
End If
blConvertedAllFeatures = True
featureCount = swDoc.GetFeatureCount
ProgressInfo ("Nr. of features in part: " & featureCount)
Set Feature = swDoc.FirstFeature
featureCount = 1
While Not Feature Is Nothing
featureName = Feature.Name
FeatureType = Feature.GetTypeName
ProgressInfo featureName
'--turn off simplified bends in flat pattern feature
If UCase(FeatureType) = UCase("flatpattern") Then
Set swFlatPattern = Feature.GetDefinition
ProgressInfo "status = " & Feature.GetDefinition.SimplifyBends
Feature.GetDefinition.SimplifyBends = False
End If
'-- after the previous lines the flatpattern option should be changed. Only it isn't.
Set Feature = Feature.GetNextFeature
featureCount = featureCount + 1
Wend
ProgressInfo "Done!"
'Unload Me
Exit Sub
ErrExit:
MsgBox Err.Description
EndProgram
End Sub
Public SwApp As SldWorks.SldWorks
Public swDoc As ModelDoc2
Public SettingsStored As Boolean
Private Sub Form_Load()
Dim DocType As Integer
Dim strDXFLocation As String
Dim CompPathName As String
Dim ConfigName As String
Dim strOrigFile As String
Dim strFileToDxf As String
Dim blConvertedAllFeatures As Boolean
Dim featureCount As Long
Dim Feature As Feature
Dim featureName As String
Dim FeatureType As String
Dim swFlatPattern As FlatPatternFeatureData
'--check if document open
CheckForSWDocument
ProgressInfo ("Connecting to SolidWorks")
If InitSolidWorks(SwApp) Then
'## Retieving active Document ##
ProgressInfo ("Retrieving active document")
Set swDoc = SwApp.ActiveDoc
If Not swDoc Is Nothing Then
DocType = swDoc.GetType
'## Auto Converter works only on Parts ##
ProgressInfo ("Checking open document type")
If (DocType = swDocPART) Then
'## Resolve lightweight components ##
CheckForLightWeightComponents
'## Retrieving information from active document ##
ProgressInfo " Document naam = " & GetDocName(swDoc.GetPathName) & " Configuratie = " & swDoc.GetActiveConfiguration.Name
Else
ProgressInfo "AutoDXFConverter works only on Parts."
Exit Sub
End If
End If
Else
ProgressInfo ("Could not connect to SolidWorks")
End If
'--check if it is a sheet metal part
Dim swBendState As Integer
swBendState = swDoc.GetBendState
If swBendState = swSMBendStateNone Then
EndProgram
ProgressInfo ("This is NO sheetmetal part.")
Exit Sub
End If
blConvertedAllFeatures = True
featureCount = swDoc.GetFeatureCount
ProgressInfo ("Nr. of features in part: " & featureCount)
Set Feature = swDoc.FirstFeature
featureCount = 1
While Not Feature Is Nothing
featureName = Feature.Name
FeatureType = Feature.GetTypeName
ProgressInfo featureName
'--turn off simplified bends in flat pattern feature
If UCase(FeatureType) = UCase("flatpattern") Then
Set swFlatPattern = Feature.GetDefinition
ProgressInfo "status = " & Feature.GetDefinition.SimplifyBends
Feature.GetDefinition.SimplifyBends = False
End If
'-- after the previous lines the flatpattern option should be changed. Only it isn't.
Set Feature = Feature.GetNextFeature
featureCount = featureCount + 1
Wend
ProgressInfo "Done!"
'Unload Me
Exit Sub
ErrExit:
MsgBox Err.Description
EndProgram
End Sub






RE: using api function FlatPatternFeatureData.SimplifyBends
- get access to the feature selections
- change the option
- modify the definition to update the feature with the new option
You are missing the first and last items in the list. I think your if statement should be:CODE
If UCase(FeatureType) = UCase("flatpattern") Then
Set swFlatPattern = Feature.GetDefinition
ProgressInfo "status = " & Feature.GetDefinition.SimplifyBends
bRet = swFlatPattern.AccessSelections(swDoc, Nothing)
swFlatPattern.SimplifyBends = False
bRet = Feature.ModifyDefinition(swFlatPattern, swDoc, Nothing)
End If
RE: using api function FlatPatternFeatureData.SimplifyBends
I changed the code as You stated and it works fine now.