iLogic to Access embedded excel in part from assembly level

iLogic to Access embedded excel in part from assembly level

andrewiv
Advisor Advisor
927 Views
2 Replies
Message 1 of 3

iLogic to Access embedded excel in part from assembly level

andrewiv
Advisor
Advisor

I'm trying to access an embedded excel file that is in a part from the assembly that the part is used in.  I can't quite figure it out.  Every time I run this iLogic rule its trying to access a spreadsheet embedded in the assembly.  How can I tell Inventor to look at the part and use the excel embedded there instead of the assembly?

Sub Main()
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim oRefDocs As DocumentsEnumerator
oRefDocs = oDoc.AllReferencedDocuments
Dim oRefDoc As Document

	For Each oRefDoc In oRefDocs
		If oRefDoc.DocumentType = kPartDocumentObject Then
		Call Update(oRefDoc)
                End If
        Next
End Sub

Function Update(oEditDoc As Document)
Dim oParams As Inventor.Parameters 
oParams = oEditDoc.ComponentDefinition.Parameters

oParams.ParameterTables.AddExcelTable("C:\MYEXCELFILE.xlsx", "C42", False)
	oXcel = oEditDoc.ReferencedOLEFileDescriptors.Item(1)
	oXcelName = oXcel.DisplayName

        GoExcel.CellValue("3rd Party:" & oXcelName, "Sheet1", "D2") = Parameter1
	GoExcel.CellValue("3rd Party:" & oXcelName, "Sheet1", "D3") = Parameter2
End Function

Andrew In’t Veld
Designer / CAD Administrator

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

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hello, try this Ilogic code in the assembly. You must have embedded the excel table inside the parts.

Sub Main()
Dim oDoc As Document = ThisDoc.Document

	For Each oRefDoc As Document In oDoc.AllReferencedDocuments
		If oRefDoc.DocumentType = kPartDocumentObject Then
		Call Update(oRefDoc)
	            End If
	Next
End Sub

Function Update(oEditDoc As Document)
Dim oParams As Inventor.Parameters 
oParams = oEditDoc.ComponentDefinition.Parameters

On Error Resume Next
Dim oTable As ParameterTable
oTable = oParams.ParameterTables.Item(1)

oXLSheet = oTable.WorkSheet
oXLSheet.Cells.Range("D2").Value = Parameter1
oXLSheet.Cells.Range("D3").Value = Parameter2

End Function

The assembly must have defined the parameters "Parameter1" and "Parameter2"

1.jpg

I hope it will be useful and help you solve your problem

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 3

andrewiv
Advisor
Advisor

Thank you, this worked perfectly.  It's good to know you can access the excel sheet through the parameter tables object instead of the referenced OLE file descriptor.

Andrew In’t Veld
Designer / CAD Administrator

0 Likes