error in PDF Ilogic snippet

Anonymous

error in PDF Ilogic snippet

Anonymous
Not applicable

I have upgradet to inventor 2019, better late than never, and have encounter this small problem.

When i run my PDF ilogic it shows a error message that says  that i use the wrong pointer, and i dont know why

The ilogic should make a pdf of every drw sheet and store it in the workspace with the name: filename + sheet x.pdf

 

 

PDF snippet code is here:

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") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
oOptions.Value("Custom_Begin_Sheet") = iSheetNumber
oOptions.Value("Custom_End_Sheet") = iSheetNumber
End If

'Set the PDF target file name
'oDataMedium.FileName = oFolder & "\" & oFileName & " " & sSheetName & " " & iSheetNumber  & ".pdf"
oDataMedium.FileName = oPath & "\" & oFileName & "-" & sSheetName & "-" & iSheetNumber  & ".pdf"

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


Next
'------end of iLogic-------

 

0 Likes
Reply
Accepted solutions (1)
769 Views
10 Replies
Replies (10)

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Please provide non confidential sample drawing document to test the iLogic code.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

oPDFAddin.HasSaveCopyAsOptions takes the document as first argument, not DataMedium.

This should work 🙂

 

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(oDrawing, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
oOptions.Value("Custom_Begin_Sheet") = iSheetNumber
oOptions.Value("Custom_End_Sheet") = iSheetNumber
End If

'Set the PDF target file name
'oDataMedium.FileName = oFolder & "\" & oFileName & " " & sSheetName & " " & iSheetNumber  & ".pdf"
oDataMedium.FileName = oPath & "\" & oFileName & "-" & sSheetName & "-" & iSheetNumber  & ".pdf"

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


Next
'------end of iLogic-------

Anonymous
Not applicable

@JhoelForshav 

So I should substitute oDataMedium with oDrawing  in the entire snippet.

Excuse for my ignorance. I build this several years ago from different snippets by trial and error as I have no programming experience.

BTW I am amazed that i got an answer, because Yesterday my post did dissappear, and the forum support couldnt find any trace of it 🙂

0 Likes

JhoelForshav
Mentor
Mentor

Hi @Anonymous 

No, only in this line:

If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then

It should be:

If oPDFAddIn.HasSaveCopyAsOptions(oDrawing, oContext, oOptions) Then

Like I did in the code I posted in my first reply 🙂

Anonymous
Not applicable

I tried that, but it didnt work.

I have attached the error message and the info to it

0 Likes

JhoelForshav
Mentor
Mentor
0 Likes

Anonymous
Not applicable

Yes

0 Likes

JhoelForshav
Mentor
Mentor
Accepted solution

@Anonymous 

I'm sorry, but did you really run this 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(oDrawing, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
oOptions.Value("Custom_Begin_Sheet") = iSheetNumber
oOptions.Value("Custom_End_Sheet") = iSheetNumber
End If

'Set the PDF target file name
'oDataMedium.FileName = oFolder & "\" & oFileName & " " & sSheetName & " " & iSheetNumber  & ".pdf"
oDataMedium.FileName = oPath & "\" & oFileName & "-" & sSheetName & "-" & iSheetNumber  & ".pdf"

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


Next
'------end of iLogic-------

Because the error message you attached is the error message you get if you don't replace oDataMedium with oDrawing in oPDFAddIn.HasSaveCopyAsOptions....

 

You could also run it like this...

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

oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
oOptions.Value("Custom_Begin_Sheet") = iSheetNumber
oOptions.Value("Custom_End_Sheet") = iSheetNumber


'Set the PDF target file name
'oDataMedium.FileName = oFolder & "\" & oFileName & " " & sSheetName & " " & iSheetNumber  & ".pdf"
oDataMedium.FileName = oPath & "\" & oFileName & "-" & sSheetName & "-" & iSheetNumber  & ".pdf"

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


Next
'------end of iLogic-------

 

0 Likes

Anonymous
Not applicable

That solved my problem.

I used you solution 2 without the

If oPDFAddIn.HasSaveCopyAsOptions(oDrawing, oContext, oOptions) Then 

and the end if

0 Likes

Anonymous
Not applicable

Thanks a lot. You were most helpfull

Tack så mycket