13 Replies Latest reply on Apr 18, 2018 9:42 AM by Jason Martin

    Create automatic sheet metal flat panel configurations?

    Jason Martin

      I have a sheet metal part but I was wondering if there was something that automatically gives every configuration a Flat_Pattern sub-configuration if it recognizes it as being a sheet metal part.

      It seems that I have placed a part in a drawing and selected the flat panel selection as a view at one time and it populated my whole sheet metal file with sub-configurations. I cannot for the life of me replicate this. I must be missing something that I've done to make this work.


      If there is no solution, is there a Macro that would work for this?

        • Re: Create automatic sheet metal flat panel configurations?
          Jason Martin

          So, I guess I found the macro I need to do this. But, I just need it to loop for each configuration.

          here is the Thread I found it from Re: Creating flat pattern configuration with help of macro

            • Re: Create automatic sheet metal flat panel configurations?
              Jason Martin

              So, here is my attempt to add the loop in. Now this macro works on any part my co worker sends me that is a sheet metal part. But, he gets an error when he runs it on his computer. I cannot understand what the problem is. The error is in the picture below.


              Dim swApp As SldWorks.SldWorks

              Dim swModel As SldWorks.ModelDoc2

              Dim swModel2 As SldWorks.ModelDoc2

              Dim swDraw As SldWorks.DrawingDoc

              Dim swConfig As SldWorks.Configuration

              Dim swFeature As SldWorks.Feature

              Dim swView As SldWorks.View

              Dim bSheetMetal As Boolean

              Dim iErrors As Long

              Dim sDrawingTemplate As String

              Dim vConfNameArr As Variant

              Dim sConfigName As String

              Dim nStart As Single

              Dim i As Long

              Dim bShowConfig As Boolean

              Dim bRet As Boolean



              Sub main()



              Set swApp = _




              If swApp.GetDocumentCount() = 0 Then Exit Sub



              Set swModel = swApp.ActiveDoc



              If swModel.GetType() = 2 Then Exit Sub



              If swModel.GetType() = 3 Then Exit Sub



              sDrawingTemplate = swApp.GetUserPreferenceStringValue(swUserPreferenceStringValue_e.swDefaultTemplateDrawing)



              If sDrawingTemplate = "" Then

                 MsgBox ("Error Retrieving Drawing Template")

                 Exit Sub

              End If



              bSheetMetal = False



              Set swFeature = swModel.FirstFeature



              Do While Not swFeature Is Nothing



                 If swFeature.GetTypeName2() = "SheetMetal" Then

                    bSheetMetal = True

                 End If



                 Set swFeature = swFeature.GetNextFeature






              If bSheetMetal = False Then

                 MsgBox ("This Macro Is For Sheet Metal Parts Only")

                 Exit Sub

              End If



              Set swApp = Application.SldWorks

                  Set swModel = swApp.ActiveDoc

                  Debug.Print "File = " + swModel.GetPathName

                  vConfNameArr = swModel.GetConfigurationNames

                  For i = 0 To UBound(vConfNameArr)

                      sConfigName = vConfNameArr(i)

                      bShowConfig = swModel.ShowConfiguration2(sConfigName)



              Set swModel2 = swApp.NewDocument(sDrawingTemplate, swDwgPaperSizes_e.swDwgPaperBsize, 0, 0)



              Set swDraw = swModel2



              Set swView = swDraw.CreateFlatPatternViewFromModelView3(swModel.GetPathName, sConfigName, 0, 0, 0, False, False)



              swModel.ForceRebuild3 (False)



              swApp.QuitDoc (swModel2.GetPathName)



              Set swModel = swApp.ActivateDoc3(swModel.GetPathName, False, swRebuildOnActivation_e.swUserDecision, iErrors)



              Next i



              End Sub


              the debugger shows this line being the problem.

            • Re: Create automatic sheet metal flat panel configurations?
              Arthur McRae

              I have been tasked with making a similar macro, I have not started yet.  I am watching this with great interest.  I have multi-body sheet metal parts as well.  I would also like to include a safe out to dxf as part of the macro for our uses.