Creating a table in a drawing using ilogic

Creating a table in a drawing using ilogic

Rogov_Sergey
Collaborator Collaborator
1,683 Views
2 Replies
Message 1 of 3

Creating a table in a drawing using ilogic

Rogov_Sergey
Collaborator
Collaborator

Good day,

I'm completely confused when creating a table in a drawing using ilogic.

Here's what I wanted to do:

1. When you run the rules to select the view in the drawing.;
2. If axonometry is selected, then continue if not, then error;
3. Deletes the table if it was created earlier for the selected view to this view;
4. Create a table with the number of rows taken from the parameters of the selected type;

 

' add custom table.
oDrawDoc = ThisDoc.Document

' Set a reference to the active sheet. 
Dim oSheet As Inventor.Sheet 
oSheet = oDrawDoc.ActiveSheet 

For Each oCustomTable In oSheet.CustomTables
    If InStr(oCustomTable.Title) > 0 Then
        oCustomTable.Delete
    End If
Next

' Set the column titles 
Dim oTitles(2) As String 
oTitles(0) = "№ сгиба" 
oTitles(1) = "Расстояние до начала гиба от базы A1 ,мм" 
oTitles(2) = "Угол в плоскости гиба" 


' Set the contents of the custom table (contents are set row-wise) 
х = Parameter("Труба ilogic (Новая).ipt.Кол_гибов")

Dim oContents(х*3) As String 
Dim i1 As Integer  = 0

For i As Integer = 1 To x
	
oContents(i1) = "Parameter"&i
i1+=1

Next

' Set the column widths (defaults to the column title width if not specified) 
Dim oColumnWidths(2) As Double 
oColumnWidths(0) = 4
oColumnWidths(1) = 4 
oColumnWidths(2) = 4


' Create the custom table 
Dim oCustomTable As Inventor.CustomTable 
oCustomTable = oSheet.CustomTables.Add("Таблица гибов", ThisApplication.TransientGeometry.CreatePoint2d(0, 0), 4, 4, oTitles, oContents, oColumnWidths) 


Находите сообщения полезными? Поставьте Нравится (Like) этим сообщениям!
На ваш вопрос успешно ответили? Нажмите кнопку 'Утвердить решение'


Рогов Сергей/ Rogov Sergey
Инженер-конструктор

0 Likes
1,684 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

I think I may see the problem with your code.  It looks like you are trying to create a custom table that is 4 columns wide and 4 rows tall.  But you are only specifying 3 titles, and 3 column widths.  And, I'm not quite sure, but it doesn't look like your oContents array is the right size either.

When specifying the titles, you need to supply one title for each column you are creating, or it will throw an error.

Same with column widths, one for each column (no more, no less).

And when specifying the contents of the table, there needs to be a value supplied for each cell within the table, even if the value is a null (empty) string.  So for a 4 x 4 table, you would have to supply 16 values.

Each value of the supplied contents array will fill the next cell in the row.  Once the row is full, it will start populating the next row of the table, and so on.   Left to right across the top row, then left to right across the next row down, until it reaches the last cell in the table.

Here is a link to the online help page for that function.  That page also contains a link to another page that has an example VBA code, which builds a 3 x 3 table.

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

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

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

WCrihfield
Mentor
Mentor

Also, near the top of your code, where your searching for a Custom Table, then deleting it.  The If line doesn't appear to be written correctly.  The InStr() function needs two input variables, and it looks like you only supplied it one variable.  That function searches for one sub string within another string, and returns the position (represented by an Integer) of that found sub string within the original.  Some use this to see if one string is contained within another.  There is perhaps a less confusing way to do this, that is a little easier to read.  You can use the Contains() function instead.

Like this:

 

For Each oCustomTable As Inventor.CustomTable In oSheet.CustomTables
    If oCustomTable.Title.Contains("sample") Then ' <<< CHANGE THIS SEARCH TERM
        oCustomTable.Delete
    End If
Next

 

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

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

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)