PRINT PDF.......need help skipping reference

PRINT PDF.......need help skipping reference

Anonymous
Not applicable
751 Views
6 Replies
Message 1 of 7

PRINT PDF.......need help skipping reference

Anonymous
Not applicable

So the following code works too good. 

 

It drills down through the BOM and prints PDFS of everything. The problem is that it prints everything including reference assemblies. 

 

Can some one help me with a way to skip reference assemblies and parts.

 

Thanks,

Josh

 

SyntaxEditor Code Snippet

'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)
    
    'INSERT RULE HERE
    

    
    
    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(True)
    
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)
0 Likes
Accepted solutions (2)
752 Views
6 Replies
Replies (6)
Message 2 of 7

HermJan.Otterman
Advisor
Advisor
Accepted solution

I added a few lines..

 

 

'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

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

'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
	 ' added
	 If oRefDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
		 'skip
	 Else
			 
	
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)
    
    'INSERT RULE HERE
    

    
    
    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(True)
    
Else
'If the model has no drawing of the same path and name - do nothing
End If

' added
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)
If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 7

MechMachineMan
Advisor
Advisor

In case like this, you should be also checking to ensure that the only instances of the parts don't have OVERRIDDEN occurrence BOM Structures. I believe your code is simply checking the DEFAULT which is set in the document.

 

You should either be iterating through the Structured BOM (as it properly excludes ALL reference parts), or add in more coding to iterate through the occurrences and skip the occurrences and their children if they are reference components.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 7

Anonymous
Not applicable

Herm Jan Otterman.

Thanks for the help. 

So here is what happened. 

It skipped any top level files marked reference, ie. 707-007-2014.iam

 

 

But it printed all the files in 707-007-2014.iam.

ie 

707-007-2014.iam skipped

-707-007-0107.ipt

-707-007-0108.ipt

-707-007-0109.ipt

-707-007-0110.ipt

 

Any Ideas?

 

Should I rewrite the script to just look at the "Structured" and "PARTS ONLY" bom's?

0 Likes
Message 5 of 7

MechMachineMan
Advisor
Advisor

Using BOM's is definitely the most straightforward, otherwise you need to write a custom function to go through the "assembly structure" to the top level checking if any of the parent parts are reference. As you have found, it's obviously missing that the "Reference status" as inherited by a parent is not stored in the occurrence information Smiley Sad


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 6 of 7

Anonymous
Not applicable
Accepted solution

Here is what we came up with

 

If anyone has a shorter version please post

 

SyntaxEditor Code Snippet

Sub Main()
'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

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

'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
doc = ThisDoc.Document
    Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition
    Dim oBOM As BOM = oAssyDef.BOM

    oBOM.StructuredViewEnabled = True
    oBOM.StructuredViewFirstLevelOnly = False

    Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")

    Dim oBOMRow As BOMRow
    Dim oCompDef As ComponentDefinition

    For Each oBOMRow In oBOMView.BOMRows

     
       If Not oBOMRow.ChildRows Is Nothing
         Call RecurseBOMRow(oBOMRow, PDFAddIn, oFolder)
      End If
       oCompDef = oBOMRow.ComponentDefinitions.Item(1)
idwPathName = Left(oCompDef.Document.FullDocumentName, Len(oCompDef.Document.FullDocumentName) - 3) & "idw"
'check to see that the model has a drawing of the same path and name 'MessageBox.Show(idwPathName)

If(System.IO.File.Exists(idwPathName)) Then
        Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
    oFileName = Left(oCompDef.Document.DisplayName, Len(oCompDef.Document.DisplayName) -3)
    
    'INSERT RULE HERE
    iLogicVb.Automation.RunExternalRule(oDrawDoc, "DELETE1")
    iLogicVb.Automation.RunExternalRule(oDrawDoc, "DELETE2")

    
    
    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(True)
    
Else
'If the model has no drawing of the same path and name - do nothing
End If
    Next



'- - - - - - - - - - - - -
Call PrintTopLevel()
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'open the folder where the new ffiles are saved
Shell("explorer.exe " & oFolder,vbNormalFocus)
End Sub

Sub RecurseBOMRow(oBOMRow As BOMRow, PDFAddIn As ApplicationAddIn, oFolder As String)
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
   For Each oBOMRow In oBOMRow.ChildRows
     Dim oCompDef As ComponentDefinition
     oCompDef = oBOMRow.ComponentDefinitions.Item(1)

