Save PDF

Save PDF

johan.degreef
Advisor Advisor
252 Views
5 Replies
Message 1 of 6

Save PDF

johan.degreef
Advisor
Advisor

For a long time this ilogic has worked without errors (maybe since 2025 was installed?)

Anyone have an idea? Many Thanks

 

Now I get this error:

 

Error on line 37 in rule: PDF_SAVE, in document: 23168_2001_9106.dwg

Unspecified error (0x80004005 (E_FAIL))

 

More info:

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (0x80004005 (E_FAIL))
at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
at ThisRule.Main() in external rule: PDF_SAVE:line 37
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at Autodesk.iLogic.Exec.AppDomExec.ExecCodeHere()
at Autodesk.iLogic.Exec.AppDomExec.ExecCodeInOtherDomain(AppDomain otherDomain, String assemName)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("project", "revision number")
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(oDocument, 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 


'get PDF target folder path
oFolder = "\\192.168.3.17\PDF_INVENTOR\"


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


'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 
'------end of iLogic-------

 

 

 

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
253 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @johan.degreef.  I only quickly glanced over your code, but I think I see something that should be pretty easy to fix.  It looks like you have one to many directory separator characters ("\") between your 'Folder' and your 'FileName' parts.  Often the final "\" character is not included in 'paths', so we instinctively add one in there when concatenating path, name, and extension.  But in your case, since your 'path' is hardcoded text, and it includes that final "\", you just need to eliminate that, one place or the other.  Some folks have also used the System.IO.Path.Combine() method to combine 'path' and 'file name' portions together, because it seems to do a good job of inserting the correct directory separator character in there for us automatically, but that does take more code, and more processing, so maybe not the most efficient.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

johan.degreef
Advisor
Advisor

No, eliminating that last "\" does not solve it....

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 4 of 6

bradeneuropeArthur
Mentor
Mentor

Hey Johan,

Inventor 2025 need to be .net8. You can find this in the help files.

 

https://help.autodesk.com/view/INVNTOR/2025/ENU/?guid=GUID-522FF5BC-7CC5-43D5-99B1-14840CF54A82

 

If you need quick help please send me an email with the vb.net project 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 5 of 6

WCrihfield
Mentor
Mentor

Good catch Arthur.  I completely ignored the 2025 spec.  I know the newer system is more strict, so one other tip would be to 'Declare' (using Dim keyword) every variable, specifying its Type in the process.  Just doing that one extra step often eliminates errors.  Another tip would be to either stick with the 'ThisDoc' reference, and use 'ThisDoc.Document' for setting the value of your oDocument variable, instead of ThisApplication.ActiveDocument.  Or eliminate using the 'ThisDoc' term altogether, because it can be pointing to a different document than ThisApplication.ActiveDocument in some situations.  Mixing the two terms in one rule is usually not a good idea.  The line of code getting the revision number is not specifying which document to retrieve that information from either, so it is likely going to be focused on the same document as the 'ThisDoc' term, if there are two different documents involved.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6

Michael.Navara
Advisor
Advisor

Also you can try to publish PDF file to local TEMP folder and then copy the result to the network location

Dim oPath As String = ThisDoc.Path
Dim oFileName As String = ThisDoc.FileName(False) 'without extension
Dim oRevNum As String = iProperties.Value("project", "revision number").ToString()
Dim oPDFAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oDocument As Document = ThisApplication.ActiveDocument
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium


If oPDFAddIn.HasSaveCopyAsOptions(oDocument, 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


'get PDF target folder path
Dim oTempFolder As String = System.IO.Path.Combine(
    System.IO.Path.GetTempPath(),
    "PDF_INVENTOR")


'Check for the PDF TEMP folder and create it if it does not exist
If Not System.IO.Directory.Exists(oTempFolder) Then
    System.IO.Directory.CreateDirectory(oTempFolder)
End If

'Set the PDF TEMP target file name
Dim tempPdfFileName As String = System.IO.Path.Combine(oTempFolder, oFileName & ".pdf")
oDataMedium.FileName = tempPdfFileName

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

'Check for the PDF FINAL folder and create it if it does not exist
Dim oFolder As String = "\\192.168.3.17\PDF_INVENTOR\"
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

Dim finalPdfFileName As String = System.IO.Path.Combine(oFolder, oFileName & ".pdf")

'Copy PDF from TEMP to FINAL folder
System.IO.File.Copy(tempPdfFileName, finalPdfFileName)

'Delete TEMP PDF file
System.IO.File.Delete(tempPdfFileName)

'------end of iLogic-------
0 Likes