2 Replies Latest reply on Dec 11, 2013 3:47 PM by Michael Caulton

    API SetBendState and FlatPatten giving weird results

    Michael Caulton

      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

      Test 1 - Step 1.JPG

           Step 2: Click sheetmetel flatten button

      Test 1 - Step 2.JPG

           Result: Everything behaves normally as expected and the part flattens.

       

      Test 2: Using attached macro "flatten sheetmetel part".


           Step 1: Open part

      Test 2 - Step 1.JPG

           Step 2: Run macro

      Test 2 - Step 2.JPG

       

           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

      Test 3 - Step 1.JPG

           Step 2: Run macro but debug pause before the second rebuild

      Test 3 - Step 2.JPG

           Step 3: Run second rebuild.

      Test 3 - Step 3.JPG

       

           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-<EdgeBend3>1

      Flatten-<EdgeBend4>1

      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?