idwPathName = Left(oCompDef.Document.FullDocumentName, Len(oCompDef.Document.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(oCompDef.Document.DisplayName, Len(oCompDef.Document.DisplayName) -3)
   
    'INSERT RULE HERE
   iLogicVb.Automation.RunExternalRule(oDrawDoc, "DELETE1")
    iLogicVb.Automation.RunExternalRule(oDrawDoc, "DELETE2")

    
    
    '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(True)
    
Else
'If the model has no drawing of the same path and name - do nothing
End If
     If Not oBOMRow.ChildRows Is Nothing
          Call RecurseBOMRow(oBOMRow, PDFAddIn, oFolder)
     End If
   Next
End Sub
'- - - - - - - - - - - - -

'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
Sub PrintTopLevel()
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

oAsmDrawing = Left(ThisApplication.ActiveDocument.FullDocumentName, Len(ThisApplication.ActiveDocument.FullDocumentName) - 3) & "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
 'oFolder = "C:\Work\Projects\24000\24373\24373-007-7000 PDF Files"
oDataMedium.FileName = oFolder & "\" & oAsmDrawingName & "pdf"
'Write out the PDF
Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
'Close the top level drawing
oAsmDrawingDoc.Close
End Sub


 

0 Likes
Message 7 of 7

MechMachineMan
Advisor
Advisor

In this case, I'd probably cheat and use global variables, as well as taking full advantage of the recursion as such:

 

Sub Main()

'Pre Rule Checks
	If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
		MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
		Exit Sub
	End If

	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
'/Pre Rule Checks

	Dim oAsmDoc As AssemblyDocument
	oAsmDoc = ThisApplication.ActiveDocument
	Dim oAssyDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
	
	oAsmPathAndName = Left(oAsmDoc.FullFileName, Len(oAsmDoc.FullFileName) - 4)
	oAsmDrawingDoc = ThisApplication.Documents.Open(oAsmPathAndName & ".idw", True)
	oAsmDisplayName = Left(oAsmDrawingDoc.DisplayName, Len(oAsmDrawingDoc.DisplayName) -4)
	
	oPath = ThisDoc.Path
	oFolder = oPath & "\" & oAsmDisplayName & " PDF Files"
	Call ConfigPDFSettings(oFolder)

	'Print Top Level

	oDatamedium.FileName = oFolder & "\" & oAsmDisplayName & ".pdf"
	Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDatamedium)
	oAsmDrawingDoc.Close


    Dim oBOM As BOM = oAssyDef.BOM
    oBOM.StructuredViewEnabled = True
    oBOM.StructuredViewFirstLevelOnly = False
    Dim oBOMView As BOMView = oBOM.BOMViews.Item("Structured")
 
 	Call RecurseandPrintBOMRows(oBOMView.BOMRows)

	MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
	Shell("explorer.exe " & oFolder,vbNormalFocus)
End Sub

	Dim oFolder As String
	Dim oContext
	Dim oOptions
	Dim oDatamedium
	Dim PDFAddIn

	Sub RecurseandPrintBOMRows(oBOMRows As BOMRowsEnumerator)
		For Each oBOMRow In oBOMRows
			Dim oCompDef As ComponentDefinition
			oCompDef = oBOMRow.ComponentDefinitions.Item(1)

			idwPathName = Left(oCompDef.Document.FullDocumentName, Len(oCompDef.Document.FullDocumentName) - 3) & "idw"

			If(System.IO.File.Exists(idwPathName)) Then
				Dim oDrawDoc As DrawingDocument
				oDrawDoc = ThisApplication.Documents.Open(idwPathName, True)
				oFileName = Left(oCompDef.Document.DisplayName, Len(oCompDef.Document.DisplayName) - 3)
				
				oDatamedium.FileName = oFolder & "\" & oFileName & "pdf"
				Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDatamedium)
				oDrawDoc.Close(True)
			Else
				'If the model has no drawing of the same path and name - do nothing
			End If
			
			If Not oBOMRow.ChildRows Is Nothing
				Call RecurseandPrintBOMRows(oBOMRow.ChildRows)
			End If
		Next
	End Sub

	Sub ConfigPDFSettings(oFolder As String)
		
		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

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

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes