PDF batch according to BOM structure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I have found a ilogic rule on this forum for printing PDF files from an assembly including all parts witch works fine for this option.
'Set Folder options as you see fit here oFolder = 'Enter Folder String here. 'PDF Options PDFAddIn = oAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oPDFContext = oTG.CreateTranslationContext oPDFContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oPDFOptions = oTG.CreateNameValueMap oPDFDataMedium = oTG.CreateDataMedium oPDFOptions.Value("All_Color_AS_Black") = 0 oPDFOptions.Value("Remove_Line_Weights") = 1 oPDFOptions.Value("Vector_Resolution") = 4800 oPDFOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'Generate List of all Documents Referenced for this Assembly. oRefDocs = ThisApplication.ActiveDocument.AllReferencedDocuments 'Generate Document Reference. Dim oDoc As Document 'Peruse each document in generated Documents list. For Each oDoc In oRefDocs 'Generate text string of .idw file to look for in the same folder as component file. idwPathName = Left(oDoc.FullDocumentName, Len(oDoc.FullDocumentName) - 3) & "idw" 'Check if generated drawing file name exists. If System.IO.File.Exists(idwPathName) Then 'Open drawing file. oDrawDoc = ThisApplication.Documents.Open(idwPathName, False) 'Remove idw extension for PDF save. oFileName = Left(oDoc.DisplayName, Len(oDoc.DisplayName) - 3) 'Generate text string of idw name and folder location. oPDFDataMedium.FileName = oFolder + "\" + oFileName + "pdf" 'Save PDF Copy. Call PDFAddIn.SaveCopyAs(oDrawDoc, oPDFContext, oPDFOptions, oPDFDataMedium) 'Close drawing file. oDrawDoc.Close(True) End If Next 'Top Level Document reference. oDoc = ThisApplication.ActiveDocument 'Generate text string of .idw file to look for in the same folder as Assembly file. idwPathName = Left(oDoc.FullDocumentName, Len(oDoc.FullDocumentName) - 3) & "idw" 'Check if generated drawing file name exists. If System.IO.File.Exists(idwPathName) Then 'Open drawing file. oDrawDoc = ThisApplication.Documents.Open(idwPathName, False) 'Remove idw extension for PDF save. oFileName = Left(oDoc.DisplayName, Len(oDoc.DisplayName) - 3) ''Generate text string of idw name and folder location. oPDFDataMedium.FileName = oFolder + "\" + oFileName + "pdf" 'Save PDF Copy. Call PDFAddIn.SaveCopyAs(oDrawDoc, oPDFContext, oPDFOptions, oPDFDataMedium) 'Close drawing file. oDrawDoc.Close(True) End If
There are some things I would like to add/change to make this rule work for me.
1). This rule works from file’s in the workspace. How do I get the latest files from my workspace?
Something like:
DownloadVaultFileToWorkspace("oDoc", False)
2). My sub-assemblies are full of suppressed parts. I want to exclude these files in the PDF plot. I think I need to add something like;
oComps = ThisDoc.Document.ComponentDefinition.Occurrences
For Each oComp In oComps
If oComp.Visible Then
‘batch to PDF
Else
‘do nothing.
End If
Next
3). I would like to divide the batch publish in top level only and anything else in 2 separate folders according to the bom levels ‘Structured’ and ‘Parts Only’.
I have found some Ilogic code to make the reference to the bomview;
Sub Main BOMQuery()
' a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim FirstLevelOnly As Boolean
If MsgBox("First level only?", vbYesNo) = vbYes Then
FirstLevelOnly = True
Else
FirstLevelOnly = False
End If
' a reference to the BOM
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
' whether first level only or all levels.
If FirstLevelOnly Then
oBOM.StructuredViewFirstLevelOnly = True
Else
oBOM.StructuredViewFirstLevelOnly = False
End If
' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True
'a reference to the "Structured" BOMView
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Structured")
Does anyone have any idea how to add these 3 pieces of code together?