6 7 8 9 10 Next Last 141 Replies Latest reply on Dec 6, 2018 6:27 AM by Ulric Bloem Go to original post
      • 135. Re: Batch export to dwg
        Jason Martin

        Gdhklf Eslk this may be a weird fix but I had help from Deepak Gupta in solving this.

        The root of the problem has to do with the drawing template that you are using. If you save a new drawing template in any location with your scale being 1:1, the problem will be solved.

        • 136. Re: Batch export to dwg
          Gdhklf Eslk

          Yes i know Deepak.


          But i control my template options. But my file format option is not avaliable. I can't change it.. What's the problem? Sw2018

          • 137. Re: Batch export to dwg
            Jason Martin

            yes you are correct. Your options will say the export is 1:1 and that is correct. That is not the solution to your problem though.

            It does sound absolutely crazy to think the drawing scale affects anything but it really does. The drawing scale actually affects the DIMENSIONAL SCALE after it is exported. your geometry will be 1:1 but your Dimensional scale will be whatever the scale of your solidworks drawing shows.

            What you need to do is open a new drawing file, change the sheet properties to 1:1 scale, then Save as drawing template file.

            • 138. Re: Batch export to dwg
              Gdhklf Eslk

              Thank you so much, you are right, your advice solve the problem.


              Can i ask sth again

              When i run the macro, i see two dxf files on my dekstop.





              I want to only sheet metal flat pattern dxf file. awd.Varsayılan is not important. What's your advice?


              The macro's code is below;


              If swModel Is Nothing Then



                  swApp.SendMsgToUser2 "A sheet metal part must be open.", swMbWarning, swMbOk



                  Exit Sub



              End If




              ' Is it a part document?



              Dim modelType As Long



              modelType = swModel.GetType



              If modelType <> SwConst.swDocPART Then



                  swApp.SendMsgToUser2 "A sheet metal part must be open.", swMbWarning, swMbOk



                  Exit Sub



              End If







                      vConfNameArr = swModel.GetConfigurationNames



                  For i = 0 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, 1)



              Next i

              End Sub

              • 139. Re: Batch export to dwg
                Jason Martin

                I am not yet proficient in the solidworks API. BUt if you use the Export SM Batch - 6.0beta.swp.zip file on page 5 of this thread, it shows an option to "IGNORE AUTOMATIC FLAT PATTERN CONFIGS"

                That macro is the one I have always been using.

                Sorry I couldn't help you with that code.

                • 140. Re: Batch export to dwg
                  Deepak Gupta

                  You can add a line to ignore the flat config. 

                  Sorry I'm away from my machine and can not help much but try replacing this line

                  bShowConfig = swModel.ShowConfiguration2(sConfigName).


                  If Not uCase(sConfigName) like "*FLAT*" Then

                  bShowConfig = swModel.ShowConfiguration2(sConfigName)

                  End If

                  Else you can pull the line from the macro Jason has mentioned.

                  • 141. Re: Batch export to dwg
                    Ulric Bloem

                    Hi Deepak


                    I have been following this thread over the 5 years it has been running.


                    Thanks a mil for all the help you have given the SW community.


                    I am running this DXF Batch Macro(See below), however I want to have it so that the bend notes and maybe some other notes like qty, material, part name thickness are included in the DXF file.


                    Is this possible at all?


                    I have no API experience whatsoever. I would really appreciate your help on this.







                    Sub main()









                       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






                       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









                    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



                           GoTo Process



                       End If


















                    'Get Part Material









                    Set swpart = swChildModel



                    sMatName = swpart.GetMaterialPropertyName2(swCurrent, sMatDB)









                    If sMatName = "" Then sMatName = "None"









                    Debug.Print "    Current material is : "; sMatName









                    'Get part Thickness









                    Set swFeat = swChildModel.FirstFeature



                       While Not swFeat Is Nothing









                       If swFeat.GetTypeName = "SheetMetal" Then



                           Set swsheetmetal = swFeat.GetDefinition






                           Thickness = swsheetmetal.Thickness






                           conv = 39.3700787401575



                           Thickness = Thickness * conv









                    Debug.Print "    Thickness is :"; Thickness; "inches"






                       End If









                    Set swFeat = swFeat.GetNextFeature












                    swMatDir = FilePath & "\" & sMatName



                    Debug.Print swMatDir









                    If Dir(swMatDir, vbDirectory) = "" Then MkDir swMatDir









                    swThkDir = FilePath & "\" & sMatName & "\" & Thickness



                    Debug.Print swThkDir









                    If Dir(swThkDir, vbDirectory) = "" Then MkDir swThkDir









                    exFileName = FilePath & "\" & sMatName & "\" & Thickness & "\" & FileName & "-" & swCurrent









                    Debug.Print exFileName









                    Set swOpenModel = swApp.ActivateDoc3(swChildModel.GetPathName, True, loptions, lerrors)









                    Boolstatus = swChildModel.ShowConfiguration2(swCurrent)









                    swChildModel.ExportFlatPatternView exFileName & ".DWG", 0









                    swApp.CloseDoc (swChildModel.GetPathName)












                    GoTo Jump















                       Debug.Print "Skipped"












                           TraverseComponent swChildComp, nLevel + 1



                              Next i









                    End Sub

                    6 7 8 9 10 Next Last