Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic Custom Table from Title Attribute IDW

16 REPLIES 16
Reply
Message 1 of 17
brianmD486F
691 Views, 16 Replies

iLogic Custom Table from Title Attribute IDW

Hi All,

I've never messed with Tables and iLogic that much but figured this might be simple. Lot of my projects can be multiple pages. Instead of constantly making a Table every time and re-entering everything, is there a way for iLogic to find the Title Attribute and Sheet Number and throw them into a table? Pretty much would be 2 Rows but the # of columns are always changing. 

 

 

brianmD486F_0-1668629660085.png

 

16 REPLIES 16
Message 2 of 17

Is this a real table or are you using sketched symbols?

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 3 of 17

Should be a real table? Could you explain more about what you mean by symbols? Let me snag a sample of the edited sheet.

brianmD486F_0-1668689019091.png

All but like one is in the iproperties window that I Add/Edit.

 

Really just wanna pull a Table from all the sheets with the corresponding sheet numbers it calls and then the title/subject (just a general idea and ill see which works). But they are all prompted entries too. 

 

Hopefully that helped @bradeneuropeArthur 

Message 4 of 17
WCrihfield
in reply to: brianmD486F

Hi @brianmD486F.  Just to clarify... Your drawings usually have multiple sheets, so you want to create a custom table that lists what each sheet in the drawing is for, right?  Which sheet would this new custom table be on?...or would there be one on each sheet?  You said that this table would have 2 rows, but the number of columns changes a lot, right?  Is one row for the title, and the other row for the sheet name?  What about subject...should there be a row for that too.  Is the title on each sheet a prompted entry, or is it pulled from iProperties?  If pulled from iProperties, is it pulled from the iProperties of the drawing itself, or from the iProperties of the model document?  Is it the standard title iProperty, or a custom iProperty named "Title"?  What do the columns represent?  Should there be a column for each sheet?  Is there a first column just for row titles, then the columns for the sheets are after that, to the right?  Finding a specific prompted entry on each sheet is already fairly complicated, because you usually have to dig down into the title block, then the title block's definition, then into its sketch, then into its TextBoxes, then you have to somehow figure out which TextBox is for that specific prompted entry, then you have to extract its current value.  But when its someone else's drawing, and that drawings is not available for testing on, the task becomes even more complicated.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 17
brianmD486F
in reply to: WCrihfield

Thanks for getting back to me on this. 

 

There will just be one table and on my first sheet. I never know how many total sheets there will be for any project till the end. So, I wouldn't care if I had to go in and adjust numbers for that if needed. The goal for this is to make an easy Table of Contents on the first page without remaking these every time. I'll attach an example of what it would look like. 

 

brianmD486F_0-1668716762644.png

brianmD486F_1-1668716879424.png

So, something like this.

 

Reading your description of what makes it complicated sounds like this would get complicated. They are all prompted entries inside the title block so sounds like this might be harder than I was thinking. Which if so, then it's not a big deal. It was an idea I thought would save me some time without having to always make a table and change out page numbers and descriptions. Do the text boxes change based on how many sheets? Like say Prompt text box 1 could be Prompt Text Box 20 on page 2 instead? I could probably send a dumbed down version of it without any vital information, but don't want to bog you down if it's going to be a big mission to make this hahaha. 

 

 

Message 6 of 17
WCrihfield
in reply to: brianmD486F

Hi @brianmD486F.  I think I understand now what is needed.  But as I mentioned before this is a fairly complex task to automate by code, and has a lot of stuff in the code that must be just right, and specific to your drawings, in order for it to come out right.  There are several things that could potentially make this code not work as planned.  But below is some code I created for you, that may do this task for you...if I haven't made any little mistakes anywhere within.  The CustomTables.Add method requires many pieces of information as input, and each bit of it must be created by the code before it gets to that method.  There are many Array's being used in this code.  Arrays can be complicated to use, because they start at zero, not one, and are a set size, not variable size.  When you initiate one, if you do not specify its size, then you must supply all of its values in that initial line of code.  If you specify its size when you create it, then you can set its values in later code, but they can not 'easily' add or subtract from its set number of entries.  The array's you input into this method's third, though its eighth input variable must exactly match the number of cells for that specific data, or it will throw an error.  Take a good look at every line of code and attempt to understand what I am trying to do there, to build up the input data needed to use this one final method.

 

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oFirstSheet As Sheet = oDDoc.Sheets.Item(1)
oFirstSheet.Activate 'make sure we start with first sheet
Dim oTitle As String = "TABLE OF CONTENTS"
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oPoint As Point2d = oTG.CreatePoint2d(0, 0)
'this code uses a lot of Arrays
'Arrays start with Item zero, not Item 1.

