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: 

Help with PDF and folder creation with iLogic

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
mwnadolny
1326 Views, 5 Replies

Help with PDF and folder creation with iLogic

I have been reading some posts on these forums regarding automatically exporting PDFs with set names. It has been going okay. I've managed to be able to export PDFs of my Inventor drawings every time I hit 'save'. But a few things aren't working.

 

1. The code exports the same number of PDFs as there are sheets in my drawing, EXCEPT, every PDF contains the image that is in Sheet 1. So if I have a 5 sheet drawing and export it, all 5 PDFs will depict what is contained in Sheet 1.

 

2. The code does not create a new folder called 'PDF' to store the PDFs in. Nor does it store the PDFs in that folder if I create it beforehand. I pretty much copied the code exactly from a tutorial I saw on how to do just that, so I'm not sure why it's not working.

 

Here is my iLogic code. Hopefully someone can help. Thank you. 🙂

 

 '------start of iLogic-------oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extensionoPDFAddIn = 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
Dim sheetCount As Integer = ThisDrawing.Document.Sheets.Count

'step through each drawing sheetFor Each oSheet In oDrawing.Sheets

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

'set PDF OptionsIf 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.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = sSheetNumber
oOptions.Value("Custom_End_Sheet") = sSheetNumber
End If

'get PDF target folder pathoFolder = Left(oPath, InStrRev(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


If sheetCount=1 Then
'Set the PDF target file nameoDataMedium.FileName = oPath & "\" & oFileName & "R" & iProperties.Value("Project", "Revision Number") & "" & sSheetName & ".pdf"
End If


If sheetCount>1
'Set the PDF target file nameoDataMedium.FileName = oPath & "\" & oFileName & "-0" & sSheetNumber & "R" & iProperties.Value("Project", "Revision Number") & "" & sSheetName & ".pdf"
End If

'Publish documentoPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

Next
'------end of iLogic-------
5 REPLIES 5
Message 2 of 6
rossano_praderi
in reply to: mwnadolny

Hi, this is "your" code with some corrections.

The old code may have created new folders in a different location, try to have a look in your workarea.

 

 '------start of iLogic-------
oDocument = ThisApplication.ActiveDocument
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

Dim oDrawing As DrawingDocument = ThisDoc.Document

Dim oSheet As Sheet
Dim lPos, rPos,sLen As Long
Dim sSheetName As String
Dim sSheetNumber As Integer
Dim sheetCount As Integer = oDrawing.Sheets.Count

oFolder = oPath & "\PDF"

If Not System.IO.Directory.Exists(oFolder) Then 
    System.IO.Directory.CreateDirectory(oFolder)
End If

For Each oSheet In oDrawing.Sheets

lPos = InStr(oSheet.Name, ":")
sLen = Len(oSheet.Name)
sSheetName = Left(oSheet.Name, lPos -1)
sSheetNumber = Right(oSheet.Name, sLen -lPos)

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.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = sSheetNumber
oOptions.Value("Custom_End_Sheet") = sSheetNumber
End If

If sheetCount = 1 Then
	oDataMedium.FileName = oFolder & "\" & oFileName & "R" & iProperties.Value("Project", "Revision Number") & "" & sSheetName & ".pdf"
ElseIf sheetCount > 1
	oDataMedium.FileName = oFolder & "\" & oFileName & "-0" & sSheetNumber & "R" & iProperties.Value("Project", "Revision Number") & "" & sSheetName & ".pdf"
End If

oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

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

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 3 of 6
mwnadolny
in reply to: rossano_praderi

Hey, thanks!

 

Another question, if you don't mind. I have my Inventor set up to export the PDFs right before I save, every time I save, but when if I have multiple drawings open and click, "Save All", every PDF that gets exported will have the image of the sheet that was open when I clicked 'Save All'.

Any idea why?

Message 4 of 6
rossano_praderi
in reply to: mwnadolny

Hi,
I would like to know if you have tried my code?
@mwnadolny wrote:

Hey, thanks!

 

Another question, if you don't mind. I have my Inventor set up to export the PDFs right before I save, every time I save, but when if I have multiple drawings open and click, "Save All", every PDF that gets exported will have the image of the sheet that was open when I clicked 'Save All'.

Any idea why?


This could be the solution to yours last question.
In this way the running Ilogic code will be correctly associated with its "Document".
By using yours code on the "ActiveDocument" this will be executed only on this one, you know what i mean.

 

'Substitute this declaration
oDocument = ThisApplication.ActiveDocument

'With this
Dim oDocument As inventor._Document = ThisApplication.documents.itembyname(ThisDoc.PathAndFileName(True))

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Message 5 of 6
mwnadolny
in reply to: rossano_praderi

That worked!

 

Thanks a lot, I really appreciate it. 🙂

Message 6 of 6
rossano_praderi
in reply to: mwnadolny

You are welcome.

 

I would be happy if you accept my solution.

 

Thank you.

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------

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

Post to forums  

Autodesk Design & Make Report