ilogic batch pdf from assembly

ilogic batch pdf from assembly

martinhoos
Advocate Advocate
2,401 Views
15 Replies
Message 1 of 16

ilogic batch pdf from assembly

martinhoos
Advocate
Advocate

Hello Forum,

i tried to modify the folowing code from Curtis Waguespack - but i failed!  In our System the drawings and the components are saved in several folders and subfolders below the workspace! Is it possible to Change the code, that ilogic is looking trough all of the folders and subfolders?

Thank you very much for your help.

Regards

Martin

 

'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)
0 Likes
Accepted solutions (1)
2,402 Views
15 Replies
Replies (15)
Message 2 of 16

bradeneuropeArthur
Mentor
Mentor
could you please show an example of the folder structure.
Like:

Assembly Folder.
|_Drawing Folder

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 16

martinhoos
Advocate
Advocate

Hello Brandeneurope,

our folder structure is "normaly" like:

 

workspace

   2D-Ableitung

   ABS-Teile

   Blechteile

   Einzelteile

   Rohrleitungen

   Zusammenbau

 

This are the folders that we have in the standard, but we can create new folders in each project.

If it is possible, look through all folders below the workspace?!

 

Thank you

Regards Martin

 

 

0 Likes
Message 4 of 16

bradeneuropeArthur
Mentor
Mentor

Hi,

 

I need to know where the drawings are stored.

ie in the same folder as the model files or a specific folder above or below, then how is the folder structure look like?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 16

martinhoos
Advocate
Advocate

Hi Brandeneurope,

the drawings are stored in the folder "2D-Ableitung".

The Folder structure looks like:

workspace

   2D-Ableitung

   ABS-Teile

   Blechteile

   Einzelteile

   Rohrleitungen

   Zusammenbau

 

Regards Martin

0 Likes
Message 6 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@martinhoos,

 

Could please provide sample assembly, parts and associated drawings to test iLogic code?

 

please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 16

martinhoos
Advocate
Advocate

Hi Chandra,

thank you for your reply. I send short sample data.

Regards

Martin

0 Likes
Message 8 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@martinhoos,

 

Thanks for sample data.

 

With samples, understood the folder structures. Try the below modified iLogic code.

 

Sub Main()
	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
	If 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) = vbNo Then
	Exit Sub
	End If
	Dim PDFAddIn As TranslatorAddIn
	Dim oContext As TranslationContext
	Dim oOptions As NameValueMap
	Dim oDataMedium As DataMedium
	Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
	
	oPath = ThisDoc.Path
	oFolder = oPath & "\" & oAsmName & " PDF Files\"
	oPath = System.IO.Directory.GetParent(oPath).FullName 		
	
	If System.IO.Directory.Exists(oFolder) = False Then
		System.IO.Directory.CreateDirectory(oFolder)
	End If
	'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
	Dim oRefDoc As Document
	Dim fileName As String 
	' For Each oRefDoc In oRefDocs = oAsmDoc.AllReferencedDocuments
	For Each oRefDoc In oAsmDoc.AllReferencedDocuments
		oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 3)		
		
		For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw",System.IO.SearchOption.AllDirectories)
			If fileName.EndsWith(oFileName + "idw") = True Then
				Dim oDrawDoc As DrawingDocument
				oDrawDoc = ThisApplication.Documents.Open(fileName, True)
				On Error Resume Next
				oDataMedium.FileName = oFolder & "\" & oFileName & "pdf"
				Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
				oDrawDoc.Close
				On Error GoTo 0
			End If
		Next		
	Next
	'- - - - - - - - - - - - -
	'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
	Dim oAsmDrawingName As String = ThisDoc.FileName(False) 'without extension	

	For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw", System.IO.SearchOption.AllDirectories)	

		If fileName.EndsWith(oAsmDrawingName + ".idw") = True Then
			Dim oAsmDrawingDoc As DrawingDocument
			oAsmDrawingDoc = ThisApplication.Documents.Open(fileName, True)				
			On Error Resume Next
			oDataMedium.FileName = oFolder & oAsmDrawingName & ".pdf"		

			Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
			oAsmDrawingDoc.Close
			On Error GoTo 0
		End If
	Next	
	MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
	Shell("explorer.exe " & oFolder,vbNormalFocus)
