14 Replies Latest reply on Aug 5, 2015 9:16 AM by Hrituc Alexandru

    Sheet metal parts in assembly...

    Hrituc Alexandru

      Hi everyone,

      i want to create a macro starting from this example of Lenny... I have a macro that run to each sheet metal part selected but it's hard to select direct from assembly or from design tree.. a list with sheet metal part it's perfect. in design tree appear many configs of the same parts and it.s hard to select...i hope to be easy to archieve it

      thanks

      1.jpg

        • Re: Sheet metal parts in assembly...
          Hrituc Alexandru

          it is so difficult to make a list with sheet metal parts from assembly??

           

          I found this macro and i modify it to make drawing for every sheet metal part from assembly but it's a problem...If a part has more config active in assembly, the macro make drawing with each in part and i want to make only one time!... to filename for example

           

          ex:  assembly 1

                sheet metal part 1 - config 1

                sheet metal part 1-  config 2

                sheet metal part 2

                sheet metal part 3 .....etc

           

          When i run the macro, I want to make 3 drawings: one for sheet metal part 1

                                                                                          one for sheet metal part 2

                                                                                          one for sheet metal part 3

          • Re: Sheet metal parts in assembly...
            Hrituc Alexandru

            how can modify this macro to activate in that list only sheet metal parts?

            1.jpg

              • Re: Sheet metal parts in assembly...
                Tapani Sjoman

                Set criteria this way:

                1. must be a part

                2. if TemplateSheetmetal -feature exist

                then should be a SheetMetal part -> select this one.

                 

                I'm not really sure if this is the right way but seemed to work for me :-)

                  • Re: Sheet metal parts in assembly...
                    Hrituc Alexandru

                    working and to me!

                    Thank you very much

                    • Re: Sheet metal parts in assembly...
                      Hrituc Alexandru

                      "if TemplateSheetmetal -feature exist

                      then should be a SheetMetal part -> select this one."

                      What should introduce a more precisely???

                      It not work in every assembly... here from example it appear nothing and exist 2 sheet metal parts

                       

                      1.jpg

                      • Re: Sheet metal parts in assembly...
                        Hrituc Alexandru

                        Hi,

                        This code found all sheet metal parts but i don't know how to integrate in your code..

                        Look over what is with bold in next code:

                         

                        Private Sub CommandButton1_Click()

                        Dim swApp                       As SldWorks.SldWorks

                           Dim swModel                     As SldWorks.ModelDoc2

                           Dim swAssy                      As SldWorks.AssemblyDoc

                           Dim swConf                      As SldWorks.Configuration

                           Dim swRootComp                  As SldWorks.Component2

                           Dim nStart                      As Single

                           Dim bRet                        As Boolean

                         

                           Set swApp = Application.SldWorks

                           Set swModel = swApp.ActiveDoc

                           Set swConf = swModel.GetActiveConfiguration

                           Set swRootComp = swConf.GetRootComponent3(True)

                         

                           Debug.Print "File = " & swModel.GetPathName

                         

                           TraverseComponent swRootComp, 1

                         

                           Debug.Print "Finished!"

                         

                        End Sub

                         

                         

                        Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)

                         

                         

                        Dim vChildComp                  As Variant

                         

                         

                           Dim swApp                       As SldWorks.SldWorks

                           Dim swpart                      As SldWorks.PartDoc

                         

                           Dim swChildComp                 As SldWorks.Component2

                           Dim swConfig                    As SldWorks.Configuration

                           Dim swConfMgr                   As SldWorks.ConfigurationManager

                           Dim swChildModel                As SldWorks.ModelDoc2

                           Dim swOpenModel                 As SldWorks.ModelDoc2

                         

                           Dim swChildCustPropMngr         As CustomPropertyManager

                           Dim swChildModelDocExt          As ModelDocExtension

                           Dim swsheetmetal                As SldWorks.SheetMetalFeatureData

                           Dim swFeat                      As SldWorks.Feature

                           Dim swBody                      As SldWorks.Body2

                         

                         

                           Dim Sheet_metal                 As Boolean

                           Dim Boolstatus                  As Boolean

                            

                           Dim Thickness                   As Double

                           Dim conv                        As Double

                         

                         

                           Dim i                           As Long

                           Dim loptions                    As Long

                           Dim lerrors                     As Long

                         

                         

                           Dim sPadStr                     As String

                           Dim FilePath                    As String

                           Dim FileName                    As String

                           Dim swThkDir                    As String

                           Dim swMatDir                    As String

                           Dim swCurrent                   As String

                           Dim RefCfg                      As String

                           Dim ChildConfigName             As String

                           Dim sMatName                    As String

                           Dim sMatDB                      As String

                           Dim exFileName                  As String

                         

                           Dim Bodies                      As Variant

                           Dim Number As String

                         

                           vChildComp = swComp.GetChildren

                         

                         

                           For i = 0 To UBound(vChildComp)

                               Set swChildComp = vChildComp(i)

                            

                               'Check to see if current component is suppressed

                               If swChildComp.IsSuppressed = False Then GoTo Active Else GoTo Skip

                            

                        Active:

                        Set swApp = Application.SldWorks

                         

                         

                        Set swChildModel = swChildComp.GetModelDoc2

                           'Check to see if child component is an Assembly or part

                           If (swChildModel.GetType <> swDocPART) Then GoTo Jump 'Skips Subassemby level

                         

                         

                        Set swpart = swChildModel 'Applies part commands for current component

                         

                         

                        FilePath = Left(swComp.GetPathName, InStrRev(swComp.GetPathName, "\") - 1)

                         

                        FileName = swChildModel.GetTitle 'Get title of component

                        swCurrent = swChildComp.ReferencedConfiguration 'Get current configuration of component

                         

                         

                        Bodies = swpart.GetBodies2(swBodyType_e.swAllBodies, True)

                        Set swBody = Bodies(0)

                         

                         

                           If swBody.IsSheetMetal = 0 Then 'If Body is not sheet metal

                         

                         

                               'Debug.Print "Component " & FileName & " is not a sheet metal component"

                               'Debug.Print "Current Config is : "; swCurrent

                                   GoTo Jump

                           End If

                         

                           If swBody.IsSheetMetal = 1 Then 'If body is sheet metal

                         

                         

                               Debug.Print "Processing component " & FileName & " as a sheet metal component"

                               Debug.Print "Current Config is : "; swCurrent

                         

                        UserForm1.ListBox1.AddItem FileName, 0

                               UserForm1.ListBox1.ListIndex = 0

                               GoTo Process

                           End If

                         

                         

                        Process:

                         

                         

                         

                         

                         

                               

                        GoTo Jump

                               

                        Skip:

                         

                         

                           Debug.Print "Skipped"

                         

                         

                        Jump:

                               TraverseComponent swChildComp, nLevel + 1

                                  Next i

                         

                         

                        End Sub

                    • Re: Sheet metal parts in assembly...
                      Hrituc Alexandru

                      I think, to check if a part is sheet metal, should be made more verification criteria : if have flat pattern, or if have flatten or bounding box and other specific features ...

                      For example: to seek in all levels inside the assembly "flat pattern" and if found to bring in the list the names of parts which have inside flat pattern