Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
AutoDesk_Inventor.
149 Views, 0 Replies

iLogic Code to Export IFC file

Hi,

 

Inventor 2020 soon to be updating to 2024.

 

I've developed a macro that efficiently exports both a Step and PDF file from an Inventor Drawing to a designated folder. However, I'm facing challenges in extending the functionality to include the export of an IFC file alongside the PDF and Step formats. Can someone assist by integrating the necessary code into the existing working code provided below?

 

I'm encountering an issue where the IFC file type is produced through the Environments tab of either a .ipt or .iam. Subsequently, I utilize the BIM Content add-in to generate the .ifc file. However, incorporating this process into the existing code proves challenging. Can someone provide assistance in seamlessly integrating the creation of the .ifc file using the Environments tab and BIM Content add-in within the current code framework?

 

iLogicVb.RunRule("Force Uppercase")

' Export PDF
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) ' without extension
oPartNum = iProperties.Value("Project", "Part Number")
oRevNum = iProperties.Value("Custom", "Revision")
oTitle = iProperties.Value("Project", "Description")

oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

' If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets

' Get target folder path
Dim oFolder As String
Dim username As String
username = Environ("USERNAME")
oFolder = "C:\DRAWING " & "\" & oPartNum & "-" & oTitle

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

oFolder = System.IO.Path.Combine(oFolder, "Revision " & oRevNum)

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

Dim reviewNumber As Integer = 1
Dim reviewFolder As String

Do
    reviewFolder = System.IO.Path.Combine(oFolder, "Approval " & reviewNumber)
    reviewNumber += 1
Loop While System.IO.Directory.Exists(reviewFolder)

System.IO.Directory.CreateDirectory(reviewFolder)

' Set the PDF target file name
Dim NewFileName As String
Dim NewName As String
NewFileName = System.IO.Path.Combine(reviewFolder, oPartNum & "_" & oRevNum & " - " & oTitle & ".pdf")
NewName = oPartNum & "_" & oRevNum & " - " & oTitle & ".pdf"
oDataMedium.FileName = NewFileName

' Publish PDF document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

' Set the STEP target file name
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oMDoc As Document = ThisDrawing.ModelDocument
Dim oAddIns As ApplicationAddIns = ThisApplication.ApplicationAddIns
Dim oSTEP As TranslatorAddIn

For Each oAddIn As ApplicationAddIn In oAddIns
    If oAddIn.DisplayName = "Translator: STEP" Then
        oSTEP = oAddIn
    End If
Next

Dim oTO As TransientObjects = ThisApplication.TransientObjects
oContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = oTO.CreateNameValueMap
oDataMedium = oTO.CreateDataMedium
Dim oStepFileName As String = iProperties.Value(oMDoc, "Project", "Part Number") & " " & iProperties.Value(oMDoc, "Project", "Description")

' Use the same folder for the STEP file
oDataMedium.FileName = System.IO.Path.Combine(reviewFolder, oPartNum & "_" & oRevNum & " - " & oTitle & ".stp")

If oSTEP.HasSaveCopyAsOptions(oMDoc, oContext, oOptions) Then
    ' Set application protocol.
    ' 2 = AP 203 - Configuration Controlled Design
    ' 3 = AP 214 - Automotive Design
    oOptions.Value("ApplicationProtocolType") = 3
    ' Other options...
    'oOptions.Value("IncludeSketches") = True
    'oOptions.Value("export_fit_tolerance") = .000393701
    'oOptions.Value("Author") = ThisApplication.GeneralOptions.UserName
    'oOptions.Value("Authorization") = ""
    'oOptions.Value("Description") = iProperties.Value(oMDoc, "Project", "Description")
    'oOptions.Value("Organization") = iProperties.Value(oMDoc, "Document Summary Information", "Company")
    oSTEP.SaveCopyAs(oMDoc, oContext, oOptions, oDataMedium)
End If

MessageBox.Show("Location:" + vbCrLf + oFolder & "\" + vbCrLf + "" + vbCrLf + "PDF File Name:" + vbCrLf + NewName & vbCrLf & "STEP File Name:" + vbCrLf + NewName & ".stp", "PDF and STEP Saved")