Add Custom properties to all subassemblies and parts

Add Custom properties to all subassemblies and parts

kresh.bell
Collaborator Collaborator
316 Views
2 Replies
Message 1 of 3

Add Custom properties to all subassemblies and parts

kresh.bell
Collaborator
Collaborator

Hi,

I have iLogic for import project custom properties from xls which generated ERP system. It works ok. I use that iLogic in my top assembly. But I would like, if it's possible, when I import custom property in e.g. top assembly that all my subassemblies and parts also have this properties.

 

And one minor thing, is it possible after importing that iLogic generate message "All Custom Properties Successfully Imported"?

 

Dim odoc = ThisDoc.Document
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)

oFileDlg.Filter = "Spredsheet Files (*.xls) (*.xlsx) (*.xlsm) (*.xlsb)|*.xls; *.xlsx; *.xlsm; *.xlsb"

'Set open location using one of these 2 options below, "1)Hard coded" or "2)Project location":
'oFileDlg.InitialDirectory = "D:\INVENTOR DATA\PROJEKTI\"  'Hard Coded path:
oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath

'Show File Open Dialogue
oFileDlg.DialogTitle = "Browse for XLS File"
oFileDlg.ShowOpen()
oXLfile = oFileDlg.FileName
If oXLfile = "" Then : Return : End If
iProperties.Value("Custom", "Referenced Spreadsheet File Name") = oXLfile

'Open Excel file
GoExcel.Open(oXLfile, "Job Sheet")

'Read from Excel file
iProperties.Value("Custom", "AreaCode") = GoExcel.CellValue("H4")
iProperties.Value("Custom", "AreaName") = GoExcel.CellValue("C4")
iProperties.Value("Custom", "ComponentCode") = GoExcel.CellValue("H7")
iProperties.Value("Custom", "ComponentName") = GoExcel.CellValue("C7")
iProperties.Value("Custom", "Priority") = GoExcel.CellValue("P7")
iProperties.Value("Custom", "D365WoNumber") = GoExcel.CellValue("H8")
iProperties.Value("Custom", "DWGName") = GoExcel.CellValue("C6")
iProperties.Value("Custom", "DWGRef") = GoExcel.CellValue("H6")
iProperties.Value("Custom", "FSCReg") = GoExcel.CellValue("N20")
iProperties.Value("Custom", "HealthSafetySheets") = GoExcel.CellValue("H19")
iProperties.Value("Custom", "IssuedTo") = GoExcel.CellValue("P6")
iProperties.Value("Custom", "ItemCode") = GoExcel.CellValue("H5")
iProperties.Value("Custom", "ItemName") = GoExcel.CellValue("C5")
iProperties.Value("Custom", "JobDescription") = GoExcel.CellValue("A9")
iProperties.Value("Custom", "LoadList") = GoExcel.CellValue("C20")
iProperties.Value("Custom", "Notes01") = GoExcel.CellValue("A10")
iProperties.Value("Custom", "Notes02") = GoExcel.CellValue("A11")
iProperties.Value("Custom", "Notes03") = GoExcel.CellValue("A12")
iProperties.Value("Custom", "Notes04") = GoExcel.CellValue("A13")
iProperties.Value("Custom", "Notes05") = GoExcel.CellValue("A14")
iProperties.Value("Custom", "Notes06") = GoExcel.CellValue("A15")
iProperties.Value("Custom", "Notes07") = GoExcel.CellValue("A16")
iProperties.Value("Custom", "Notes08") = GoExcel.CellValue("A17")
iProperties.Value("Custom", "Notes09") = GoExcel.CellValue("A18")
iProperties.Value("Custom", "ProjectCode") = GoExcel.CellValue("H3")
iProperties.Value("Custom", "Project_Name") = GoExcel.CellValue("C3")
iProperties.Value("Custom", "RefDrawing") = GoExcel.CellValue("C6")
iProperties.Value("Custom", "TehnicalDataSheets") = GoExcel.CellValue("P19")
iProperties.Value("Custom", "LoadList") = GoExcel.CellValue("C20")
iProperties.Value("Custom", "UnitQty1") = GoExcel.CellValue("A22")
iProperties.Value("Custom", "UnitQty2") = GoExcel.CellValue("A23")
iProperties.Value("Custom", "UnitQty3") = GoExcel.CellValue("A24")
iProperties.Value("Custom", "UnitName1") = GoExcel.CellValue("B22")
iProperties.Value("Custom", "UnitName2") = GoExcel.CellValue("B23")
iProperties.Value("Custom", "UnitName3") = GoExcel.CellValue("B24")
iProperties.Value("Custom", "UnitEmpty1") = GoExcel.CellValue("C22")
iProperties.Value("Custom", "UnitEmpty2") = GoExcel.CellValue("C23")
iProperties.Value("Custom", "UnitEmpty3") = GoExcel.CellValue("C24")
iProperties.Value("Custom", "UnitDescription1") = GoExcel.CellValue("D22")
iProperties.Value("Custom", "UnitDescription2") = GoExcel.CellValue("D23")
iProperties.Value("Custom", "UnitDescription3") = GoExcel.CellValue("D24")

'Close Excel file
GoExcel.Close

 

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

A.Acheson
Mentor
Mentor
Accepted solution

Hi @kresh.bell 

 

To do this you need a few things, target all the documents of the assembly through referenced documents. Next you need to target the iproperty in each document. The filename with extension is read using System.IO

AAcheson_0-1694382283739.png

 

