Control custom table content in drawings with iLogic

Control custom table content in drawings with iLogic

Daan_M
Collaborator Collaborator
2,814 Views
6 Replies
Message 1 of 7

Control custom table content in drawings with iLogic

Daan_M
Collaborator
Collaborator

Hi,

 

I'm wondering if its possible to control the contents of custom tables in a drawing.

I created the custom table below, i would like to control the variables in the Table (vTx) with iLogic.

I haven't found any property to do this in the API Object model 

 

table question.PNG

 

Accepted solutions (1)
2,815 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

I created an iLogic rule that will work with an 'active' drawing document, and creates a fairly simple Custom Table 'from scratch'.  Within this rule, right after I create the oContents variable, that's where I've filled in the contents of the table.  This includes all the cells of all the rows, below the title row and the column header row.  Right now I've just used a simple 'For' loop to fill them all in with generic data to help you understand how all the cells are being filled in from the single dimension array of Strings.  You can replace that simple loop with a much more detailed section of code which sets the value of each cell individually.  I have included some examples of both setting all array values at once, and setting each individually.  When setting them all at once, you don't specify the array's size, just set its values.  But when setting its values individually, you need to specify the size of the array when you create it (otherwise you will have to keep resizing it to avoid errors).

Here's the code:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("A Drawing Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet

Dim oTitle As String = "CUSTOM TABLE TITLE"
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oPPoint As Point2d = oTG.CreatePoint2d(0, 0)
Dim oCols As Integer = 5
Dim oRows As Integer = 6
'Number of column titles supplied must match number of columns specified
'Dim oColTitles() As String = {" ", "Dimension L1", "Dimension L2", "Material", "Cost" }
'or
Dim oColTitles(oCols - 1) As String
oColTitles(0) = " " '1st column title
oColTitles(1) = "Column 2 Title" '2nd column title
oColTitles(2) = "Column 3 Title" '3rd column title
oColTitles(3) = "Material" '4th column title
oColTitles(4) = "Cost" '5th column title

'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
For oCell As Integer = 0 To oCells
	oContents(oCell) = "Cell " & oCell
Next

'Dim oColWidths() As Double = {1.25, 2.5, 2.5, 1.5, 1.25 }
'or
'could run a function here to determine how wide each column needs to be, then set them individually
Dim oColWidths(oCols - 1) As Double
oColWidths(0) = 1.25 '1st column width
oColWidths(1) = 2.5
oColWidths(2) = 2.5
oColWidths(3) = 1.5
oColWidths(4) = 1.25 '5th column width

'Dim oRowHeights() As Double = {.25, .25, .25, .25, .25, .25 }
'or
'could run a function here to determine how tall each row needs to be, then set them individually
Dim oRowHeights(oRows - 1) As Double
For oRow As Integer = 0 To (oRows-1)
	oRowHeights(oRow) = .25
Next

Dim oCTable As CustomTable = oSheet.CustomTables.Add(oTitle, oPPoint, 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) 👍.

If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7

Daan_M
Collaborator
Collaborator

Thanks, code seems suitable to achieve my goal.

 

Just for discussion's sake;

I find it odd that it's possible to put content into a table when creating it, but not adjust it in an existing one.

I know changing single TextLabels is possible in drawing documents. I'd almost go as far as placing a empty table on my Sheet, Then placing TextLabels over the emptycells of the table, and changing the content of those to get the same result....

 

 

 

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

There is a way to change the values within the cells of an already existing Custom Table too, I just didn't have an example previously prepared, that shows how to do it.

So basically you have go to each 'Row' of the table, then to the row's Items (oRow.Item(1)) which are (Cells), then you can get/set the cell's value.  The cell's 'Value' is a read/write property.  Similarly to working with a PartsList or BOM.

How you get to the specific cells you want may depend on if you want to check Column Title's or just use Index numbers (like when the table is always laid out the same.)  In your case, since you aren't using any column titles, you would likely have to either simply use index numbers to navigate to the cell you want, or use a more specific and detailed block of code to check the value of multiple cells in each row, until you find one that matches what you're expecting, then you know you have the right row.  Similarly to the GoExcel.FindRow() method.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor
Accepted solution

@Daan_M 

Here is a generic example of changing the Value of each cell in a Custom Table.  I didn't go into custom detail, because i don't really know what all you are attempting to do.  This should give you the idea/direction for what you need to do to customize your solution the way you need it though.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("A Drawing Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oCTable As CustomTable = oSheet.CustomTables.Item(1)
Dim oCols As Inventor.Columns = oCTable.Columns
Dim oRows As Inventor.Rows = oCTable.Rows
Dim oRow As Inventor.Row
Dim oCell As Inventor.Cell
For Y As Integer = 1 To oRows.Count
	oRow = oRows.Item(Y)
	For X As Integer = 1 To oCols.Count
		oCell = oRow.Item(X)
		oCell.Value = "25"
	Next
Next

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 7

Daan_M
Collaborator
Collaborator

Thanks, i'm pretty sure i'll manage with this.

0 Likes
Message 7 of 7

Daan_M
Collaborator
Collaborator

Got it working via the Example you gave, thanks again.

0 Likes