Loading data from the .xlsx table into the title block

Loading data from the .xlsx table into the title block

ProRuzneDrobnosti
Contributor Contributor
593 Views
4 Replies
Message 1 of 5

Loading data from the .xlsx table into the title block

ProRuzneDrobnosti
Contributor
Contributor

If ilogic can also be used to load data into a title block (or anywhere into a .dvg drawing sheet) from a .xlsx table? Thank you very much for the answer! 

0 Likes
Accepted solutions (1)
594 Views
4 Replies
Replies (4)
Message 2 of 5

FINET_Laurent
Advisor
Advisor
Accepted solution

Hello @ProRuzneDrobnosti,

 

Yes indeed you can. I made a small set up with :

1. An Excel fine named TitleBlock.xlsx placed inside the active Inventor project

1.1 Inside a table with two columns : properties & their values

FINET_Laurent_0-1704713501440.png

 

2. A custom title block with promts set with the same name as inside the Excel file :

FINET_Laurent_1-1704713574000.png

 

Then, we can make a first function that will gather the information, and fille the titleblock afterward. Here is the sample code in iLogic :

Sub main
	Dim excelTable As Dictionary(Of String, String) = get_inputs
	
	Dim doc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
	Dim titleblock As Inventor.TitleBlock = doc.ActiveSheet.TitleBlock
	Dim s As Inventor.DrawingSketch = titleblock.Definition.Sketch
	
	For Each t As Inventor.TextBox In s.TextBoxes
			For Each k As String In excelTable.Keys
				If t.Text = "<" & k & ">" Then
					titleblock.SetPromptResultText(t, excelTable(k))
					Exit For
					
				End If
			Next
	Next
	
End Sub

Function get_inputs() As Dictionary(Of String, String)
	Dim propertiesColumn As String = "A"
	Dim valuesColumn As String = "B"
	Dim firstLine As Integer = 1
	Dim lastLine As Integer = 3
	
	Dim excelTable As New Dictionary(Of String, String)

	For i As Byte = firstLine To lastLine
		Dim p As String = GoExcel.CellValue("TitleBlock.xlsx", "Tabelle1", propertiesColumn & i)
		Dim v As String = GoExcel.CellValue("TitleBlock.xlsx", "Tabelle1", valuesColumn & i)
		excelTable.Add(p, v)
		
	Next

	GoExcel.Close
	Return excelTable

End Function

Note the properties names  inside excel & the prompt names inside Inventor must perfectly match.

 

FINET_Laurent_2-1704713724854.png

Does this suits your needs ? 

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 3 of 5

ProRuzneDrobnosti
Contributor
Contributor

Wow, it looks like this is what i wanted. I will try to figure it out. Thank you very much!

Message 4 of 5

ProRuzneDrobnosti
Contributor
Contributor

Hello, can I clarify a little? It is necessary to read other data from .xlsx tables for each sheet. Thank you very much

0 Likes
Message 5 of 5

ProRuzneDrobnosti
Contributor
Contributor

Hi again, is it possible to use similar code in ilogic to write to a table (General . ProRuzneDrobnosti_0-1708505939261.png)

 

(not titleblock) Thank you very much for your help!

0 Likes