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: 

Saveas all IDW sheets to PDF

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
insomnix
929 Views, 6 Replies

Saveas all IDW sheets to PDF

Using Inventor 2015, I have a some code I have been using to iterate through factories to build prints. Now I am now trying to do the same thing with assemblies with multiple sheets. Everything works great until I get to: oDrawingDoc.SaveAs(printsfileLocation & oMemberName & ".pdf", True).

 

This function appears to only create a pdf of the active sheet. I need all sheets exported to the same pdf. I have included a section of the code I am using.

 

 

    'iterate through the rows
    Dim oRow As iAssemblyTableRow 'iPartTableRow
    For Each oRow In oFactory.TableRows
        'make this the active row so the model will recompute.
        oFactory.DefaultRow = oRow

        'get the name of the ipart
        oMemberFile = oRow.MemberName
        oMemberName = oRow.MemberName

        oMemberTemplate = oRow.Item(iTemplateColumnIndex).Value 'oParentPartDoc.ComponentDefinition.Parameters.Item("template").Value ' select parametr by name
        oMemberScale = oRow.Item(iScaleColumnIndex).Value
        
        If Len(Dir(templatesfileLocation & oMemberTemplate & ".idw")) > 0 Then
            'get the drawing template
            Set oDrawingDoc = ThisApplication.Documents.Open(templatesfileLocation & oMemberTemplate & ".idw")
            Set oSheets = oDrawingDoc.Sheets

            For Each oSheet In oSheets
                'get the drawing view
                Dim oView As DrawingView
                For Each oView In oSheet.DrawingViews
                    Select Case oView.Name
                        Case "FRONT", "BACK", "ISO"
                            Call oView.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(ipartsfileLocation & oMemberFile & ".iam")
                            oView.[Scale] = oMemberScale
                            oView.IsRasterView = False
                        Case Else
                        
                    End Select
                Next
                
                Dim oPartsList As PartsList
                For Each oPartsList In oSheet.PartsLists
                    oPartsList.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference (ipartsfileLocation & oMemberFile & ".iam")
                Next
            Next oSheet
    
            Call oDrawingDoc.Update2(True)
            'save copy as one new idw using the member name in the prints folder
            Call oDrawingDoc.SaveAs(printsfileLocation & oMemberName & ".idw", True)
            
            Call oDrawingDoc.MakeAllViewsPrecise
            Call oDrawingDoc.SaveAs(printsfileLocation & oMemberName & ".pdf", True)
            Call oDrawingDoc.Close

 

6 REPLIES 6
Message 2 of 7
rossano_praderi
in reply to: insomnix

Hi insomnix,

this is my sample code which can be suitable for your needs.

 

Sub Main
	printsfileLocation=ThisDoc.Path
	oMemberName=ThisDoc.FileName(False) 'without extension
	exportPDF(printsfileLocation, oMemberName, ThisApplication.activedocument)
End Sub

Sub exportPDF(oPath As String, oFileName As String, oDocument As Document)
	Try
		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 = oDocument
		Dim sheetCount As Integer = oDrawing.Sheets.Count
	
		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") = 1
			oOptions.Value("Custom_End_Sheet") = sheetcount
		End If
	
		oDataMedium.FileName = oPath & "\" & oFileName & ".pdf" ' check carefully this line
	
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
	Catch
	End Try
End Sub

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------
Tags (1)
Message 3 of 7
insomnix
in reply to: insomnix

I found something similar to this late yesterday after I posted my problem: http://modthemachine.typepad.com/my_weblog/2009/01/

 

This was an old post from 2009, so I didn't know if it was still a good solution in inventor 2015. Thanks for confirming that 6 years old code is still the best solution to export multiple sheets to a single pdf.

Message 4 of 7
rossano_praderi
in reply to: insomnix

Your are welcome.


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

Hi. I have a funny problem with this code. Not all the drawings save a pdf. there is no error massage but some drawings with this code just does not make a pdf. I have checked the event is triggering but no pdf is made in the same folder.

 

here is the code that I am using

 

 

 

InventorVb.DocumentUpdate()


'------------------- Complex code added to save all sheets ----------------
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
'oDocument = ThisApplication.ActiveDocument
oDocument = ThisDoc.Document
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
'this publish all doens't work
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'try a different publish all command
oOptions.Value("Publish_All_Sheets") = 1
'oOptions.Value("Custom_Begin_Sheet") = 2
'oOptions.Value("Custom_End_Sheet") = 4
End If

'Set the PDF target file name
oDataMedium.FileName = ThisDoc.FileName & ".pdf"
'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

I havce made one change to the code. 

oDocument = ThisDoc.Document

The reason is to get save all to work. That way I can open the all the drawings and hit the save all button and get new pdfs with multipe sheets.

 

Just need to point out that this is no when I get the probem. I get the problem when i save a drawing regardless if i use save or save all. 

I have checed the following. 

1. That the rual is triggered. I used a messaged box at the end and it is

2. That the code is the same between drawing which works and which does not. 

 

Any ideas?

Message 6 of 7
Anonymous
in reply to: Anonymous

Here is the idw with the part that is giving the problems.

 

Help please. i have over 300 drawings i need to convert to PDF's and some works and others don't

Message 7 of 7
rossano_praderi
in reply to: Anonymous

I've checked your code, I've found only a problem with the assignation of path and filename.
Attached you can find your file with two ilogic rules, both of them completely tested and fully working.

 

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