8 Replies Latest reply on Mar 18, 2015 4:02 AM by Bill Florac

    Get Flat-Pattern Folder Feature (VBA)

    Charles Robin

      Hi everyone

      Im on SW2013

      i wanna get the sketch feature in the "Flat-Pattern Folder"

      Capture.PNG

      this example is not working: 2014 SOLIDWORKS API Help - Get Flat-Pattern Folder Feature Example (VBA)

      SW don't know "Dim flatPatternFolder As SldWorks.flatPatternFolder"

       

      Anyone have an Idea?

       

      Thank you

        • Re: Get Flat-Pattern Folder Feature (VBA)
          Deepak Gupta

          Seems like this API call was introduced in 2014 and hence may not work in 2013.

           

          You may check this example: Boundary Box Sketch (VBA)

          • Re: Get Flat-Pattern Folder Feature (VBA)
            Keith Rice

            The following code will get the second sketch feature in the Flat Pattern folder:

             

            Dim swApp As SldWorks.SldWorks
            Dim swModel As SldWorks.ModelDoc2
            Dim swFeat As SldWorks.Feature
            Dim swSubFeat As SldWorks.Feature
            Dim swFinalFeat As SldWorks.Feature
            Dim swSketch As SldWorks.Sketch
            Dim i As Integer
            
            Sub main()
                Set swFinalFeat = Nothing
                Set swApp = Application.SldWorks
                Set swModel = swApp.ActiveDoc
                
                For i = swModel.GetFeatureCount To 1 Step -1
                    Set swFeat = swModel.FeatureByPositionReverse(swModel.GetFeatureCount - i)
                    If Not swFeat Is Nothing Then
                        If swFeat.GetTypeName = "FlatPattern" Then
                            Set swSubFeat = swFeat.GetFirstSubFeature
                            Do While Not swSubFeat Is Nothing
                                If swSubFeat.GetTypeName = "ProfileFeature" Then
                                    Set swSketch = swSubFeat.GetSpecificFeature2
                                    If swSketch.IsBoundaryBoxSketch Then
                                        Set swFinalFeat = swSubFeat
                                        Exit For
                                    End If
                                End If
                                Set swSubFeat = swSubFeat.GetNextSubFeature
                            Loop
                        End If
                    End If
                Next i
                
                If Not swFinalFeat Is Nothing Then swApp.SendMsgToUser _
                    "Found flat pattern bounding box sketch: " & swFinalFeat.Name
            End Sub
            

             

            Keith

            SolidWorks API Tutorials

            • Re: Get Flat-Pattern Folder Feature (VBA)
              Charles Robin

              Thank you a lot Keith Rice & Bill Florac

               

              I just wanna get the dimension of the line inside the "Bounding-Box1"

               

              thank Bill to precise .GetSpecificFeature2 and to flatten the part.!

               

               

               

               

               

              Dim swApp As SldWorks.SldWorks
              Dim swModel As SldWorks.ModelDoc2
              Dim swFeat As SldWorks.Feature
              Dim swSubFeat As SldWorks.Feature
              Dim swFinalFeat As SldWorks.Feature
              Dim swSketch                As SldWorks.Sketch
              Dim NumLines                As Long
              Dim vLines                  As Variant
              
              
              
              Dim i As Integer, j As Integer
              
              Sub main()
                  Set swFinalFeat = Nothing
                  Set swApp = Application.SldWorks
                  Set swModel = swApp.ActiveDoc
                 
                  For i = swModel.GetFeatureCount To 1 Step -1
                      Set swFeat = swModel.FeatureByPositionReverse(swModel.GetFeatureCount - i)
                      If Not swFeat Is Nothing Then
                          If swFeat.GetTypeName = "FlatPattern" Then
                              j = 0
                              Set swSubFeat = swFeat.GetFirstSubFeature
                              Do While Not swSubFeat Is Nothing
                                  If swSubFeat.GetTypeName = "ProfileFeature" Then j = j + 1
                                  If j = 2 Then
                                      Set swFinalFeat = swSubFeat
                                      Exit For
                                  End If
                                  Set swSubFeat = swSubFeat.GetNextSubFeature
                              Loop
                          End If
                      End If
                  Next i
                 
                  If Not swFinalFeat Is Nothing Then
                      Debug.Print "Found flat pattern bounding box sketch: " & swFinalFeat.Name
                      Debug.Print swFinalFeat.GetType
                      swModel.SetBendState (swSMBendStateFlattened)
                      Set swSketch = swFinalFeat.GetSpecificFeature2
                          NumLines = swSketch.GetLineCount2(1) ' Exclude crosshatch lines
                     
              
              
                          Debug.Print "  NumLines = " & NumLines
                          vLines = swSketch.GetLines2(1) 'Exclude crosshatch lines
                     
                          For i = 0 To NumLines - 1
                     
                              Debug.Print "  Line(" & i & ")"
                     
                              Debug.Print "    type  = " & vLines(7 * i)
                     
                              Debug.Print "    start = (" & vLines(12 * i + 6) * 1000# & "," & vLines(12 * i + 7) * 1000# & "," & vLines(12 * i + 8) * 1000# & ") mm"
                     
                              Debug.Print "    end  = (" & vLines(12 * i + 9) * 1000# & "," & vLines(12 * i + 10) * 1000# & "," & vLines(12 * i + 11) * 1000# & ") mm"
                             
                              Debug.Print "    lg    =  " & Sqr((vLines(12 * i + 9) - vLines(12 * i + 6)) ^ 2 + (vLines(12 * i + 10) - vLines(12 * i + 7)) ^ 2) * 1000
                             
                              Debug.Print "    "
                          Next i
              
              
                          swModel.EditRebuild3
                  End If
                
              End Sub