Rule to PDF all drawings with Part Number instead of File Name

Rule to PDF all drawings with Part Number instead of File Name

matthew.johnson200
Enthusiast Enthusiast
223 Views
2 Replies
Message 1 of 3

Rule to PDF all drawings with Part Number instead of File Name

matthew.johnson200
Enthusiast
Enthusiast

Hi, I have 2 iLogic rules which both PDF drawings. One PDFs just a single drawing, whichever drawing on the screen when the rule is run. The other PDFs all the drawings in the same folder as where the currently opened drawing is saved. The problem I have is the single PDF rule saves the file with part number and revision, whereas the one which saves multiple saves the file name and revision instead. Sometimes in our company these are different as we use an internal numbering system for the file name, but sometimes we needs a suppliers number which we put in the part number. I would like the multiple PDF rule to export the PDF with the part number & revision. I'm sure its relatively simple but I cant figure it out. the 2 rules are below.

 

Thanks in advanced.

 

Single PDF Rule (working fine):

Sub Main()

Dim oDoc As Document
oDoc = ThisDoc.Document
Dim PDFAddIn As TranslatorAddIn
Dim oContext As TranslationContext
Dim oOptions As NameValueMap
Dim oDataMedium As DataMedium
Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
oFolder = "C:\Pdfs"

'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)
	MessageBox.Show("DRAWINGS WILL BE SAVED IN C:\Pdfs", "PDF")

End If


'oBaseName = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)

oBaseName = iProperties.Value("Project", "Part Number") 
oBaseName=oBaseName & "-" & iProperties.Value("Project", "Revision Number") 

oDataMedium.FileName = oFolder & "\" & oBaseName & ".pdf"


Call PDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)


End Sub
Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
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
'

 Multiple PDF Rule (To be changed to use the part number instead of file name):

 Sub Main
	 	 
    Dim processPath As String
	Dim oDoc As Document
	oDoc = ThisDoc.Document
	Dim PDFAddIn As TranslatorAddIn
	Dim oContext As TranslationContext
	Dim oOptions As NameValueMap
	Dim oDataMedium As DataMedium
	Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
	oFolder = "C:\Pdfs"

	'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)
		MessageBox.Show("DRAWINGS WILL BE SAVED IN C:\Pdfs", "PDF")

	End If

	CurFileName = oDoc.FullFileName
	FNamePos = InStrRev(CurFileName, "\", -1)   

	Name = Right(CurFileName, Len(CurFileName) - FNamePos)
	processPath = Left(CurFileName, Len(CurFileName) - Len(Name))
	
    Dim filenames() As String
    filenames = System.IO.Directory.GetFiles(processPath, "*.dwg")
	
    For Each filename As String In filenames
				
	 	oDoc=ThisApplication.Documents.Open(filename, True)
		
		oBaseName = System.IO.Path.GetFileNameWithoutExtension(filename)
		
		oBaseName=oBaseName & "-" & oDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value
		
		oDataMedium.FileName = oFolder & "\" & oBaseName & ".pdf"
	
		Call PDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
			
    Next

	
End Sub 


Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
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

 

0 Likes
Accepted solutions (1)
224 Views
2 Replies
Replies (2)
Message 2 of 3

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@matthew.johnson200 , this should work.

 

Hope that help, Curtis

 

Sub Main

	Dim processPath As String
	Dim oDoc As Document
	oDoc = ThisDoc.Document
	Dim PDFAddIn As TranslatorAddIn
	Dim oContext As TranslationContext
	Dim oOptions As NameValueMap
	Dim oDataMedium As DataMedium
	Call ConfigurePDFAddinSettings(PDFAddIn, oContext, oOptions, oDataMedium)
	oFolder = "C:\Pdfs"

	'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)
		MessageBox.Show("DRAWINGS WILL BE SAVED IN C:\Pdfs", "PDF")
	End If

	CurFileName = oDoc.FullFileName
	FNamePos = InStrRev(CurFileName, "\", -1)

	Name = Right(CurFileName, Len(CurFileName) -FNamePos)
	processPath = Left(CurFileName, Len(CurFileName) -Len(Name))

	Dim filenames() As String
	filenames = System.IO.Directory.GetFiles(processPath, "*.dwg")

	For Each filename As String In filenames

		oDoc = ThisApplication.Documents.Open(filename, True)
		oPartNumber = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
		oRevNumber = oDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value
		oBaseName = oPartNumber & "-" & oRevNumber
		oDataMedium.FileName = oFolder & "\" & oBaseName & ".pdf"
		Call PDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
	Next
End Sub


Sub ConfigurePDFAddinSettings(ByRef PDFAddIn As TranslatorAddIn, ByRef oContext As TranslationContext, ByRef oOptions As NameValueMap, ByRef oDataMedium As DataMedium)
	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

 

EESignature

0 Likes
Message 3 of 3

matthew.johnson200
Enthusiast
Enthusiast

That works great. Exactly what I wanted. 

 

Thanks for your help!