End Sub

Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
	oPath = ThisDoc.Path
	PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oOptions.Value("All_Color_AS_Black") = 1
	oOptions.Value("Remove_Line_Weights") = 0
	oOptions.Value("Vector_Resolution") = 400
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	oOptions.Value("Custom_Begin_Sheet") = 1
	oOptions.Value("Custom_End_Sheet") = 1
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
End Sub

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 9 of 16

martinhoos
Advocate
Advocate

Hello Chandra,

thanks for your reply - your code is great.

Thank you very much for your help.

Regards

Martin

0 Likes
Message 10 of 16

cmcconnell
Collaborator
Collaborator

Hello,

 

I am trying to modify your code to work how we need it to.

I am having a couple issues:

  1. I have tried to append the rev number to the pdf filename - for some reason, it is appending the rev number of the assembly to all of the pdfs
  2. It is leaving drawings of the assembly and the sub assemblies open after it is complete

I am sure it is something simple. 🙂

 

Here is what I have done so far:

Sub Main()
	Dim oDoc As Document
    oDoc = ThisDoc.Document
    oDocName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
    
    If Not (oDoc.DocumentType = kAssemblyDocumentObject Or oDoc.DocumentType = kDrawingDocumentObject) Then
        MessageBox.Show("Please run this rule from the assembly or assembly drawing file.", "iLogic")
        Exit Sub
    End If
	
	'get user input
	If 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) = vbNo Then
	Exit Sub
	End If
	Dim PDFAddIn As TranslatorAddIn
	Dim oContext As TranslationContext
	Dim oOptions As NameValueMap
	Dim oDataMedium As DataMedium
	Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
	
	oPath = ThisDoc.Path
	oFolder = "C:\PDF" & "\" & oAsmName & " PDF Files\"
	oPath = System.IO.Directory.GetParent(oPath).FullName 		
	
	If System.IO.Directory.Exists(oFolder) = False Then
		System.IO.Directory.CreateDirectory(oFolder)
	End If
	
	'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
	Dim oRefDoc As Document
	Dim fileName As String
	
	For Each oRefDoc In oDoc.AllReferencedDocuments
	oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 4)		
		
		For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw",System.IO.SearchOption.AllDirectories)
			If fileName.EndsWith(oFileName + ".idw") = True Then
				Dim oDrawDoc As DrawingDocument
				oDrawDoc = ThisApplication.Documents.Open(fileName, True)				
				On Error Resume Next
				oRevNum = iProperties.Value("Project", "Revision Number")
				oDataMedium.FileName = oFolder & "\" & oFileName & "-R" & oRevNum & ".pdf"
				Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
				oDrawDoc.Close
				On Error GoTo 0
			End If
		Next		
	Next
	'- - - - - - - - - - - - -
	
	'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
	Dim oAsmDrawingName As String = ThisDoc.FileName(False) 'without extension	

	For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw", System.IO.SearchOption.AllDirectories)	

		If fileName.EndsWith(oAsmDrawingName + ".idw") = True Then
			Dim oAsmDrawingDoc As DrawingDocument
			oAsmDrawingDoc = ThisApplication.Documents.Open(fileName, True)
			oAsmRevNum = iProperties.Value("Project", "Revision Number")
			On Error Resume Next
			oDataMedium.FileName = oFolder & oAsmDrawingName & "-R" & oAsmRevNum & ".pdf"		

			Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
			oAsmDrawingDoc.Close
			On Error GoTo 0
		End If
	Next	
	MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
	Shell("explorer.exe " & oFolder,vbNormalFocus)
End Sub

Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
	oPath = ThisDoc.Path
	PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oOptions.Value("All_Color_AS_Black") = 0
	oOptions.Value("Remove_Line_Weights") = 0
	oOptions.Value("Vector_Resolution") = 400
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	'oOptions.Value("Custom_Begin_Sheet") = 1
	'oOptions.Value("Custom_End_Sheet") = 1
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
End Sub
Mechanix Design Solutions inc.
0 Likes
Message 11 of 16

MechMachineMan
Advisor
Advisor

