Hi we have just had our software updated to 2021 from 2016.
I had the below ilogic previously working.
It was to create to ask if I wanted to create a PDF and DXF.
in a folder call PDFDXF under the same location with file name and rev.
If any one could help that would be great.
Here are the errors
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
'query user
question = MessageBox.Show("Create PDF?", "Create PDF?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
'set condition based on answer
If question = vbYes Then
'------start of iLogic-------
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If
'get PDF target folder path
oFolder = oPath & "\" & "PDFDXF"
'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" rev" & oRevNum & ".pdf"
MessageBox.Show("PDF SAVED TO: " & oDataMedium.FileName, "PDF Saved", MessageBoxButtons.OK)
'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'------end of iLogic-------
Else If question = vbNo Then
End If
'query user
question = MessageBox.Show("Create DXF?", "Create DXF?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
'set condition based on answer
If question = vbYes Then
'get DXF target folder path
oFolder = oPath & "\" & "PDFDXF"
'Check for the DXF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'Set the DXF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" rev" & oRevNum & ".dxf"
MessageBox.Show("DXF SAVED TO: " & oDataMedium.FileName, "DXF Saved", MessageBoxButtons.OK)
'Publish document
oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'------end of iLogic-------
Else If question = vbNo Then
End If
See if this works for you.
The main thing I changed was instead of specifying the Addin by its ClientId String (which is horrible), I find it with a loop, by checking which of them has the document type abbreviation in its DisplayName, which they do.
I also simply declared the Types of most of the variables, because that sometimes causes folks problems too, depending on how everything is set up.
I also moved the oFolder specification, and its check for existing job, up above both of the translator blocks, since it was the same in both situations.
Dim oPath As String = ThisDoc.Path
Dim oFileName As String = ThisDoc.FileName(False) 'without extension
Dim oRevNum As String = iProperties.Value("Project", "Revision Number")
Dim oPDFAddIn As TranslatorAddIn
Dim oDXFAddIn As TranslatorAddIn
For Each oAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
If oAddin.AddInType = ApplicationAddInTypeEnum.kTranslationApplicationAddIn Then
If oAddin.DisplayName.Contains("PDF") Then
oPDFAddIn = oAddin
ElseIf oAddin.DisplayName.Contains("DXF") Then
oDXFAddIn = oAddin
End If
End If
Next
Dim oDocument As Document = ThisApplication.ActiveDocument
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = oTO.CreateNameValueMap
Dim oDataMedium As DataMedium = oTO.CreateDataMedium
Dim oFolder As String = oPath & "\" & "PDFDXF"
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'PDF portion
Dim oQ1 As DialogResult = MessageBox.Show("Create PDF?", "Create PDF?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If oQ1 = DialogResult.Yes Then
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If
oDataMedium.FileName = oFolder & "\" & oFileName & " rev" & oRevNum & ".pdf"
MessageBox.Show("PDF SAVED TO: " & oDataMedium.FileName, "PDF Saved", MessageBoxButtons.OK)
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If
'DXF portion
Dim oQ2 As DialogResult = MessageBox.Show("Create DXF?", "Create DXF?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If oQ2 = DialogResult.Yes Then
oDataMedium.FileName = oFolder & "\" & oFileName & " rev" & oRevNum & ".dxf"
MessageBox.Show("DXF SAVED TO: " & oDataMedium.FileName, "DXF Saved", MessageBoxButtons.OK)
oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE" 👍.
Also, when you have time, please review & vote for these 'Ideas' I'd like to get implemented.
Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield
(Not an Autodesk Employee)
I think I see where the problem may have been.
Within the HasSaveCopyAsOptions, you specified oDataMedium as the first entry instead of oDocument, and I didn't catch and change that before posting the code that last time.
I fixed that in this updated code, and changed a couple more things too, to help with errors.
I added a check for in there, before each translation block of code, that checks if the Translator Addin was found, before trying to use it. If not found, it lets you know, then either skips to the next translator block or ends the rule.
Try this now:
Dim oPath As String = ThisDoc.Path
Dim oFileName As String = ThisDoc.FileName(False) 'without extension
Dim oRevNum As String = iProperties.Value("Project", "Revision Number")
Dim oPDFAddIn As TranslatorAddIn
Dim oDXFAddIn As TranslatorAddIn
For Each oAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
If oAddin.AddInType = ApplicationAddInTypeEnum.kTranslationApplicationAddIn Then
If oAddin.DisplayName = "Translator: PDF" Then
oPDFAddIn = oAddin
ElseIf oAddin.DisplayName = "Translator: DXF" Then
oDXFAddIn = oAddin
End If
End If
Next
Dim oDocument As Document = ThisApplication.ActiveDocument
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = oTO.CreateNameValueMap
Dim oDataMedium As DataMedium = oTO.CreateDataMedium
Dim oFolder As String = oPath & "\" & "PDFDXF"
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'PDF portion
If oPDFAddIn Is Nothing Then
MsgBox("PDF Translator Addin could not be found.", vbOKOnly, " ")
GoTo DXF
End If
Dim oQ1 As MsgBoxResult = MsgBox("Create PDF?", vbYesNo + vbQuestion, "Create PDF?")
If oQ1 = vbYes Then
If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If
oDataMedium.FileName = oFolder & "\" & oFileName & " rev" & oRevNum & ".pdf"
MsgBox("PDF SAVED TO: " & oDataMedium.FileName, vbOKOnly, "PDF Saved")
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If
'DXF portion
DXF :
If oDXFAddIn Is Nothing Then
MsgBox("DXF Translator Addin could not be found.", vbOKOnly, " ")
Return
End If
Dim oQ2 As MsgBoxResult = MsgBox("Create DXF?", vbYesNo + vbQuestion,"Create DXF?")
If oQ2 = vbYes Then
If oDXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("Export_Acad_IniFile") = "Default DXF Configuration"
'Or something similar to this:
'oOptions.Value("Export_Acad_IniFile") = "C:\Users\YourProfileName\AppData\Local\Temp\exportdxf250ENU.ini"
End If
oDataMedium.FileName = oFolder & "\" & oFileName & " rev" & oRevNum & ".dxf"
MsgBox("DXF SAVED TO: " & oDataMedium.FileName, vbOKOnly, "DXF Saved")
oDXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE" 👍.
Also, when you have time, please review & vote for these 'Ideas' I'd like to get implemented.
Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield
(Not an Autodesk Employee)
That fixed the PDF part of it, but seems the DXF is still broken.
I get the following:
Thanks
Hmm... This is odd. I don't usually export multiple formats from the same iLogic rule, but my other rules for exporting haven't had any problems, and are somewhat similarly laid out, so I'm not entirely sure why this one isn't working for you.
The error message suggests that it is having trouble with the SaveCopyAs built-in sub, but it does have several variables, so it's not that straight forward diagnose.
In my investigation, I noticed that sometimes it would recognize one addin and not the other, and some times it would recognize both, with no changes to the code, so I'm thinking it isn't liking the direct value asignment of oAddin, for both. So I changed the way I was setting the values of both addin variables, and the new method works like a charm. The reason I avoid using the long string values of ClientId and ClassIdString is because these long complicated looking strings have been known to change when changing Inventor versions. Not with every Inventor version, but between some versions. So, it is just more stable/reliable to go the loop route.
I also added a few more checks into the code to help catch errors.
And also some other minor modifications, that may or may not fix the error, but might help us figure out exactly where the error is happening, and why. Some of the newer stuff you may be able to either comment out, or delete completely, once we get it working for you.
Here's the latest code that is working for me:
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("This rule '" & iLogicVb.RuleName & "' only works with an active Drawing Document. Exiting.", vbOKOnly + vbExclamation, " ")
Return
End If
Dim oAddins As ApplicationAddIns =ThisApplication.ApplicationAddIns
Dim oAddin As ApplicationAddIn
'Dim oPDFAddIn As TranslatorAddIn = oAddins.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'Dim oDXFAddIn As TranslatorAddIn = oAddins.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
For Each oAddin In oAddins
If oAddin.AddInType = ApplicationAddInTypeEnum.kTranslationApplicationAddIn Then
If oAddin.DisplayName.Contains("PDF") Then
oPDFAddIn = oAddins.ItemById(oAddin.ClassIdString)
End If
If oAddin.DisplayName.Contains("DXF") Then
oDXFAddIn = oAddins.ItemById(oAddin.ClassIdString)
End If
End If
Next
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oContext As TranslationContext = oTO.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = oTO.CreateNameValueMap
Dim oDataMedium As DataMedium = oTO.CreateDataMedium
Dim oSourcePath As String = IO.Path.GetDirectoryName(oDDoc.FullFileName)
Dim oSourceFileName As String = IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName)
Dim oRevNum As String = iProperties.Value("Project", "Revision Number")
Dim oTargetFolder As String = oSourcePath & "\" & "PDFDXF"
If Not System.IO.Directory.Exists(oTargetFolder) Then
System.IO.Directory.CreateDirectory(oTargetFolder)
End If
'PDF portion
If oPDFAddIn Is Nothing Then
MsgBox("PDF Translator Addin could not be found.", vbOKOnly, " ")
GoTo DXF
End If
oPDFAddIn.Activate
If oDXFAddIn.SupportsSaveCopyAs = False Then
MsgBox("This PDF Addin does not support the 'SaveCopyAs' Sub. Exiting.", vbOKOnly + vbExclamation, " ")
Return
End If
Dim oQ1 As MsgBoxResult = MsgBox("Create PDF?", vbYesNo + vbQuestion, "Create PDF?")
If oQ1 = vbYes Then
If oPDFAddIn.HasSaveCopyAsOptions(oDDoc, oContext, oOptions) Then
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If
oDataMedium.FileName = oTargetFolder & "\" & oSourceFileName & " rev" & oRevNum & ".pdf"
Try
oPDFAddIn.SaveCopyAs(oDDoc, oContext, oOptions, oDataMedium)
MsgBox("PDF SAVED TO: " & oDataMedium.FileName, vbOKOnly, "PDF Saved")
Catch oEx As Exception
MsgBox("The PDF 'SaveCopyAs' sub failed." & vbCr & _
"Error message is as follows:" & vbCr & _
oEx.Message, vbOKOnly + vbExclamation, "PDF - SAVE-COPY-AS FAILURE")
End Try
End If
'DXF portion
DXF :
If oDXFAddIn Is Nothing Then
MsgBox("DXF Translator Addin could not be found.", vbOKOnly, " ")
Return
End If
oDXFAddIn.Activate
If oDXFAddIn.SupportsSaveCopyAs = False Then
MsgBox("This DXF Addin does not support the 'SaveCopyAs' Sub. Exiting.", vbOKOnly + vbExclamation, " ")
Return
End If
Dim oQ2 As MsgBoxResult = MsgBox("Create DXF?", vbYesNo + vbQuestion,"Create DXF?")
If oQ2 = vbYes Then
If oDXFAddIn.HasSaveCopyAsOptions(oDDoc, oContext, oOptions) Then
oOptions.Value("Export_Acad_IniFile") = "Default DXF Configuration"
'Or something similar to this:
'oOptions.Value(Export_Acad_IniFile") = "C:\Users\YourProfileName\AppData\Local\Temp\exportdxf250ENU.ini"
Else
MsgBox("This DXF Addin does not have 'SaveCopyAs' options.", vbOKOnly," ")
End If
oDataMedium.FileName = oTargetFolder & "\" & oSourceFileName & " rev" & oRevNum & ".dxf"
Try
oDXFAddIn.SaveCopyAs(oDDoc, oContext, oOptions, oDataMedium)
MsgBox("DXF SAVED TO: " & oDataMedium.FileName, vbOKOnly, "DXF Saved")
Catch oEx As Exception
MsgBox("The DXF 'SaveCopyAs' sub failed." & vbCr & _
"Error message is as follows:" & vbCr & _
oEx.Message, vbOKOnly + vbExclamation, "DXF - SAVE-COPY-AS FAILURE")
End Try
End If
I hope this works for you.
Wesley Crihfield
(Not an Autodesk Employee)
I had it working for me, before posting it that last time, but that's often not any guarantee that it will work on another persons situation.
Maybe try separating the two different export processes into two different external iLogic rules, then use another rule which asks the question and runs the necessary other external rules. Or separating the two export processes into different subs.
I'm wandering if the values of the oContext and/or oOptions variables are being modified by passing through the first PDF exporter process first, then not working for the DXF exporter.
Wesley Crihfield
(Not an Autodesk Employee)
Thanks,
Originally i found the the ilogic by using someone else's code,
Its been so long since I looked at it and I have forgotten how it all works.
Can't find what you're looking for? Ask the community or share your knowledge.