3 Replies Latest reply on Mar 31, 2018 2:17 AM by Nilesh Patel

    Bended part flatening script does not work

    Edgars Baumanis

      Hi!

       

      I have been using ready script that I found on the internet as part of my own macro, but today I noticed that it doesn't do the job that it is supposed to do.

      I have two example parts, they are very similar, but it might be that they are made with different Solidworks versions - that is why the script works for some parts, but for some it doesn't. In the attachment there are two pats - "part1" where the script is working and "part2" where the script is not working for some reason.

      Can someone help me get this script working for both parts?

       

       

      The script

      Option Explicit

       

      Public Enum swSMBendState_e

       

          swSMBendStateNone = 0       '  No bend state - not a sheet metal part

       

          swSMBendStateSharps = 1     '  Bends are in the sharp state - bends currently not applied

       

          swSMBendStateFlattened = 2  '  Bends are flattened

       

          swSMBendStateFolded = 3     '  Bends are fully applied

       

      End Enum

       

      Public Enum swSMCommandStatus_e

       

          swSMErrorNone = 0               '  No errors

       

          swSMErrorUnknown = 1            '  Failed for an unknown reason

       

          swSMErrorNotAPart = 2           '  Sheet metal commands only apply to SolidWorks parts

       

          swSMErrorNotASheetMetalPart = 3 '  Part contains no sheet metal features

       

          swSMErrorInvalidBendState = 4   '  Invalid bend state was specified

       

      End Enum

       

      Sub main()

       

          Dim swApp               As SldWorks.SldWorks

       

          Dim swModel             As SldWorks.ModelDoc2

       

          Dim nBendState          As Long

       

          Dim nRetVal             As Long

       

          Dim bRet                As Boolean

       

          Set swApp = CreateObject("SldWorks.Application")

       

          Set swModel = swApp.ActiveDoc

       

         

       

          nBendState = swModel.GetBendState

       

         

       

          Debug.Print "File = " & swModel.GetPathName

       

          Debug.Print "  BendState    = " & nBendState

       

         

       

          If nBendState <> swSMBendStateFlattened Then

       

              nRetVal = swModel.SetBendState(swSMBendStateFlattened)

       

              Debug.Print "  SetBendState = " & nRetVal

       

             

       

              ' Rebuild to see changes

       

              bRet = swModel.EditRebuild3: Debug.Assert bRet

       

          End If

       

      End Sub

       

        • Re: Bended part flatening script does not work
          Nilesh Patel

          Try attached macro. I will work on any sheet metal part.

            • Re: Bended part flatening script does not work
              Edgars Baumanis

              Thank you.

               

              Indeed it works for both parts now. However, there is problem. Basically I have made macro that opens up assembly, then goes through every file looking for sheet metal parts and reads their dimensions. If the sheet metal is bended, then it needs to be unfolded, so the macro can read its true dimensions as sheet metal, not as bended part.

               

              The problem is that with this new script included, it takes 1 minute 19 seconds to execute. With the old script it executes in 4,84s.

              I guess it is because the new script is also looking for each parts flat pattern folder? Is there some other way to do this?

                • Re: Bended part flatening script does not work
                  Nilesh Patel

                  Hi Edgards,

                   

                  Parts created in SW2014 and later will have 'Flat- Pattern' folder if it is a sheet metal part. Also 'SetBendState' only works on parts that are old style sheet-metal parts or non-sheet metal parts converted to sheet metal. If you have part that has a 'Base-Flange' as first feature 'SetBendState' won't work and if the part is created in SW2013, it won't have 'Flat- Pattern' folder either. In this case, you will have to loop through all features in the part until you find 'Flat-Patern' feature and then un-supress it.

                   

                  Hope this make sense. This is the reason why it takes more time to run.

                   

                  Your macro only took 4.84 seconds because it would have only processed old style sheet metal parts or non-sheet metal parts converted to sheet metal. It would have skipped new style sheet metal parts.

                   

                  Regards,

                  Nilesh Patel