Dim oCols As Integer = 2 'number of columns
Dim oRows As Integer = oDDoc.Sheets.Count 'number of rows
'Number of column titles supplied must match number of columns specified
Dim oColTitles() As String = {"SHEET NO.", "DESCRIPTION"}

'Contents must be a 'single dimension' array of String.
'the number of entries supplied in Contents must match the number of cells in the table
Dim oCells As Integer = ((oCols * oRows) -1) 'minus the 1, because an array starts at zero, instead of 1
Dim oContents(oCells) As String
Dim oSheetItem As Integer = 0
For oCell As Integer = 0 To oCells
	oSheetItem = oSheetItem + 1
	Dim oSheet As Sheet = oDDoc.Sheets.Item(oSheetItem)
	oSheet.Activate
	Dim oTB As TitleBlock = oSheet.TitleBlock
	Dim oDSketch As DrawingSketch = oTB.Definition.Sketch
	Dim oSheetNo As String = "" 'making sure value is clear time
	Dim oDescription As String = "" 'making sure value is clear time
	For Each oTBox As Inventor.TextBox In oDSketch.TextBoxes
		If oTBox.FormattedText.Contains("<Prompt>SHEET NUMBER</Prompt>") Then
			oSheetNo = oTB.GetResultText(oTBox)
		End If
		If oTBox.FormattedText.Contains("<Prompt>TITLE</Prompt>") Then
			oDescription = oTB.GetResultText(oTBox)
		End If
	Next 'oTBox
	oContents(oCell) = oSheetNo
	oCell = oCell + 1
	oContents(oCell) = oDescription
Next 'oCell

Dim oColWidths() As Double = {3, 6}

Dim oRowHeights(oRows - 1) As Double
For oRH As Integer = 0 To UBound(oRowHeights)
	oRowHeights(oRH) = .25
Next
oFirstSheet.Activate
Dim oCTable As CustomTable = oFirstSheet.CustomTables.Add(oTitle, oPoint, oCols, oRows, oColTitles, oContents, oColWidths, oRowHeights)

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 17
brianmD486F
in reply to: WCrihfield

Wow thanks for all this and the explaination, Ill be going through all this, this weekend and seeing what I can tweak and what will work. Now looking at things, Im wondering would it have been easier to take the Sheet name on the model browser and have that information taken instead? I didnt think about it at first, but dont know if thats easier or harder. These will always match in a sense with the sheet number and description to whats on the actually title block entries.

brianmD486F_0-1668780274086.png

But figured Id bring it up and ask haha. 

 

Message 8 of 17
dlongley
in reply to: WCrihfield

Just jumping in here, looking for something similar, but grabs the Sheet.Name and Sheet.Revision for each sheet in the drawing file, and drops them into Custom table.

 

I tried modifying the code, but it keeps tripping out at Line 7 with a "Class not registered" error.

 

I thought I must have stuffed something up in my mods, but even just copying and pasting directly did not help.

 

