Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PDF from Assembly - make views precise

6 REPLIES 6
Reply
Message 1 of 7
dfitting
603 Views, 6 Replies

PDF from Assembly - make views precise

I found this code and have been using it for quite some time to create pdf's from assemblies written by Curtis Waguespack.

 

I've searched but I cant figure out how to modify it to make views precise.

 

Is there any way to make the code process the Make All Views Precise before it begins to process the pdf file?

 

I've tried adding a line to pause the code after open to give the file time to process the InventorViewCompute.exe but it is only doing the active sheet and the others arent processing, and therefore are raster. 

 

I've attached a pdf, notice the 2nd page is precise due to it being the active sheet when the idw file opened, and the 1st page is in Raster view.

 

Note that when these files were closed, they were all saved in Precise view. 

 

 

'define the active document as an assembly file
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) -4)

'check that the active document is an assembly file
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If

'get user input
RUsure = MessageBox.Show ( _
"This will create a PDF file for all of the asembly components that have drawings files." _
& vblf & "This rule expects that the drawing file shares the same name and location as the component." _
& vblf & " " _
& vblf & "Are you sure you want to create PDF Drawings for all of the assembly components?" _
& vblf & "This could take a while.", "iLogic  - Batch Output PDFs ",MessageBoxButtons.YesNo)

If RUsure = vbNo Then
Return
Else
End If

'- - - - - - - - - - - - -PDF setup - - - - - - - - - - - -
oPath = ThisDoc.Path
PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

If PDFAddIn.HasSaveCopyAsOptions(oDataMedium, 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 = oPath & "\" & oAsmName & " PDF Files"

'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
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -
'look at the files referenced by the assembly
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oAsmDoc.AllReferencedDocuments
Dim oRefDoc As Document

'work the the drawing files for the referenced models
'this expects that the model has a drawing of the same path and name 
For Each oRefDoc In oRefDocs
idwPathName = Left(oRefDoc.FullDocumentName, Len(oRefDoc.FullDocumentName) - 3) & "idw"
'check to see that the model has a drawing of the same path and name 
If(System.IO.File.Exists(idwPathName)) Then
		Dim oDrawDoc As DrawingDocument
	oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
	oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) -3)

	On error Resume Next ' if PDF exists and is open or read only, resume next
	 'Set the PDF target file name
	oDataMedium.FileName = oFolder & "\" & oFileName & "pdf"
	'Write out the PDF
	Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
	'close the file
	oDrawDoc.Close
Else
'If the model has no drawing of the same path and name - do nothing
End If
Next
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
oAsmDrawing = ThisDoc.ChangeExtension(".idw")
oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmDrawing, True)
oAsmDrawingName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -3)
'write out the PDF for the Top Level Assembly Drawing file
On error Resume Next ' if PDF exists and is open or read only, resume next
 'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "pdf"
'Write out the PDF
Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
'Close the top level drawing
oAsmDrawingDoc.Close
'- - - - - - - - - - - - -

MessageBox.Show("New Files Created in: " & vblf & oFolder, "iLogic")
'open the folder where the new ffiles are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: dfitting

Hi, have you found an answer to this? Today I am using the same code and some of my exported pdfs are in low-quality raster view. Thank you

Message 3 of 7
Mark.Lancaster
in reply to: Anonymous

@Anonymous

 

This posting is about 3 years old and the OP hasn't visited the forums in over a year..  Smiley Very Happy   Paging Dr @Curtis_Waguespack

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

Message 4 of 7
dfitting
in reply to: dfitting

I sort of found a solution that works. I modified the code to have a pop-up window to select open only or pdf. What I do is run the code, do the open only and it will leave the idws open, I'll then click through them, specially the ones with multiple pages, make the process their views. After that I run the code again from the assembly and select pdf, and it will create the pdf with precise views.
Message 5 of 7
dfitting
in reply to: dfitting

I'm here... Always watching... Always waiting.... Muahahahah... Actually I have an account now with my work email but I get notifications from this account on my email lol.
Message 6 of 7

Hi everyone,

 

This is what I had on hand concerning precise views.

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 
'Iterate through all sheets
For Each oSheet In ThisDoc.Document.Sheets
    'Iterate through all views on sheet
    For Each oView In oSheet.DrawingViews
		'set view to be precise
		oView.IsRasterView = False
	Next
Next

 

 

 

Message 7 of 7
dfitting
in reply to: dfitting

Awesome, thank you Curtis! That's way better than my hack of a solution lol

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

Post to forums  

Autodesk Design & Make Report