Using SW 2010 SP5
If I record a macro for clicking the flatten sheetmetel button it gives me the result below as the code I need to use.
longstatus = Part.SetBendState(2)
boolstatus = Part.EditRebuild3()
So from this I have been using the code below to flatten parts that are sheetmetel in a macro we run which I believe is exactly the same thing but I get really weird results.
BendState = swModel.SetBendState(swSMBendState_e.swSMBendStateFlattened) ' Flatten part
bRebuild = swModel.EditRebuild3()
All testing done on attached part HPW023-1.SLDPRT which is a known problem part, i.e. doesn’t behave as expected while others do.
Test 1: Using built in SW sheetmetel flatten button
Step 1: Open part
Step 2: Click sheetmetel flatten button
Result: Everything behaves normally as expected and the part flattens.
Test 2: Using attached macro "flatten sheetmetel part".
Step 1: Open part
Step 2: Run macro
Result: SM flatten button looks to be activated but the part is not flattened. The name of the flat pattern has now also changed from Flat-Pattern1 from Flat-Pattern2.
Test 3: Modify EditRebuild3 to be ForceRebuild3 and run the rebuild twice.
BendState = swModel.SetBendState(swSMBendState_e.swSMBendStateFlattened)
bRebuild = swModel.ForceRebuild3(False)
bRebuild = swModel.ForceRebuild3(False)
Step 1: Open part
Step 2: Run macro but debug pause before the second rebuild
Step 3: Run second rebuild.
Result: After first rebuild everything appears to be the same as Test 2 with the name changing to Flat-Patten2 and the part not flattening but then once the second rebuild is run the name corrects itself and the part flattens.
Test 4: Check what’s in the feature tree
Step 1: Open part
Step 2: Run macro "list all features in tree"
Debugger output:
FName: Flat-Pattern1 (FType: FlatPattern)
SubFeatures:
Bend-Lines1
Sketch Transformation1
Flatten-
Flatten-
FName: Flat-Pattern2 (FType: FlatPattern)
SubFeatures:
Bend-Lines2
Result: Above shows that there appears to be a second flatpattern that is in the part data but not normally visible in the SW GUI.
Am I doing something wrong or does anyone have any ideas how I can get all parts flattened reliably without doing two ForceRebuild3 and hoping it’s going to always work?
SolidworksApi macros