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:Ā 

DWG to PDF directing the save path

5 REPLIES 5
Reply
Message 1 of 6
benjoefoe
323 Views, 5 Replies

DWG to PDF directing the save path

I have a code that'll print my dwgs to pdf. I created a form so that I can change a custom parameter called "SAVELOC" to direct where to save the pdf file. I really don't like this way of doing it. I was wondering if there is maybe a way to pull up a browser either through code or the form so that I can just click and point to the folder I want it to save to.

 

Here is my code...like I said, where it says "SAVELOC" it substitutes the entire folder path.

 

 

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(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 600
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 = Left(oPath, InStrRev(oPath, SAVELOC)) & SAVELOC

'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)
Thanks, Ben

AutoDesk Inventor 2020 Certified
5 REPLIES 5
Message 2 of 6
VdVeek
in reply to: benjoefoe

Ben, Look for the "File Dialog API Sample" in the API Help. There is an example of opening the Open/Save Dialog.

Rob.

Autodesk Inventor 2015 Certified Professional & Autodesk Inventor 2012 Certified Professional.
Message 3 of 6
GosponZ
in reply to: benjoefoe

Here is how i do: Open folder where will be your pdf's. Copy address. Run this code. Change path in code.

response = MessageBox.Show("Did you change path in this rule?", "Reminder",MessageBoxButtons.YesNo)

If response = vbNo Then Exit Sub

 

 

'Save PDF with options

'SaveLoc = "C:\"

'FileName = ThisDoc.FileName(True)

'ThisDoc.Document.SaveAs(FileName & (".pdf") , True)

oPath = ThisDoc.Path

PN = iProperties.Value("Project", "Part Number")

 

 

'path_and_namePDF = ThisDoc.Pathandname(False)

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

 

 

 

 

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") = 1

'oOptions.Value("Custom_End_Sheet") = 4

End If

 

 

 

'Set the destination file name

oPath = "C:\MY PDF FILES\"

oPath = InputBox("Replace Path","New Path")

 

oDataMedium.FileName = oPath & "\" & PN & ".pdf"

'Publish document

 'Confirmation message

 MessageBox.Show("PDF SAVED TO: " & oDataMedium.FileName, "PDF Saved", MessageBoxButtons.OK)

 

 

 

On Error Goto handlePDFLock

'Publish document.

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

 

 

'--------------------------------------------------------------------------------------------------------------------

 

 

Exit Sub

 

 

handlePDFLock:

MessageBox.Show("PDF could not be saved, most likely someone else has it open", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")

Resume Next

 

 

handleXLSLock:

MessageBox.Show("No XLS", "iLogic")

Resume Next

 

 

 

Message 4 of 6
benjoefoe
in reply to: VdVeek

Yes, I believe the Open/Save Dialog is the key to my goal here, but I am only an ilogic beginner so it may take some time with a lot of trial and error for me to figure this out.

Thanks you guys for the great suggestions! I'll let you know if I get something

Thanks, Ben

AutoDesk Inventor 2020 Certified
Message 5 of 6
GosponZ
in reply to: benjoefoe

In this code i gave you just change path with desired path of yours pdf folder

oPath = "C:\MY PDF FILES\"

 

run rule , and you will need to copy paste address where is your folder.

 

That is it , this one is very easy šŸ™‚ and working very well. It is time saver

Message 6 of 6
benjoefoe
in reply to: GosponZ

What I have is one master folder, and then in that folder I have a bunch of project folders, in those project folders I have assembly folders. I'm constantly mapping back and forth through folders saving pdfs in many different folders throughout the day. It's a great code you gave me and way better than what I was using but my goal is to pull up the folders in windows and navigate back and forth by clicking rather than typing. Thanks again for your replys!

Thanks, Ben

AutoDesk Inventor 2020 Certified

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

Post to forums  

Autodesk Design & Make Report