15 Replies Latest reply on May 28, 2018 5:01 PM by Nilesh Patel Branched to a new discussion.

    Get thickness of sheetmetal part without selecting any face

    Yash Kothari

      I am working on a program to save DXF file into separate thickness wise folders(if it is there else create new folder). To get started i first need to get the thickness of part, and for that i found a program from one of forums, but when i select any face other than the base flange face, it gives me debug error, I am thinking if i can get the thickness without selecting any face. The program is:

       

      Option Explicit
      
      
      Sub main()
      
      
          Dim swApp                   As SldWorks.SldWorks
          Dim swModel                 As SldWorks.ModelDoc2
          Dim vConfNameArr            As Variant
          Dim sConfigName             As String
          Dim nStart                  As Single
          Dim i                       As Long
          Dim bShowConfig             As Boolean
          Dim bRebuild                As Boolean
          Dim bRet                    As Boolean
         
          Dim swsel As SldWorks.SelectionMgr
          Dim swface As SldWorks.Face2
          Dim swfeature As SldWorks.Feature
          Dim swfeaturedata As Object
          Dim Thickness As String
          
         
      
      
          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          
          Set swsel = swModel.SelectionManager
          Set swface = swsel.GetSelectedObject(1)
          Set swfeature = swface.GetFeature
          Set swfeaturedata = swfeature.GetDefinition
      
      
          Thickness = swfeaturedata.Thickness
      
      
          swApp.SendMsgToUser "Sheet Thickness" & " " & Thickness * 1000 & "mm"
      
      
            
      
      
          vConfNameArr = swModel.GetConfigurationNames
      
      
          For i = 1 To UBound(vConfNameArr)
      
      
              sConfigName = vConfNameArr(i)
      
      
              
      bShowConfig = swModel.ShowConfiguration2(sConfigName)
      
      
      bRebuild = swModel.ForceRebuild3(False)
      
      
      Dim FilePath As String
      Dim PathSize As Long
      Dim PathNoExtension As String
      Dim NewFilePath As String
      
      
      FilePath = swModel.GetPathName
      PathSize = Strings.Len(FilePath)
      PathNoExtension = Strings.Left(FilePath, PathSize - 6)
      
      
      
      
      NewFilePath = PathNoExtension + sConfigName & ".DXF"
      
      
      'Export Flat Pattern
      bRet = swModel.ExportFlatPatternView(NewFilePath, swExportFlatPatternOption_None)
      
      
      Next i
      
      
      End Sub
      

       

      I succeeded in getting sheet thickness, but i want it without selecting any face.

       

      Thanks

        • Re: Get thickness of sheetmetal part without selecting any face
          Nilesh Patel

          Hi Yash,

           

          Have a look at the attached macro. It displays message with sheet metal feature name and the thickness. It also works for both old and new style sheet metal parts. You don't need to select anything in the model. I made an assumption that you have only one feat metal feature in your part, if not then you will need to modify the macro to suit your needs.

           

          Regards,

          Nilesh

            • Re: Get thickness of sheetmetal part without selecting any face
              Yash Kothari

              Hi Nilesh

              Thanks for the code, it worked fine and sorry for the delayed response due to weekend.

              What is 'one feat metal feature'. Is it one body sheet metal or one feature(e.g extrude, cut etc) sheet metal.

              I am going to put this code into my main code, where I am saving DXF files into separate thickness wise folders. Give me some time, I will post that code here.

              • Re: Get thickness of sheetmetal part without selecting any face
                Yash Kothari

                The program is little tricky(for me) but worked perfectly. My final program after embedding yours into others, is written here. Though I am done with the macro, any suggestions would be appreciated.

                 

                Option Explicit
                
                
                Sub main()
                
                
                    Dim swApp                   As SldWorks.SldWorks
                    Dim swModel                 As SldWorks.ModelDoc2
                    Dim vConfNameArr            As Variant
                    Dim sConfigName             As String
                    ' Dim nStart                  As Single
                    Dim i                       As Long
                    Dim bShowConfig             As Boolean
                    Dim bRebuild                As Boolean
                    Dim bRet                    As Boolean
                   
                    Dim swFeatMgr               As FeatureManager
                    Dim swFeat                  As Feature
                    Dim swSheetMetalFol         As SheetMetalFolder
                    Dim swSheetFeatData         As SheetMetalFeatureData
                    Dim swBaseFlangeFeatData    As BaseFlangeFeatureData
                    Dim vSheetMetalFeat         As Variant
                    
                    
                    Dim ThicknessM As String
                    
                
                
                    Set swApp = Application.SldWorks
                    Set swModel = swApp.ActiveDoc
                    
                        Set swFeatMgr = swModel.FeatureManager
                    Set swSheetMetalFol = swFeatMgr.GetSheetMetalFolder
                    
                    If Not swSheetMetalFol Is Nothing Then
                        vSheetMetalFeat = swSheetMetalFol.GetSheetMetals
                        For i = 0 To UBound(vSheetMetalFeat)
                            Set swFeat = vSheetMetalFeat(i)
                            If swFeat.GetTypeName2 = "SheetMetal" Then
                                Set swSheetFeatData = swFeat.GetDefinition
                                ' swApp.SendMsgToUser2 "Sheet Metal Feat Name: " & swFeat.Name & "     Thickness: " & swSheetFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                swApp.SendMsgToUser2 "Thickness: " & swSheetFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                Exit For
                            End If
                        Next i
                    Else
                        Set swFeat = swModel.FirstFeature
                        Do While Not swFeat Is Nothing
                            If swFeat.GetTypeName2 = "SMBaseFlange" Then
                                Set swBaseFlangeFeatData = swFeat.GetDefinition
                                swApp.SendMsgToUser2 "Sheet Metal Feat Name: " & swFeat.Name & "     Thickness: " & swBaseFlangeFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                swApp.SendMsgToUser2 "Thickness: " & swBaseFlangeFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                Exit Do
                            ElseIf swFeat.GetTypeName2 = "SheetMetal" Then
                                Set swSheetFeatData = swFeat.GetDefinition
                                ' swApp.SendMsgToUser2 "Sheet Metal Feat Name: " & swFeat.Name & "     Thickness: " & swSheetFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                swApp.SendMsgToUser2 "Thickness: " & swSheetFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                Exit Do
                            End If
                            Set swFeat = swFeat.GetNextFeature
                        Loop
                    End If
                    
                    ThicknessM = swSheetFeatData.Thickness * 1000
                    
                    Dim Qty As String
                        
                    Qty = InputBox("Enter number of parts to process")
                        
                    If Qty = "" Then
                        Qty = 1
                    Else
                        Qty = Qty
                    End If
                    
                    ' Debug.Print Qty
                    
                           
                        bShowConfig = swModel.ShowConfiguration2(sConfigName)
                        bRebuild = swModel.ForceRebuild3(False)
                
                
                    Dim FilePath As String
                    Dim PathSize As Long
                    Dim PathNoExtension As String
                    Dim NewFilePath As String
                
                
                        FilePath = swModel.GetPathName
                        PathSize = Strings.Len(FilePath)
                        PathNoExtension = Strings.Left(FilePath, PathSize - 7)
                        
                    Dim pos As Integer
                    Dim FileName As String
                        
                        pos = InStrRev(swModel.GetPathName, "\")
                        FileName = Mid(swModel.GetPathName, pos + 1, Len(swModel.GetPathName) - pos - 7)
                        ' Debug.Print FileName; vbTab
                        
                    Dim NewFilePath2 As String
                    Dim CrtFldr As String
                        
                        CrtFldr = Mid(PathNoExtension, 1, Len(PathNoExtension) - Len(FileName)) + "DXF"
                        ' Debug.Print CrtFldr
                        
                    If Len(Dir(CrtFldr, vbDirectory)) = 0 Then
                        MkDir CrtFldr
                    End If
                                
                    CrtFldr = Mid(PathNoExtension, 1, Len(PathNoExtension) - Len(FileName)) + "DXF\" + ThicknessM + "mm"
                        
                    If Len(Dir(CrtFldr, vbDirectory)) = 0 Then
                        MkDir CrtFldr
                    End If
                      
                       
                        NewFilePath2 = Mid(PathNoExtension, 1, Len(PathNoExtension) - Len(FileName)) + "DXF\" + ThicknessM + "mm" + "\" + FileName + "_Qty_" + Qty + ".DXF"
                        ' Debug.Print NewFilePath2
                   
                        'Export Flat Pattern
                        bRet = swModel.ExportFlatPatternView(NewFilePath2, swExportFlatPatternOption_None)
                        
                        ' Debug.Print sConfigName; vbTab; FilePath; vbTab; PathSize; vbTab; PathNoExtension; vbTab; NewFilePath
                
                
                
                
                End Sub
                         
                
              • Re: Get thickness of sheetmetal part without selecting any face
                Amen Allah Jlili

                Yash,

                 

                Assuming your part is a single bodied sheet metal part, you can get the thickness via the ISheetMetalFeatureData::Thickness property. The value will be supplied in meters however. Traverse the feature tree features using IModelDoc2::FeatureManager::GetFeatures until you hit the sheet metal feature. Use IFeature::GetDefinition to get the ISheetMetalFeatureData object. Now, you have the thickness of your part.

                 

                If you have a multiple-bodied part, then, things are a little different but the base logic is the same.

                 

                Best,
                Amen

                SolidWorks API Video Tutorials

                • Re: Get thickness of sheetmetal part without selecting any face
                  Kevin Chandler

                  Hello,

                   

                  I don't know if this will make for simpler code, but sheet metal thickness is always stored as the global variable "Thickness" in the part's units.

                   

                  Cheers,

                   

                  Kevin

                  • Re: Get thickness of sheetmetal part without selecting any face
                    Yash Kothari

                    Thanks all for help. My final program is written here. Any more suggestions are most appreciated. Please try this program and review it and do share feedback, so that it can be used efficiently. Thanks Nilesh patel for Thickness program.

                     

                     

                    Option Explicit
                    
                    
                    Sub main()
                    
                    
                        Dim swApp                   As SldWorks.SldWorks
                        Dim swModel                 As SldWorks.ModelDoc2
                        Dim vConfNameArr            As Variant
                        Dim sConfigName             As String
                        ' Dim nStart                  As Single
                        Dim i                       As Long
                        Dim bShowConfig             As Boolean
                        Dim bRebuild                As Boolean
                        Dim bRet                    As Boolean
                       
                        Dim swFeatMgr               As FeatureManager
                        Dim swFeat                  As Feature
                        Dim swSheetMetalFol         As SheetMetalFolder
                        Dim swSheetFeatData         As SheetMetalFeatureData
                        Dim swBaseFlangeFeatData    As BaseFlangeFeatureData
                        Dim vSheetMetalFeat         As Variant
                        
                        
                        Dim ThicknessM As String
                        
                    
                    
                        Set swApp = Application.SldWorks
                        Set swModel = swApp.ActiveDoc
                        
                            Set swFeatMgr = swModel.FeatureManager
                        Set swSheetMetalFol = swFeatMgr.GetSheetMetalFolder
                        
                        If Not swSheetMetalFol Is Nothing Then
                            vSheetMetalFeat = swSheetMetalFol.GetSheetMetals
                            For i = 0 To UBound(vSheetMetalFeat)
                                Set swFeat = vSheetMetalFeat(i)
                                If swFeat.GetTypeName2 = "SheetMetal" Then
                                    Set swSheetFeatData = swFeat.GetDefinition
                                    ' swApp.SendMsgToUser2 "Sheet Metal Feat Name: " & swFeat.Name & "     Thickness: " & swSheetFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                    swApp.SendMsgToUser2 "Thickness: " & swSheetFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                    Exit For
                                End If
                            Next i
                        Else
                            Set swFeat = swModel.FirstFeature
                            Do While Not swFeat Is Nothing
                                If swFeat.GetTypeName2 = "SMBaseFlange" Then
                                    Set swBaseFlangeFeatData = swFeat.GetDefinition
                                    swApp.SendMsgToUser2 "Sheet Metal Feat Name: " & swFeat.Name & "     Thickness: " & swBaseFlangeFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                    swApp.SendMsgToUser2 "Thickness: " & swBaseFlangeFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                    Exit Do
                                ElseIf swFeat.GetTypeName2 = "SheetMetal" Then
                                    Set swSheetFeatData = swFeat.GetDefinition
                                    ' swApp.SendMsgToUser2 "Sheet Metal Feat Name: " & swFeat.Name & "     Thickness: " & swSheetFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                    swApp.SendMsgToUser2 "Thickness: " & swSheetFeatData.Thickness * 1000 & "mm.", swMessageBoxIcon_e.swMbInformation, swMessageBoxBtn_e.swMbOk
                                    Exit Do
                                End If
                                Set swFeat = swFeat.GetNextFeature
                            Loop
                        End If
                        
                        ThicknessM = swSheetFeatData.Thickness * 1000
                        
                        Dim Qty As String
                            
                        Qty = InputBox("Enter number of parts to process")
                            
                        If Qty = "" Then
                            Qty = 1
                        Else
                            Qty = Qty
                        End If
                        
                        ' Debug.Print Qty
                        
                               
                            bShowConfig = swModel.ShowConfiguration2(sConfigName)
                            bRebuild = swModel.ForceRebuild3(False)
                    
                    
                        Dim FilePath As String
                        Dim PathSize As Long
                        Dim PathNoExtension As String
                        Dim NewFilePath As String
                    
                    
                            FilePath = swModel.GetPathName
                            PathSize = Strings.Len(FilePath)
                            PathNoExtension = Strings.Left(FilePath, PathSize - 7)
                            
                        Dim pos As Integer
                        Dim FileName As String
                            
                            pos = InStrRev(swModel.GetPathName, "\")
                            FileName = Mid(swModel.GetPathName, pos + 1, Len(swModel.GetPathName) - pos - 7)
                            ' Debug.Print FileName; vbTab
                            
                        Dim NewFilePath2 As String
                        Dim CrtFldr As String
                            
                            CrtFldr = Mid(PathNoExtension, 1, Len(PathNoExtension) - Len(FileName)) + "DXF"
                            ' Debug.Print CrtFldr
                            
                        If Len(Dir(CrtFldr, vbDirectory)) = 0 Then
                            MkDir CrtFldr
                        End If
                                    
                        CrtFldr = Mid(PathNoExtension, 1, Len(PathNoExtension) - Len(FileName)) + "DXF\" + ThicknessM + "mm"
                            
                        If Len(Dir(CrtFldr, vbDirectory)) = 0 Then
                            MkDir CrtFldr
                        End If
                          
                           
                            NewFilePath2 = Mid(PathNoExtension, 1, Len(PathNoExtension) - Len(FileName)) + "DXF\" + ThicknessM + "mm" + "\" + FileName + "_Qty_" + Qty + ".DXF"
                            ' Debug.Print NewFilePath2
                       
                            'Export Flat Pattern
                            bRet = swModel.ExportFlatPatternView(NewFilePath2, swExportFlatPatternOption_None)
                            
                            ' Debug.Print sConfigName; vbTab; FilePath; vbTab; PathSize; vbTab; PathNoExtension; vbTab; NewFilePath
                    
                    
                    
                    
                    End Sub