Does this work in 2023 (which I'm using), or is it something only from 2024?  

 

Thanks,

Derek

Message 9 of 17
dlongley
in reply to: dlongley

Please forget about the above question, or rather the error that it was having problems with.  I have been trying so many different iLogic rules, that I was left in a mode in Inventor where I was in Edit mode of a drawing sketch.  So obviously, iLogic rule didn't work properly.  Idiot!

 

Anyway, if anyone knows a quicker or easier way to do this one, please feel free to put the code up.

Message 10 of 17
WCrihfield
in reply to: dlongley

Hi @dlongley.  I wrote a similar code for someone on another post, but it included sheet in the left column, and view names separated by commas on that sheet within the cell on the right column.  I used some of my code from that solution, with some modifications & updates, to help with this request.  See if this iLogic rule code below will do what you are wanting it to do.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim oSheets As Inventor.Sheets = oDDoc.Sheets
	Dim oASheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oFirstSheet As Inventor.Sheet = GetFirstSheet(oDDoc)
	If oASheet IsNot oFirstSheet Then oFirstSheet.Activate
	Dim oCTables As Inventor.CustomTables = oFirstSheet.CustomTables
	Dim oTable As Inventor.CustomTable = Nothing
	If oCTables.Count = 0 Then 'create the CustomTable
		Dim sTitle As String = "SHEET REVISIONS"
		Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
		Dim oPos2D As Point2d = oTG.CreatePoint2d(oFirstSheet.Border.RangeBox.MinPoint.X, oFirstSheet.Border.RangeBox.MaxPoint.Y)
		Dim iColsCount As Integer = 2
		Dim iRowsCount As Integer = oSheets.Count
		Dim oColTitles() As String = {"SHEET", "REVISION" }
		Dim oContents() As String = GetSheetsData(oDDoc)
		oTable = oCTables.Add(sTitle, oPos2D, iColsCount, iRowsCount, oColTitles, oContents)
		oTable.TableDirection = TableDirectionEnum.kTopDownDirection
		oTable.HeadingPlacement = HeadingPlacementEnum.kHeadingAtTop
		oTable.ShowTitle = True
	Else 'try to find the existing CustomTable, then update it
		oTable = oCTables.Item(1) 'assuming it is the first CustomTable on the sheet
		Dim oData() As String = GetSheetsData(oDDoc)
		If oData Is Nothing OrElse oData.Length = 0 Then Exit Sub
		Dim oRows As Inventor.Rows = oTable.Rows
		If oRows.Count < oSheets.Count Then
			Do
				oRows.Add()
			Loop Until oRows.Count = oSheets.Count
		ElseIf oRows.Count > oSheets.Count Then
			Do
				oRows.Item(oRows.Count).Delete
			Loop Until oRows.Count = oSheets.Count
		End If
		Dim iRow As Integer = 1
		For i As Integer = 0 To UBound(oData) Step 2
			Dim oRow As Inventor.Row = oRows.Item(iRow)
			Dim oSheetCell As Inventor.Cell = oRow.Item(1)
			Dim oRevCell As Inventor.Cell = oRow.Item(2)
			oSheetCell.Value = oData(i)
			oRevCell.Value = oData(i + 1)
			iRow = iRow + 1
		Next 'i
	End If
	If oASheet IsNot oFirstSheet Then oASheet.Activate
	oDDoc.Update2(True)
End Sub

Function GetFirstSheet(oDDoc As DrawingDocument) As Inventor.Sheet
	If oDDoc Is Nothing Then Return Nothing
	Dim oSheets As Inventor.Sheets = oDDoc.Sheets
	For Each oSheet As Inventor.Sheet In oSheets
		If oSheet.Name.Split(":").Last = "1" Then Return oSheet
	Next
	Return Nothing
End Function

Function GetSheetsData(oDDoc As DrawingDocument) As String()
	If oDDoc Is Nothing Then Return Nothing
	Dim oDataList As New List(Of String)
	Dim oSheets As Inventor.Sheets = oDDoc.Sheets
	For Each oSheet As Inventor.Sheet In oSheets
		oDataList.Add(oSheet.Name)
		oDataList.Add(oSheet.Revision)
	Next 'oSheet
	Return oDataList.ToArray
End Function

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 11 of 17
Jpfeifer5TC7R
in reply to: WCrihfield

Doubt in getting a response on this, but why when i try to increase the column amount, then try to pass in two more titles do I get an "incorrect parameter" error? This makes no sense, I'm just passing more information into the chart.

Message 12 of 17
WCrihfield
in reply to: Jpfeifer5TC7R

Hi @Jpfeifer5TC7R.  Working with these CustomTable objects by code can be pretty complicated, because many of the things involved are pretty strict.  First of all, I may need a more detailed description of what you did, before I can guess at what may have cause a problem.  Are you creating a new CustomTable, or changing an existing CustomTable (or both, like in the last example above)?  It sounds like you may have only added two more names into the one Array for column title Strings.  If you were creating a new CustomTable, and you wanted to add 2 more columns, then you would have to specify that there will be 2 more columns, then also include those two more column titles within the Array of Strings for column titles.  Then you would have to account for there being that many more cells in the table (added columns count, multiplied by the number of rows).  Because the 'Contents' Array needs to be the correct size to account for one entry for each cell in the table.  And remember that an Arrays first entry is at zero, not one, then its final entry index is one less than the 'Count', because of it starting at zero.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 13 of 17
Jpfeifer5TC7R
in reply to: WCrihfield

I'm outside my wheel house in a company where work is a bit slow. They want me to automate a table to include columns "Items", "qty", "description", and "material". I've been able to mess with small coding projects in the past, but the array stuff keeps running me into issues. To be clear, my knowledge of array's is almost non existent. I've only really played with manipulating values or messing with if statements and so on. 

 

I've removed and changed the need for the first sheet page to be the only one the rule applies to. My code now applies the table to any active sheet I'm currently looking at. From here I decided to change

Dim iColsCount As Integer = 4

Once the value was 4. Then I changed the title section to be 

Dim oColTitles() As String =  {"ITEM", "QTY", "DESCRIPTION", "MATERIAL"}

 When I do this, it tells me incorrect parameter on the creation line for the table itself. 

 

My plan was to manipulate this code to my means at a later time. I'm learning that the documentation behind Ilogic is out of date, even including the suffix "get" or "set". Furthermore, the code examples to create a simple chart doesn't function because of their out of date nature. In fact, I'm not exactly sure how anyone uses the horrible documentation behind this system. Nor how I am to learn anything about this system fighting the documentation constantly. 

 

My plan is to autopopulate the first Item column from a link with a excel table. Then based upon that Item value, I planned to pass in strings for the description to match that said item. Very outside my wheel house, but simply changing a value and adding should not be causing a problem from my limited knowledge. All before I even attempt to add functionality that would be custom. 

 

Edited to add: Just a bit happy I'm being paid to learn this, even with the frustration behind things. 

Message 14 of 17
WCrihfield
in reply to: Jpfeifer5TC7R

Hi @Jpfeifer5TC7R.  My example code above may not be a good one to go by if you only need to create a new CustomTable, and do not need to update or change an already existing one.  After changing the two lines of code you are showing, then you would have to also had to change this following line somehow.

Dim oContents() As String = GetSheetsData(oDDoc)

But in that example, it is calling a whole other code routine to set the value of that variable, so it would be pretty complicated to change just that one line to meet your needs.  That custom Function it is calling to run, was specifically designed to collect data in a way that would work for a table with only two columns of data (Sheet Name & Sheet Revision).  That resulting data would be patterned in a way that would result in the Sheet Name always ending up in the first column, while the Sheet Revision would always end up in the second column.

 

So, I will attempt to explain what is needed in your situation.  That 'contents' array must end up with the same number of entries in it, as there will be cells in the table (one entry per cell).  And, when creating a new table, and supplying that Array to it for the contents of the table, it will fill in the cells in the following way.  It will start by filling in the top left cell, then fill in any cells to the right of that cell in that same row, then to the farthest left cell of the next row down, then across that row, and so on until it reaches the last cell on the right of that bottom row.  Knowing that ahead of time helps, but it can still be difficult to plan putting the data entries into that Array in just the right way they they fill in the cells exactly the way you want them to be.  What you can do though, is just supply an empty String for each cell (in the Array).  Then, once the table has been created, it is easier to fill in the cell values the way you want the later by navigating the rows & columns of the table.

 

If a table already exists, and you just want to add more rows to it, or add more columns to it, then that is also easier to do than re-creating it from scratch.  For this, we can use the CustomTable.Rows.Add() method, or the CustomTable.Columns.Add() method.  In those methods, all 'inputs' they request are optional.  Meaning, you can just create an empty new row or column, then fill in its contents later, if needed.  When adding a new column, it does require that you at least specify a title for it though.

 

About Arrays (and similar):

One thing to keep in mind, that may help down the road...any type of collection type object that is defined by the VB.NET system will be 'zero based' (first item is at Index of zero, not one).  But any collection type of object that is defined by Autodesk Inventor API or iLogic will be 'one based' (first item is at Index of one, not zero).

With that in mind...

An Array is a 'fixed size' type of collection.  So, when we create one, we have to do one of two things...specify how big it should be, or specify all of its contents at one time, which will set its size to the number of things you initially put into it.  In my example above, I did the second way.  I set all its contents at one time, because I was not sure how many entries it would need.  If I know how many entries it will need to contain (4 columns x 4 rows = 16 cells) then I can do it that way, and that would look like:

Dim oContents(15) As String

...even though we need it to hold 16 entries, because the first entry will be at Index zero, then the 16th entry will be at Index 15.  When we specify its size, then we can leisurely set the entry values later, using multiple lines of code, instead of all at once, on one line of code.

oContents(0) = "Upper-Left Cell (A1)"
oContents(1) = "Next Cell To The Right (B1)"
oContents(2) = "Next Cell To The Right (C1)"
oContents(3) = "Last Cell In First Row (D1)"
oContents(4) = "First Cell In Second Row (A2)"
oContents(4) = "Second Cell In Second Row (B2)"
'...and so on
oContents(15) = "Last Cell In Last Row (D4)"

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 15 of 17
Jpfeifer5TC7R
in reply to: WCrihfield

Public Class CreateCustomTable()
	Sub main
		
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    
    ' Set a reference to the active sheet.
    Dim oSheet As Sheet
    oSheet = oDrawDoc.ActiveSheet
    
	Dim Ipos As Point2d
	Ipos = ThisApplication.TransientGeometry.CreatePoint2d(15,15)                     '(33.544, 8.315)
	
    ' Set the column titles
    Dim oTitles(0 To 2) As String
    oTitles(0) = "Part Number"
    oTitles(1) = "Quantity"
	oTitles(2) = "Description"
    'oTitles(3) = "Material"
    
    ' Set the contents of the custom table (contents are set row-wise)
    Dim oContents(0 To 8) As String
    oContents(0) = "1"
    oContents(1) = "1"
    oContents(2) = "Brass"
    oContents(3) = "2"
    oContents(4) = "2"
    oContents(5) = "Aluminium"
    oContents(6) = "3"
    oContents(7) = "1"
    oContents(8) = "Steel"
	'oContents(9) = "Steel"
	'oContents(10) = "Steel"
	'oContents(11) = "Steel"
	
    
    ' Set the column widths (defaults to the column title width if not specified)
    Dim oColumnWidths(0 To 2) As Double
    oColumnWidths(0) = 2.5
    oColumnWidths(1) = 2.5
    oColumnWidths(2) = 4
      
    ' Create the custom table
    Dim oCustomTable As CustomTable
   oCustomTable = oSheet.CustomTables.Add("TANK COMPONONETS", Ipos, 3, 3, oTitles, oContents, oColumnWidths)
                                        

End Sub
End Class

This is what I've been able to get function since our comments to each other. However I still must not be understanding something correctly. For example, you can see I've commented out a few lines that I've been fighting with. If I want to increase the rows, I would change the values after the (dot).add portion to 4,3 so that the table is created with 12 cells of information. Then I change the 0-2 value to 0-3 to incorporate another title section. 

Then When changing the total number of cells my oContent must be equal to that total of 4*3=12? 

 

Every time I change a value or add something the program fails with the error "Parameter incorrect"

 

 

 

Message 16 of 17
WCrihfield
in reply to: Jpfeifer5TC7R

Hi @Jpfeifer5TC7R.  This type of thing will just take some time to learn, and get used to as you go.  What you learn from trial & error experience sticks with you longer anyways.

 

I did quickly throw together a couple examples for you to look at, but they are not completely as you would want them yet.  They are just meant to give you some ideas.  The main theme with both of these is to show how to create the table early, then fill it in later, as needed.

 

This one does not specify any column titles up front, but fills them in later.  And since the Contents are not a 'Required' input when first creating a table (it is Optional), this does not set those up front either, but later, after the table has been created.

Public Class CreateCustomTable
	Sub Main
		' Set a reference to the drawing document.
		' This assumes a drawing document is active.
		Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
		' Set a reference to the active sheet.
		Dim oSheet As Sheet = oDrawDoc.ActiveSheet
		Dim sTableTitle As String = "TANK COMPONONETS"
		Dim Ipos As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(15, 15) '(33.544, 8.315)
		'specify how many Columns you want this table to have
		Dim iColumnsCount As Integer = 3
		'specify how many Rows you want this table to have
		Dim iRowsCount As Integer = 3
		Dim oTitles(iColumnsCount - 1) As String
		For iTitle As Integer = LBound(oTitles) To UBound(oTitles)
			oTitles(iTitle) = ""
		Next iTitle
		
		' Create the custom table
		Dim oCustomTable As CustomTable
		oCustomTable = oSheet.CustomTables.Add(sTableTitle, Ipos, iColumnsCount, iRowsCount, oTitles)
		
		Dim oColumns As Inventor.Columns = oCustomTable.Columns
		For iCol As Integer = 1 To iColumnsCount
			Dim oColumn As Inventor.Column = oColumns.Item(iCol)
			oColumn.Title = "Column " & iCol.ToString & " Title"
		Next iCol
		
		Dim oRows As Inventor.Rows = oCustomTable.Rows
		For iRow As Integer = 1 To oRows.Count
			Dim oRow As Inventor.Row = oRows.Item(iRow)
			'For Each oCell As Inventor.Cell In oRow
			For iCell As Integer = 1 To oRow.Count
				Dim oCell As Inventor.Cell = oRow.Item(iCell)
				oCell.Value = "Cell " & iCell.ToString & " , " & iRow.ToString
				'oCell.Value = "Cell " & iRow.ToString
			Next iCell
		Next iRow
	End Sub
End Class

This example is very similar to the last one.  But this one shows how to use a List(Of String) type variable (it does not have a set size), then add stuff to it, then convert that into the Array we need, without having to specify the size of the Array.  Then it shows an example of creating the proper size Array for the Contents, then filling in its entries with empty strings, similar to what we did with the titles in the last example. Then, since this one supplied column titles up front, it does not change them after the table has been created.  The rest is pretty similar to the first.

Public Class CreateCustomTable
	Sub Main
		' Set a reference to the drawing document.
		' This assumes a drawing document is active.
		Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
		' Set a reference to the active sheet.
		Dim oSheet As Sheet = oDrawDoc.ActiveSheet
		Dim sTableTitle As String = "TANK COMPONONETS"
		Dim Ipos As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(15, 15) '(33.544, 8.315)
		'specify how many Columns you want this table to have
		Dim iColumnsCount As Integer = 3
		'specify how many Rows you want this table to have
		Dim iRowsCount As Integer = 3
		
		'a List does not have a set size - its size grows or shrinks as you add or remove items
		Dim oTitlesList As New List(Of String)
		oTitlesList.Add("Part Number")
		oTitlesList.Add("Quantity")
		oTitlesList.Add("Description")
		
		'now, convert that 'List' into the Array that we need - no need to specify size
		Dim oTitles() As String = oTitlesList.ToArray

'[ <<< This section of code for filling in Contents is not necessary to do before creating the table >>>
' <<< We could fill in the contents later, after that table has been created. >>>

		'determine number of cells in the table, based on columns & rows
		Dim iContentsCount As Integer = (iColumnsCount * iRowsCount)
		
		'use that iContentsCount to set the correct size of the Contents Array
		Dim oContents(iContentsCount - 1) As String
		
		'Now, simply iterate through each entry in this Array, and fill in an empty String
		For iContent As Integer = LBound(oContents) To UBound(oContents)
			oContents(iContent) = ""
		Next iContent
		
'] <<< End of this section of code which sets the empty contents >>>

		' Create the custom table with empty column titles, and empty data cells
		Dim oCustomTable As CustomTable
		oCustomTable = oSheet.CustomTables.Add(sTableTitle, Ipos, iColumnsCount, iRowsCount, oTitles, oContents)
		
		'now we can go back and edit the column titles as needed
		'we could also adjust the column widths as needed now too
		Dim oColumns As Inventor.Columns = oCustomTable.Columns
		For iCol As Integer = 1 To iColumnsCount
			Dim oColumn As Inventor.Column = oColumns.Item(iCol)
			'oColumn.Width = 2.5
		Next iCol
		
		'now fill in the cells as we iterate through the rows
		Dim oRows As Inventor.Rows = oCustomTable.Rows
		For iRow As Integer = 1 To oRows.Count
			Dim oRow As Inventor.Row = oRows.Item(iRow)
			For iCell As Integer = 1 To oRow.Count
				Dim oCell As Inventor.Cell = oRow.Item(iCell)
				oCell.Value = "Cell " & iCell.ToString & " , " & iRow.ToString
			Next iCell
		Next iRow
	End Sub
End Class

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 17 of 17
Jpfeifer5TC7R
in reply to: WCrihfield

You're a legend mate, been playing around with my own table so far. Been able to get what was holding me back so far. However I see what you mean when it comes to complexity. It's one thing to hard code all of the table's data. However when you want to be able to call upward and update things based on unknows you abstract through several other arrays to handle the data. You've give me much to review, and I appreciate your help in this area. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report