Description Iproperty behind export file name

Description Iproperty behind export file name

jesserop
Advocate Advocate
527 Views
4 Replies
Message 1 of 5

Description Iproperty behind export file name

jesserop
Advocate
Advocate

Hi all,

 

I'm using the code below to batch export my drawings, which works very good. 
Now I want to add the description of a part behind the file name. 

 

I'm convinced I should add 0description behind this part of the code but it doesn't work. 
Can someone help me in this? 

 

oPDFDataMedium.FileName = oFolder + "\" + oFileName + "pdf"

 

Sub Main
	'get the main assembly document
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	'run the Sub below on the main assembly
	ExportDrawingToPDF(oADoc)

	'Peruse each document in generated Documents list.
	For Each oRefDoc As Document In oADoc.AllReferencedDocuments
		'run the Sub below on each referenced document
		ExportDrawingToPDF(oRefDoc)
	Next
End Sub

Sub ExportDrawingToPDF(oDoc As Document)
	'Set Folder options as you see fit here
	oFolder = ThisDoc.Path + "\" ']

	'PDF Options
	oAddIns = ThisApplication.ApplicationAddIns
	Dim PDFAddIn As TranslatorAddIn = oAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	oTO = ThisApplication.TransientObjects
	oPDFContext = oTO.CreateTranslationContext
	oPDFContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oPDFOptions = oTO.CreateNameValueMap
	oPDFDataMedium = oTO.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 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.
		Dim oDrawDoc As DrawingDocument = ThisApplication.Documents.Open(idwPathName, True)
		'get the value of the description iProperty, within the drawing
		Dim oDescription As String = oDrawDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
		'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.
		PDFAddIn.SaveCopyAs(oDrawDoc, oPDFContext, oPDFOptions, oPDFDataMedium)
		'Close drawing file.
		oDrawDoc.Close(True)
	End If
End Sub

 

 

0 Likes
528 Views
4 Replies
Replies (4)
Message 2 of 5

vpeuvion
Advocate
Advocate

Hi,

Try to replace the two corresponding lines by these:

 

		oFileName = Left(oDoc.DisplayName, Len(oDoc.DisplayName) - 4)
		
		oPDFDataMedium.FileName = oFolder + "\" + oFileName + oDescription + ".pdf"

Hope this can help you.

Vincent. 

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

The part where you are adding in the 'Description' is OK, but subtracting 4 from the end of the DisplayName, instead of 3, then adding ".pdf" instead of "pdf" is just a trade off.

However, since the variable oFolder was defined this way:

 

oFolder = ThisDoc.Path + "\"

 

It already contains the 'directory separator' character, so I would leave that "\" out of your oPDFDataMedium.FileName line, which ever way you do it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 5

jesserop
Advocate
Advocate

Hi, 

I have tried this before, the problem is that it picks the iproperties of te drawing instead of the part. 
Therefore i need to reach the part that is linked to the drawing. 

i'm aware that i can do this manually but since we are using vendor drawings a lot i want to reach the source iproperties if possible. 

 

 

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

If you need to get the 'Description' iProperty value from the 'model' instead of from the drawing, then use the oDoc variable at the start of the line of code you are using to retrieve its value, instead of the oDrawDoc variable.

Dim oDescription As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes