Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Printing PDF's from .idw file

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
jeffbohn
437 Views, 2 Replies

Printing PDF's from .idw file

Thanks all for your advice and suggestions on this issue.

 

I have recently upgraded to 2019 version. I was using 2016 and had a Rule within my .idw template that allowed me to print PDF's of the .idw into a PDF folder if there wasn't a PDF folder already created, the Rule would create one. This Rule would print individual PDF's of all pages within the .idw file.

 

Since upgrading to 2019, the Rule no longer works and is giving me an error that I have no idea how to fix. Please see below for the Rule & Error Message:

 

Rule:

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
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

'Define the drawing
Dim oDrawing As DrawingDocument
oDrawing = ThisDoc.Document

Dim oSheet As Sheet
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim iSheetNumber As Integer

'step through each drawing sheet
For Each oSheet In oDrawing.Sheets

'find the seperator in the sheet name:number
lPos = InStr(oSheet.Name, ":")
'find the number of characters in the sheet name
sLen = Len(oSheet.Name)
'find the sheet name
sSheetName = Left(oSheet.Name, lPos -1)
'find the sheet number
iSheetNumber = Right(oSheet.Name, sLen -lPos)

'set PDF Options
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = iSheetNumber
oOptions.Value("Custom_End_Sheet") = iSheetNumber
End If

'get PDF target folder path
oFolder = oPath & "\PDF"

'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 & "\" & sSheetName & ".pdf"

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

Next
 
 

Error Message:

Error in rule: Print Individual PDF's, in document: D7214-D7216.idw

Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))

 

Error Message - More Info:

System.NullReferenceException: Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Any insight would be greatly appreciated as this Rule eliminates a lot of time trying to print each individual page in an .idw file.

 

 

2 REPLIES 2
Message 2 of 3
yan.gauthier
in reply to: jeffbohn

Change oDataMedium in HasSaveCopyAsOption method to your oDrawing object. You test for the document capability to save as PDF, not the medium

Message 3 of 3
jeffbohn
in reply to: yan.gauthier

Thank you, that fixed the issue. Greatly appreciate the help.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report