1. The "basic" iProperty call only corresponds to the DOCUMENT of which the rule is run from. You need to add in a document identifier to get it to access iProperties from another file (only valid for files that are children of the current document).

 

iproperties.Value(System.IO.Path.GetFileName(filename), "Project", "Part Number")

2. You should probably remove the error catching surrounding the iProperties/save commands.

2. Use Application.SilentOperation = True at the start of the code, and Application.SilentOperation = False at the end.

 

Sub Main()
	Dim oDoc As Document
    oDoc = ThisDoc.Document
    oDocName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
    
    If Not (oDoc.DocumentType = kAssemblyDocumentObject Or oDoc.DocumentType = kDrawingDocumentObject) Then
        MessageBox.Show("Please run this rule from the assembly or assembly drawing file.", "iLogic")
        Exit Sub
    End If
 
Application.SilentOperation = True 'get user input If 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) = vbNo Then Exit Sub End If Dim PDFAddIn As TranslatorAddIn Dim oContext As TranslationContext Dim oOptions As NameValueMap Dim oDataMedium As DataMedium Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium) oPath = ThisDoc.Path oFolder = "C:\PDF" & "\" & oAsmName & " PDF Files\" oPath = System.IO.Directory.GetParent(oPath).FullName If System.IO.Directory.Exists(oFolder) = False Then System.IO.Directory.CreateDirectory(oFolder) End If '- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly Dim oRefDoc As Document Dim fileName As String For Each oRefDoc In oDoc.AllReferencedDocuments oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 4) For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw",System.IO.SearchOption.AllDirectories) If fileName.EndsWith(oFileName + ".idw") = True Then Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Open(fileName, True) oRevNum = iProperties.Value(System.IO.Path.GetFileName(fileName), "Project", "Revision Number") oDataMedium.FileName = oFolder & "\" & oFileName & "-R" & oRevNum & ".pdf" Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium) oDrawDoc.Close(True) End If Next Next '- - - - - - - - - - - - - '- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - - Dim oAsmDrawingName As String = ThisDoc.FileName(False) 'without extension For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw", System.IO.SearchOption.AllDirectories) If fileName.EndsWith(oAsmDrawingName + ".idw") = True Then Dim oAsmDrawingDoc As DrawingDocument oAsmDrawingDoc = ThisApplication.Documents.Open(fileName, True) oAsmRevNum = iProperties.Value("Project", "Revision Number") oDataMedium.FileName = oFolder & oAsmDrawingName & "-R" & oAsmRevNum & ".pdf" Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium) oAsmDrawingDoc.Close(True) End If Next

Application.SilentOperation = False MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic") Shell("explorer.exe " & oFolder,vbNormalFocus) End Sub Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium) oPath = ThisDoc.Path PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oOptions.Value("All_Color_AS_Black") = 0 oOptions.Value("Remove_Line_Weights") = 0 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'oOptions.Value("Custom_Begin_Sheet") = 1 'oOptions.Value("Custom_End_Sheet") = 1 oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 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
Message 12 of 16

cmcconnell
Collaborator
Collaborator

Thanks for the response!

 

You are speaking a bit over my head. Here is what I did:

  1. I modified the line you provided for my oRevNum variable and placed that in the component drawings area. It makes oRevNum = nothing. SO I end up with filename-R.pdf.
  2. This is over my head. 😞
  3. When I put theses 2 lines in, where you suggest, I get an error when I save the rule:  'Application' is ambiguous, imported from the namespaces or types 'Inventor, System.Windows.Forms'.
  4. Adding (true) to the close operations seems to have fixed the leaving drawings open issue.

Here is what my code looks like now:

