6 Replies Latest reply on Oct 31, 2017 11:39 AM by Huseyin Ata

    Macro to export PDF's, Sheet metal DXF's & Sheet Metal BoM

    Simon Rafferty

      Thought this might be useful to some of you.

      If you open an assembly and run the macro, it will export PDF's of any drawings (in the same folder as the Assembly) then find all the parts with Sheet Metal.

      It exports a DXF file for the unfolded flat pattern and builds a BoM as a CSV for just the sheet metal parts.

        

      PART NAME MATERIAL THICKNESS(mm) QUANTITY
      Part1.DXF1060 Alloy61
      Part2.DXF1060 Alloy61
      Another Part.DXFPlain Carbon Steel101

       

      This is intended that you can send the BoM + DXF's to your Laser Cutter being sure you've not forgotten anything!

       

      It creates two folders in the root of the assembly for the DXF & PDF files.

      It's not the tidiest bit of code I've ever written - and mostly just cobbled together out of examples from here & the API help - but it does seem to work OK.

      The worst bit IMHO is the way it finds drawings by looking for a file with the same name as the part, but with the extension .sldprt.  If found, it saves as a PDF.

       

      It seems that it's pretty difficult to find the drawing referenced by a model within an assembly.  I tried a few methods, which didn't work - so having run out of time kept it as it was!

      The upshot is all the part & drawing files need to be in the same folder as the assembly (which I rarely do) - but you can use Pack'n'go and save to a single folder to make it so - better than nothing!

       

      If I've 'borrowed' a snippet of your code - let me know and I'll give you a credit!

       

      I hope it's useful to some of you.

       

      Si

        • Re: Macro to export PDF's, Sheet metal DXF's & Sheet Metal BoM
          Thomas Alberts

          Simon,

           

          Thanks, this will be useful.  Any idea how to include the configuration with the file name?  Most of my drawings are: file name + configuration name.  

           

          I could open the file and get the configuration but my previous experience is that it doesn't always open the referenced configuration.

          • Re: Macro to export PDF's, Sheet metal DXF's & Sheet Metal BoM
            Simon Rafferty

            OK, here's a quick solution.

            If you open a configuration - then run the macro, the files generated have -Configuration Name appended to the end for both the PDF, DXF & BOM.  I've also changed it so the assembly name is included in the name of the BOM.

             

            I guess what you are (actually) looking for is to iterate through all the configurations in the assembly and export files for each?  If so, it's a little more complex but I'll have a look later.

             

            Si

              • Re: Macro to export PDF's, Sheet metal DXF's & Sheet Metal BoM
                Thomas Alberts

                Thanks Simon,

                 

                I moved a few things around so its looking at the part configuration in the while loop.   I haven't fully tested it, but it looking pretty good!

                 

                    While NumDocsReturned <> 0
                      
                       CompConfig = swDoc.ConfigurationManager.ActiveConfiguration.Name
                       
                        bDocWasVisible = swDoc.Visible
                        'swApp.ActivateDoc swDoc.GetPathName'
                        DwgPath = swDoc.GetPathName
                        If (LCase(Right(DwgPath, 3)) = "prt") Then
                            'Open model

                            'Export any sheet metal parts as DXF Flat patterns
                           
                            If CompConfig <> "Default" Then
                           
                                prtPath = Left(DwgPath, Len(DwgPath) - 7) & CompConfig & ".sldprt"
                                Set myDwgDoc = swApp.OpenDoc6(prtPath, swDocPART, swOpenDocOptions_Silent, "", OpenErrors, OpenWarnings)
                                Set featureMgr = myDwgDoc.FeatureManager
                                Set SheetMetalFolder = featureMgr.GetSheetMetalFolder
                               
                            Else
                           
                                prtPath = Left(DwgPath, Len(DwgPath) - 3) & "prt"
                                Set myDwgDoc = swApp.OpenDoc6(prtPath, swDocPART, swOpenDocOptions_Silent, "", OpenErrors, OpenWarnings)
                                Set featureMgr = myDwgDoc.FeatureManager
                                Set SheetMetalFolder = featureMgr.GetSheetMetalFolder
                               

              • Re: Macro to export PDF's, Sheet metal DXF's & Sheet Metal BoM
                Huseyin Ata

                hi simon solidworks 2018 problem