Sub Main
	
	Dim fileDlg As Inventor.FileDialog = Nothing
	InventorVb.Application.CreateFileDialog(fileDlg)

	fileDlg.Filter = "Spredsheet Files (*.xls) (*.xlsx) (*.xlsm) (*.xlsb)|*.xls; *.xlsx; *.xlsm; *.xlsb"

	'Set open location using one of these 2 options below, "1)Hard coded" or "2)Project location":
	'fileDlg.InitialDirectory = "D:\INVENTOR DATA\PROJEKTI\"  'Hard Coded path:
	fileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath

	'Show File Open Dialogue
	fileDlg.DialogTitle = "Browse for XLS File"
	fileDlg.ShowOpen()
	
	Dim xlFile As String  = fileDlg.FileName
	If xlFile = "" Then : Exit Sub: End If

	'Open Excel file.
	GoExcel.Open(xlFile, "Job Sheet")

	Dim doc As Document = ThisDoc.Document
	Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(doc, "Custom Properties Import") 'Make this a single transaction
	Dim filename As String  = Nothing
	
	processDocument(filename,xlFile)
	
	If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then 
		
		'Traverse all referenced documents.
		For Each refDoc As Document In doc.AllReferencedDocuments 
			
			'Avoid readonly files like CC and Library.
			If refDoc.IsModifiable Then
				filename = IO.Path.GetFileName(refDoc.FullFileName)
				processDocument(filename,xlFile)
			End If
			
		Next
	End If
	
	'Close Excel file.
	GoExcel.Close
	
	trans.End 'End the trasaction
	
	MessageBox.Show("All Custom Properties Successfully Imported", "iLogic")

End Sub

Sub processDocument(filename As String, xlFile As String)

	'Read from Excel file
	iProperties.Value(filename,"Custom", "Referenced Spreadsheet File Name") = xlFile
	iProperties.Value(filename,"Custom", "AreaCode") = GoExcel.CellValue("H4")
	iProperties.Value(filename,"Custom", "AreaName") = GoExcel.CellValue("C4")
	iProperties.Value(filename,"Custom", "ComponentCode") = GoExcel.CellValue("H7")
	iProperties.Value(filename,"Custom", "ComponentName") = GoExcel.CellValue("C7")
	iProperties.Value(filename,"Custom", "Priority") = GoExcel.CellValue("P7")
	iProperties.Value(filename,"Custom", "D365WoNumber") = GoExcel.CellValue("H8")
	iProperties.Value(filename,"Custom", "DWGName") = GoExcel.CellValue("C6")
	iProperties.Value(filename,"Custom", "DWGRef") = GoExcel.CellValue("H6")
	iProperties.Value(filename,"Custom", "FSCReg") = GoExcel.CellValue("N20")
	iProperties.Value(filename,"Custom", "HealthSafetySheets") = GoExcel.CellValue("H19")
	iProperties.Value(filename,"Custom", "IssuedTo") = GoExcel.CellValue("P6")
	iProperties.Value(filename,"Custom", "ItemCode") = GoExcel.CellValue("H5")
	iProperties.Value(filename,"Custom", "ItemName") = GoExcel.CellValue("C5")
	iProperties.Value(filename,"Custom", "JobDescription") = GoExcel.CellValue("A9")
	iProperties.Value(filename,"Custom", "LoadList") = GoExcel.CellValue("C20")
	iProperties.Value(filename,"Custom", "Notes01") = GoExcel.CellValue("A10")
	iProperties.Value(filename,"Custom", "Notes02") = GoExcel.CellValue("A11")
	iProperties.Value(filename,"Custom", "Notes03") = GoExcel.CellValue("A12")
	iProperties.Value(filename,"Custom", "Notes04") = GoExcel.CellValue("A13")
	iProperties.Value(filename,"Custom", "Notes05") = GoExcel.CellValue("A14")
	iProperties.Value(filename,"Custom", "Notes06") = GoExcel.CellValue("A15")
	iProperties.Value(filename,"Custom", "Notes07") = GoExcel.CellValue("A16")
	iProperties.Value(filename,"Custom", "Notes08") = GoExcel.CellValue("A17")
	iProperties.Value(filename,"Custom", "Notes09") = GoExcel.CellValue("A18")
	iProperties.Value(filename,"Custom", "ProjectCode") = GoExcel.CellValue("H3")
	iProperties.Value(filename,"Custom", "Project_Name") = GoExcel.CellValue("C3")
	iProperties.Value(filename,"Custom", "RefDrawing") = GoExcel.CellValue("C6")
	iProperties.Value(filename,"Custom", "TehnicalDataSheets") = GoExcel.CellValue("P19")
	iProperties.Value(filename,"Custom", "LoadList") = GoExcel.CellValue("C20")
	iProperties.Value(filename,"Custom", "UnitQty1") = GoExcel.CellValue("A22")
	iProperties.Value(filename,"Custom", "UnitQty2") = GoExcel.CellValue("A23")
	iProperties.Value(filename,"Custom", "UnitQty3") = GoExcel.CellValue("A24")
	iProperties.Value(filename,"Custom", "UnitName1") = GoExcel.CellValue("B22")
	iProperties.Value(filename,"Custom", "UnitName2") = GoExcel.CellValue("B23")
	iProperties.Value(filename,"Custom", "UnitName3") = GoExcel.CellValue("B24")
	iProperties.Value(filename,"Custom", "UnitEmpty1") = GoExcel.CellValue("C22")
	iProperties.Value(filename,"Custom", "UnitEmpty2") = GoExcel.CellValue("C23")
	iProperties.Value(filename,"Custom", "UnitEmpty3") = GoExcel.CellValue("C24")
	iProperties.Value(filename,"Custom", "UnitDescription1") = GoExcel.CellValue("D22")
	iProperties.Value(filename,"Custom", "UnitDescription2") = GoExcel.CellValue("D23")
	iProperties.Value(filename,"Custom", "UnitDescription3") = GoExcel.CellValue("D24")

End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 3

kresh.bell
Collaborator
Collaborator

It works great, thanks 

0 Likes