Sub Main()
	Dim oDoc As Document
    oDoc = ThisDoc.Document
    oDocName = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\" & System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
    
    If Not (oDoc.DocumentType = kAssemblyDocumentObject Or oDoc.DocumentType = kDrawingDocumentObject) Then
        MessageBox.Show("Please run this rule from the assembly or assembly drawing file.", "iLogic")
        Exit Sub
    End If
	
	Application.SilentOperation = True
		'get user input
		If MessageBox.Show ( _
		"This will create a PDF file for all of the assembly components that have drawing 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) = vbNo Then
		Exit Sub
		End If
		Dim PDFAddIn As TranslatorAddIn
		Dim oContext As TranslationContext
		Dim oOptions As NameValueMap
		Dim oDataMedium As DataMedium
		Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
	
		oPath = ThisDoc.Path
		oFolder = "C:\PDF" & "\" & oAsmName & " PDF Files\"
		oPath = System.IO.Directory.GetParent(oPath).FullName 		
		
		If System.IO.Directory.Exists(oFolder) = False Then
			System.IO.Directory.CreateDirectory(oFolder)
		End If
		
		'- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - -'look at the files referenced by the assembly
		Dim oRefDoc As Document
		Dim fileName As String
		
		For Each oRefDoc In oDoc.AllReferencedDocuments
		oFileName = Left(oRefDoc.DisplayName, Len(oRefDoc.DisplayName) - 4)		
			
			For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw",System.IO.SearchOption.AllDirectories)
				If fileName.EndsWith(oFileName + ".idw") = True Then
					Dim oDrawDoc As DrawingDocument
					oDrawDoc = ThisApplication.Documents.Open(fileName, True)				
					On Error Resume Next
					oRevNum = iProperties.Value(System.IO.Path.GetFileName(fileName), "Project", "Revision Number")
					oDataMedium.FileName = oFolder & "\" & oFileName & "-R" & oRevNum & ".pdf"
					Call PDFAddIn.SaveCopyAs(oDrawDoc, oContext, oOptions, oDataMedium)
					oDrawDoc.Close(True)
					On Error GoTo 0
				End If
			Next		
		Next
		'- - - - - - - - - - - - -
		
		'- - - - - - - - - - - - -Top Level Drawing - - - - - - - - - - - -
		Dim oAsmDrawingName As String = ThisDoc.FileName(False) 'without extension	

		For Each fileName In System.IO.Directory.GetFiles(oPath, "*.idw", System.IO.SearchOption.AllDirectories)	

			If fileName.EndsWith(oAsmDrawingName + ".idw") = True Then
				Dim oAsmDrawingDoc As DrawingDocument
				oAsmDrawingDoc = ThisApplication.Documents.Open(fileName, True)
				oAsmRevNum = iProperties.Value("Project", "Revision Number")
				On Error Resume Next
				oDataMedium.FileName = oFolder & oAsmDrawingName & "-R" & oAsmRevNum & ".pdf"		

				Call PDFAddIn.SaveCopyAs(oAsmDrawingDoc, oContext, oOptions, oDataMedium)
				oAsmDrawingDoc.Close(True)
				On Error GoTo 0
			End If
		Next	
	
	Application.SilentOperation = False
	MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
	Shell("explorer.exe " & oFolder,vbNormalFocus)
End Sub

Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
	oPath = ThisDoc.Path
	PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oOptions.Value("All_Color_AS_Black") = 0
	oOptions.Value("Remove_Line_Weights") = 0
	oOptions.Value("Vector_Resolution") = 400
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
	'oOptions.Value("Custom_Begin_Sheet") = 1
	'oOptions.Value("Custom_End_Sheet") = 1
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
End Sub

 

Mechanix Design Solutions inc.
0 Likes
Message 13 of 16

Jesper_S
Collaborator
Collaborator

Hi.

 

Try this for the Rev number problem.

 

oRevNum = oDrawDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value
oAsmRevNum = oAsmDrawingDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value

//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Message 14 of 16

corym
Advocate
Advocate

That seems to have cured it! thanks.

Cory McConnell
0 Likes
Message 15 of 16

Hi. How can I make this work in Inventor 2015? I guess that add-in 

0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4 

is not found because the rule creates folders but no PDFs. I usually just use the native Inventor export to pdf button, which seems to have the same options as the one referenced in the rule, but not sure if it's a different add-in. I did a google search for that ID to try to find out what add-in that is, but all I found were more rules referring to the same add-in.

Thanks. 

0 Likes
Message 16 of 16

chandra.shekar.g
Autodesk Support
Autodesk Support

@SometimesInventorMakesMeAngry,

 

Sorry for inconvenience,

 

To test the scenario, Inventor 2015 is unavailable in my system.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes