Hello!
I use this piece of code:
http://inventortrenches.blogspot.de/2012/11/ilogic-batch-output-pdfs-from-assembly.html
Which works but the thing is; there are components of the code that are not integrated in ilogic since version 2018.
like the red marked sections below. (Or difference in ilogic and VBA thingy.)
If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
'oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If
So i deleted this parts and the pdf creation works well.
it creates the files in the correct folders and so on. but then there is this error:
System.NullReferenceException: Ungültiger Zeiger (Ausnahme von HRESULT: 0x80004003 (E_POINTER))
bei Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
bei Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
bei LmiRuleScript.Main()
bei Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
bei iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
i guess this error has the same root.
Actually i wonder why the rule is perfectly working, except this error message.
Can anyone tell me which lines i have to delete to get rid of the message?
i looked that up, but the answers here are already included in my code: (callPDFAddin and so on)
https://forums.autodesk.com/t5/inventor-customization/inventor-2018-ilogic-error/td-p/7073741
https://forums.autodesk.com/t5/inventor-customization/ilogic-fail/td-p/6972701
My code looks like this now:
SyntaxEditor Code Snippet
'define the active document as an assembly file Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4) 'check that the active document is an assembly file If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("Please run this rule from the assembly file.", "iLogic") Exit Sub End If 'get user input RUsure = MessageBox.Show ( _ "This will create a PDF file for all of the asembly components that have drawings files." _ & vbLf & "This rule expects that the drawing file shares the same name and location as the component." _ & vbLf & " " _ & vbLf & "Are you sure you want to create PDF Drawings for all of the assembly components?" _ & vbLf & "This could take a while.", "iLogic - Batch Output PDFs ",MessageBoxButtons.YesNo) If RUsure = vbNo Then Return Else End If '- - - - - - - - - - - - -PDF setup - - - - - - - - - - - - oPath = ThisDoc.Path PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets oOptions.Value("Custom_Begin_Sheet") = 1 oOptions.Value("Custom_End_Sheet") = 1 'get PDF target folder path oFolder = oPath & "\" & oAsmName & " PDF Files" '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 '- - - - - - - - - - - - - '- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly Dim oRefDocs As DocumentsEnumerator oRefDocs = oAsmDoc.AllReferencedDocuments Dim oRefDoc As Document 'work the the drawing files for the referenced models'this expects that the model has a drawing of the same path and name For Each oRefDoc In oRefDocs idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw" 'check to see that the model has a drawing of the same path and name If(System.IO.File.Exists(idwPathName)) Then Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(idwPathName, True) oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3) On Error Resume Next ' if PDF exists and is open or read only, resume next 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oFileName & "pdf" 'Write out the PDF Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium) 'close the file oDrawDoc.Close Else 'If the model has no drawing of the same path and name - do nothing End If Next '- - - - - - - - - - - - - '- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - - oAsmDrawing = ThisDoc.ChangeExtension(".idw") oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawing, True) oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3) 'write out the PDF for the Top Level Assembly Drawing file On Error Resume Next ' if PDF exists and is open or read only, resume next 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "pdf" 'Write out the PDF Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium) 'Close the top level drawing oAsmDrawingDoc.Close '- - - - - - - - - - - - - MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic") 'open the folder where the new ffiles are saved Shell("explorer.exe " & oFolder,vbNormalFocus)
Thank you very much.
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
Hello!
i tried a few things and looked up a view solutions
https://forums.autodesk.com/t5/inventor-customization/inventor-2018-ilogic-error/td-p/7073741
implemented - not working
https://www.aplicit.com/erreur-ilogic-exception/
implemented - not working
here it says i can fix this by repairing the visual studio installation (???)
https://forums.autodesk.com/t5/inventor-customization/ilogic-made-pdf-w-rev/td-p/7154650
implemented that, but it did not work out
It all says that the problem is in the PDFAddIn section. And as the error message appears when the top level drawing is opened i assume that the problem is there. For me it just trial and error.
SyntaxEditor Code Snippet
oAsmDrawing = ThisDoc.ChangeExtension(".idw") oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawing, True) oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -4) 'write out the PDF for the Top Level Assembly Drawing file' if PDF exists and is open or read only, resume next 'Set the PDF target file name'oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & ".pdf" oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "_v" & Microsoft.VisualBasic.Strings.Format(oAsmDrawingDoc.FileSaveCounter,"00#") & ".pdf" 'Write out the PDF'PDFAddIn = ThisApplication.Documents.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")'PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 'Close the top level drawing oAsmDrawingDoc.Close
unfortunately i guess my programming skills are not sufficient to solve this problem.
Maybe you could give me hint, what to do.
thank you
Hi steven.luthra,
I glanced at this and your similar/duplicate thread on this topic yesterday, and asked the moderator to move them both to the Inventor Customization forum (http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120 ), since these are API related questions. That's where I would post programming questions in the future.
I don't have Inventor 2018 on this machine so I can't take a look at this issue for you, but I'll ask the moderator to move these posts over to the other forum again, so that they have the correct audience.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Proper variable declaration of variables goes a long ways.
Sub Main() Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4) 'check that the active document is an assembly file If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("Please run this rule from the assembly file.", "iLogic") Exit Sub End If 'get user input If MessageBox.Show ( _ "This will create a PDF file for all of the asembly components that have drawings files." _ & vbLf & "This rule expects that the drawing file shares the same name and location as the component." _ & vbLf & " " _ & vbLf & "Are you sure you want to create PDF Drawings for all of the assembly components?" _ & vbLf & "This could take a while.", "iLogic - Batch Output PDFs ",MessageBoxButtons.YesNo) = vbNo Then Exit Sub End If Dim PDFAddIn As TranslatorAddIn
Dim oContext As TranslationContext Dim oOptions As NameValueMap Dim oDataMedium As DataMedium Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium) oPath = ThisDoc.Path oFolder = oPath & "\" & oAsmName & " PDF Files" If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If '- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly Dim oRefDoc As Document For Each oRefDoc In oRefDocs = oAsmDoc.AllReferencedDocuments idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentNaMe) - 3) & "idw" If(System.IO.File.Exists(idwPathName)) Then Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(idwPathName, True) oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3) On Error Resume Next oDataMedium.FileName = oFolder & "\" & oFileName & "pdf" Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium) oDrawDoc.Close On Error Goto 0 End If Next '- - - - - - - - - - - - - '- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - - Dim oAsmDrawingDoc As DrawingDocument oAsmDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True) oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3) On Error Resume Next oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "pdf" Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium) oAsmDrawingDoc.Close MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic") Shell("explorer.exe " & oFolder,vbNormalFocus) End Sub Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium) oPath = ThisDoc.Path PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets oOptions.Value("Custom_Begin_Sheet") = 1 oOptions.Value("Custom_End_Sheet") = 1 oDataMedium = ThisApplication.TransientObjects.CreateDataMedium End Sub
@Curtis_Waguespack thank you for your reply. I hope the topic can be moved. Next time i will post the topic in the correct section.
@MechMachineMan: Thank you for your answer. I tried your piece of code but it generates an error as follows.
As there is something in german i try to translate what it says:
System.InvalidCastException: Der Operator = ist für 'Nothing' und Typ DocumentsEnumerator nicht definiert.
System.InvalidCastException: The operator = is for 'Nothing' and Type DocumentsEnumerator not defined. (hope this makes sense)
bei Microsoft.VisualBasic.CompilerServices.Operators.InvokeObjectUserDefinedOperator(UserDefinedOperator Op, Object[] Arguments)
bei Microsoft.VisualBasic.CompilerServices.Operators.InvokeUserDefinedOperator(UserDefinedOperator Op, Object[] Arguments)
bei Microsoft.VisualBasic.CompilerServices.Operators.CompareObjectEqual(Object Left, Object Right, Boolean TextCompare)
bei LmiRuleScript.Main()
bei Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
bei iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
i looked it up and found this:
and this
so i assume it is in the For-loop. I tried to exchange the section of your code with the section of my previous one, but this did not work out.
Unfortunately it doesnt say which line the problem is. and how can the "="-Operator not be defined?
Thank you for your answer.
Yeah; there was one bug in the code.
Sub Main() Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4) 'check that the active document is an assembly file If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("Please run this rule from the assembly file.", "iLogic") Exit Sub End If 'get user input If MessageBox.Show ( _ "This will create a PDF file for all of the asembly components that have drawings files." _ & vbLf & "This rule expects that the drawing file shares the same name and location as the component." _ & vbLf & " " _ & vbLf & "Are you sure you want to create PDF Drawings for all of the assembly components?" _ & vbLf & "This could take a while.", "iLogic - Batch Output PDFs ",MessageBoxButtons.YesNo) = vbNo Then Exit Sub End If Dim PDFAddIn As TranslatorAddIn Dim oContext As TranslationContext Dim oOptions As NameValueMap Dim oDataMedium As DataMedium Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium) oPath = ThisDoc.Path oFolder = oPath & "\" & oAsmName & " PDF Files" If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If '- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly Dim oRefDoc As Document ' For Each oRefDoc In oRefDocs = oAsmDoc.AllReferencedDocuments For Each oRefDoc In oAsmDoc.AllReferencedDocuments idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentNaMe) - 3) & "idw" If(System.IO.File.Exists(idwPathName)) Then Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(idwPathName, True) oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3) On Error Resume Next oDataMedium.FileName = oFolder & "\" & oFileName & "pdf" Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium) oDrawDoc.Close On Error Goto 0 End If Next '- - - - - - - - - - - - - '- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - - Dim oAsmDrawingDoc As DrawingDocument oAsmDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True) oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3) On Error Resume Next oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "pdf" Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium) oAsmDrawingDoc.Close MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic") Shell("explorer.exe " & oFolder,vbNormalFocus) End Sub Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium) oPath = ThisDoc.Path PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets oOptions.Value("Custom_Begin_Sheet") = 1 oOptions.Value("Custom_End_Sheet") = 1 oDataMedium = ThisApplication.TransientObjects.CreateDataMedium End Sub
Hello, first one, thank you
i tried your latest code a i have this error
Erreur de règle: Règle0, dans le document 17005AFZM001Z0-001.iam
Paramètre incorrect. (Exception de HRESULT : 0x80070057 (E_INVALIDARG))
System.ArgumentException: Paramètre incorrect. (Exception de HRESULT : 0x80070057 (E_INVALIDARG))
à System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
à Inventor.Documents.Open(String FullDocumentName, Boolean OpenVisible)
à LmiRuleScript.Main()
à Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
à iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
Thank you for your reply
i run it in assembly file, it make PDF files and after the last PDF create, it make this error (Exception de HRESULT : 0x80070057 (E_INVALIDARG))
Yannick
Hi @Anonymous
When you say "after the last PDF created", do you mean that the PDF from the top level drawing was created ?
The error you have is : "Inventor.Documents.Open(String FullDocumentName, Boolean OpenVisible)"
So the problem IMO is this line : ( - - - - after Top level drawing - - - - )
oAsmDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True)
Which could run this issue :
Please check this
You can also try to modify the code like this to avoid the error :
'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - - Dim oAsmDrawingDoc As DrawingDocument oAsmDrawingDocName = ThisDoc.PathAndFileName(False) & ".idw" If(System.IO.File.Exists(oAsmDrawingDocName)) Then 'oAsmDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True) oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawingDocName, True) oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3) On Error Resume Next oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "pdf" Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium) oAsmDrawingDoc.Close End If
Thomas
Mechanical Designer / Inventor Professionnal 2025
Hi @ThomasB44
Thank you very much 🙂
it work fine !!!
here is the modified code that works for me
Sub Main() Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4) 'check that the active document is an assembly file If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("Please run this rule from the assembly file.", "iLogic") Exit Sub End If 'get user input If MessageBox.Show ( _ "This will create a PDF file for all of the asembly components that have drawings files." _ & vbLf & "This rule expects that the drawing file shares the same name and location as the component." _ & vbLf & " " _ & vbLf & "Are you sure you want to create PDF Drawings for all of the assembly components?" _ & vbLf & "This could take a while.", "iLogic - Batch Output PDFs ",MessageBoxButtons.YesNo) = vbNo Then Exit Sub End If Dim PDFAddIn As TranslatorAddIn Dim oContext As TranslationContext Dim oOptions As NameValueMap Dim oDataMedium As DataMedium Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium) oPath = ThisDoc.Path oFolder = oPath & "\" & oAsmName & " PDF Files" If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If '- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly Dim oRefDoc As Document ' For Each oRefDoc In oRefDocs = oAsmDoc.AllReferencedDocuments For Each oRefDoc In oAsmDoc.AllReferencedDocuments idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentNaMe) - 3) & "idw" If(System.IO.File.Exists(idwPathName)) Then Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(idwPathName, True) oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3) On Error Resume Next oDataMedium.FileName = oFolder & "\" & oFileName & "pdf" Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium) oDrawDoc.Close On Error Goto 0 End If Next '- - - - - - - - - - - - - '- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - - Dim oAsmDrawingDoc As DrawingDocument oAsmDrawingDocName = ThisDoc.PathAndFileName(False) & ".idw" If(System.IO.File.Exists(oAsmDrawingDocName)) Then oAsmDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True) oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawingDocName, True) oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3) On Error Resume Next oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "pdf" Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium) oAsmDrawingDoc.Close End If End Sub Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium) oPath = ThisDoc.Path PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets oOptions.Value("Custom_Begin_Sheet") = 1 oOptions.Value("Custom_End_Sheet") = 1 oDataMedium = ThisApplication.TransientObjects.CreateDataMedium End Sub
These 2 lines do the same thing :
oAsmDrawingDoc = ThisApplication.Documents.Open(ThisDoc.ChangeExtension(".idw"), True) oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawingDocName, True)
Just choose one
Thomas
Mechanical Designer / Inventor Professionnal 2025
Same here i get this error message:
I guess they have changed some coding or got rid of certain codes.
Can anyone help.
How can I switch of the accepted solution, this is not valid anymore.
Here is my error message:
Fehler in Regel: PDF_Batch_Export in Dokument: 10010104_Motor-Komplett.idw
Das COM-Objekt des Typs "System.__ComObject" kann nicht in den Schnittstellentyp "Inventor.AssemblyDocument" umgewandelt werden. Dieser Vorgang konnte nicht durchgeführt werden, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der IID "{29F0D465-C114-11D2-B77F-0060B0F159EF}" aufgrund des folgenden Fehlers nicht durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von HRESULT: 0x80004002 (E_NOINTERFACE)).
System.InvalidCastException: Das COM-Objekt des Typs "System.__ComObject" kann nicht in den Schnittstellentyp "Inventor.AssemblyDocument" umgewandelt werden. Dieser Vorgang konnte nicht durchgeführt werden, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der IID "{29F0D465-C114-11D2-B77F-0060B0F159EF}" aufgrund des folgenden Fehlers nicht durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von HRESULT: 0x80004002 (E_NOINTERFACE)).
bei LmiRuleScript.Main()
bei Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
bei iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
I guess the problem is the AssemblyDocument but i dont know how to fix this.
I don't think so. I tried running it in 2018.2 and got no compiler errors or issues came up aside from the fact I ran it from a blank which caused an error. It makes me think it it is dataset specific.
Also, you can't "Unmark" things as a solution. It is helpful to add relevant questions to the same thread, but if you get no responses, it doesn't hurt to start a new thread.
What I would do in your case is try to manually debug it and isolate what line the error occurs at. It my signature (below this text) is a link on how to "manually debug" in iLogic. Report back when you've done that.
'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly Dim oRefDoc As Document ' For Each oRefDoc In oRefDocs = oAsmDoc.AllReferencedDocuments For Each oRefDoc In oAsmDoc.AllReferencedDocuments idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentNaMe) - 3) & "idw" If(System.IO.File.Exists(idwPathName)) Then Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(idwPathName, True) oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3) On Error Resume Next oDataMedium.FileName = oFolder & "\" & oFileName & "pdf" Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium) oDrawDoc.Close On Error Goto 0 End If Next
oDrawDoc.close in this part of the code, does it mean that all idw will close after pdf cration ?
Hi @Anonymous
You're right.
Inside the For each / Next, the code open each drawing and then close it, one by one.
This line open the document :
oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
And this line close it :
oDrawDoc.Close
Thomas
Mechanical Designer / Inventor Professionnal 2025
That pdf creation code working well, it open all idw that is good to read files input changes, but is it possible to add something to close idw file after pdf craetion
Can't find what you're looking for? Ask the community or share your knowledge.