AnsweredAssumed Answered

How to save IGS file from referenced view in drawing

Question asked by William Miller on Apr 6, 2018
Latest reply on Apr 6, 2018 by William Miller

Hi everyone,


I am trying to save a reference model from a drawing as an igs file via macro. I am having trouble with the actual IGS file being saved however. I think it has something to do with how I set my swModel as equal to the swView.ReferencedDocument. Can anyone take a look at my relevant lines of code an help me get around this?

My relevant code for saving the IGS file starts at line 65.

Option Explicit
    Dim swApp               As SldWorks.SldWorks
    Dim swModel             As SldWorks.ModelDoc2
    Dim status              As Boolean
    Dim filename            As String
    Dim errors              As Long
    Dim warnings            As Long
    Dim swDraw              As SldWorks.DrawingDoc
    Dim swCustProp          As SldWorks.CustomPropertyManager
    Dim swView              As SldWorks.View
    Dim ValOut              As String
    Dim Path                As String
    Dim PDFpath             As String
    Dim DXFpath             As String
    Dim IGSpath             As String
    Dim filename            As String
    Dim Rev                 As String

Sub main()
    Set swApp = Application.SldWorks
    Set swApp = Application.SldWorks
    Set swDraw = swApp.ActiveDoc
    Set swView = swDraw.GetFirstView 'this is the sheet view
    Set swView = swView.GetNextView 'this is the next view
    Set swModel = swView.ReferencedDocument
    Set swCustProp = swModel.Extension.CustomPropertyManager(swView.ReferencedConfiguration)
    'Opens folder browser dialogue and prompts user for PDF Folder
    Path = SelectFolder("Select PDF Folder", "C:\Users\USER\Desktop\TEST FILES")
    Path = Path + "\"
    'creates the PDF directory if it doesn't exist
    PDFpath = Path & "PDFs\"
    If Dir(PDFpath, vbDirectory) = "" Then MkDir PDFpath
    'creates the DXF directory if it doesn't exist
    DXFpath = Path & "DXFs\"
    If Dir(DXFpath, vbDirectory) = "" Then MkDir DXFpath
    'creates the IGS directory if it doesn't exist
    IGSpath = Path & "IGSs\"
    If Dir(IGSpath, vbDirectory) = "" Then MkDir IGSpath
    'gets drawing number from model
    Set swCustProp = swModel.Extension.CustomPropertyManager("")
    swCustProp.Get5 "DrawingNo", True, ValOut, filename, False

    'gets rev from drawing properties
    Rev = swDraw.CustomInfo("Revision")
    'sets the filename to format: M*123456_REV-**
    filename = filename & "_REV-" & Rev

    'saves as PDF
    swDraw.SaveAs (PDFpath & filename & ".pdf")
    'Saves as DXF
    swDraw.SaveAs (DXFpath & filename & ".dxf")
    'Saves as IGES
    swModel.Extension.SaveAs (IGSpath & filename & ".igs"), swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, errors, warnings
End Sub