3 Replies Latest reply on Jul 12, 2018 6:07 PM by Salman Faiz

    Save Drawing View as DXF Macro

    Salman Faiz

      Hi All,

       

      I had this nice macro on Autodesk Inventor to convert each drawing view to DXF and assign the part file name along with drawing revision.

       

      I was wondering if someone could help me to convert it for solidworks?

       

      Dim oDoc As Document

      oDoc = ThisApplication.ActiveDocument

       

      Dim oViews as DrawingViews

      oViews = oDoc.ActiveSheet.DrawingViews

       

      strDrawingPath = ThisDoc.Path

       

      strInterPath = Left(strDrawingPath,Len(strDrawingPath)-21)

       

      strDXFPath=strInterPath & "01 Issued Drawings" & "\DXF Files"

       

      oFolder = strDXFPath

       

      If Not System.IO.Directory.Exists(oFolder) Then

           

            System.IO.Directory.CreateDirectory(oFolder)

           

      End If

       

      strInterPathRdrive = Mid(Left(strDrawingPath,Len(strDrawingPath)-21),22)

       

      strDXFRdrivePath=strInterPathRdrive & "01 Issued Drawings" & "\DXF Files"

       

      strDXFRdrivePath = "R:\Drafting and Drawing\Contracts\" & strDXFRdrivePath

       

      If Not System.IO.Directory.Exists(strDXFRdrivePath) Then

       

            System.IO.Directory.CreateDirectory(strDXFRdrivePath)

           

      End If

       

      'MsgBox(strDXFPath)

       

      'Determine the number of views

       

      Dim intViews,intViewsCount As Integer

      Dim strViews as String

       

      'strViews=InputBox("How many base views are there?","iLogic Question", 0)

      'If strViews="" Then strViews="0"

       

      'intViews=CInt(strViews)

       

      intViewsCount = oViews.Count

       

      Dim oView As DrawingView

       

       

      • oDoc.DrawingSettings.DeferUpdates="False"

       

       

      For k = 1 To intViewsCount

       

       

      • oViews.Item(k).Suppressed

       

      Next k

       

      For j = 1 To intViewsCount

       

      'This portion of the rule gets the part file name from a view.

       

       

       

      If oViews.Item(j).ParentView Is Nothing Then

       

      strView = j

       

      • oViews.Item(j).Suppressed

       

      oView = oViews.Item(j)

      strFileName = oView.ReferencedDocumentDescriptor.DisplayName

       

      y=Len(strFileName)

       

      strFileName = Left(strFileName,y-4)

       

       

      strDXFName = strFileName & "-Rev" & iProperties.Value("Project", "Revision Number")

       

      strDXFPathandName = strDXFPath & "\" &strDXFName

       

      strDXFRdrivePathandName = strDXFRdrivePath & "\" &strDXFName

       

           

      'For creating DXF files on local drive   

      folder = CreateObject("Scripting.FileSystemObject")

      source = folder.getfolder(strDXFPath)

      count = source.files.count

      x=0

       

            For Each file In source.files

           

                  If File.Name = strDXFName & ".dxf" Then

                 

                        question1 = MessageBox.Show("The file "& File.Name &" already exists on Local Drive. Do you want to overwrite it?", "iLogic Question" ,MessageBoxButtons.YesNo ,MessageBoxIcon.Question)

                              x=1

                             

                                    If question1 = vbYes Then

                                   

                                          ThisDoc.Document.SaveAs (strDXFPathandName & (".dxf") ,True)

                                         

                                    End If

                                   

                  End If

                 

                 

                 

                 

            Next

           

                  If x<>1 Then

                 

                        ThisDoc.Document.SaveAs(strDXFPathandName & (".dxf") , True)

                       

                  End If

       

                 

      'This is for creating DXF files on the R drive

      folder = CreateObject("Scripting.FileSystemObject")

      source = folder.getfolder(strDXFRdrivePath)

      count = source.files.count

      a=0

       

            For Each file In source.files

           

                  If File.Name = strDXFName & ".dxf" Then

                 

                        question2 = MessageBox.Show("The file" & File.Name &" already exists on R Drive. Do you want to overwrite it?", "iLogic Question" ,MessageBoxButtons.YesNo ,MessageBoxIcon.Question)

                              a=1

                             

                                    If question2 = vbYes Then

                                   

                                          ThisDoc.Document.SaveAs (strDXFRdrivePathandName & (".dxf") ,True)

                                         

                                    End If

                                   

                  End If

                 

            Next

           

                  If a<>1 Then

                 

                        ThisDoc.Document.SaveAs(strDXFRdrivePathandName & (".dxf") , True)

                       

                  End If

       

                 

                 

                 

                 

                 

                 

                 

      1. ThisDoc.Save

      'MsgBox(strDXFPathandName) 'The message box displays the part file name

       

      • oViews.Item(j).Suppressed

       

      End If

       

      Next j

       

      For a = 1 To intViewsCount

       

      'strView = l

       

      • oViews.Item(a).Suppressed

       

      Next a

       

      • oDoc.DrawingSettings.DeferUpdates="True"

       

      Regards,

       

      Salman