- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.