Custom variable table

Custom variable table

S7RM7RPR
Advocate Advocate
1,636 Views
6 Replies
Message 1 of 7

Custom variable table

S7RM7RPR
Advocate
Advocate

I'm having a heck of a time trying to figure out how to make a stupid automatic table. I've been trying to use the Inventor API help but it seems all the code examples are outdated and I can't get it to work.

 

So instead of showing off the code I can't get to work, I'll show what I need and hopefully someone can help me to get there. (should be attatched)

 

What I seem to be having trouble with is putting in the cell values. I can generate a table, but I can't get my values in for some reason.

 

I need to be able to support up to 24 different spider items.

 

Thanks in advance. I have no programming training so I'm learning on the fly with this otherwise I'm sure I would have been able to figure out what's going wrong.

0 Likes
Accepted solutions (1)
1,637 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Hi ajknextlang

 

What is your code?

 

0 Likes
Message 3 of 7

S7RM7RPR
Advocate
Advocate

This is the code I can get to work.

 

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

'  the column titles
Dim oTitles() As String = {"SPIDER","IMB","PROCEDURE","'A' DIMENSION"}


Dim oPoint As Point2d
oPoint = ThisApplication.TransientGeometry.CreatePoint2d(1, 6)

' Create the custom table
Dim oCustomTable As CustomTable
oCustomTable = oSheet.CustomTables.Add("IMB WELDING", oPoint, 4, 24, oTitles)
0 Likes
Message 4 of 7

ekinsb
Alumni
Alumni

Here's a modified version of the sample from the API Help.  I think the problem you ran into running it is the difference in arrays between VBA and VB.Net.  I've modified this version so that it will be compatible with both and I've changed it so it outputs the table in your example, with the exception that the custom table doesn't support merging a column so they are still individual cells.

 

Public Sub CreateCustomTable()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    
    ' Set a reference to the active sheet.
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
    
    Dim columnCount As Integer
    Dim rowCount As Integer
    columnCount = 4
    rowCount = 6
    
    ' Set the column titles
    Dim titles() As String
    ReDim titles(columnCount - 1)
    titles(0) = "SPIDER"
    titles(1) = "IMB"
    titles(2) = "PROCEDURE"
    titles(3) = "'A' DIMENSION"
    
    ' Set the contents of the custom table (contents are set row-wise)
    
    Dim contents() As String
    ReDim contents(columnCount * rowCount - 1)
    Dim row As Integer
    row = 0
    contents(4 * row) = "F25"
    contents(4 * row + 1) = "S-10090-2"
    contents(4 * row + 2) = "S15020-A"
    contents(4 * row + 3) = "33.25 [844.5]"
    
    row = row + 1
    contents(4 * row) = "F26"
    contents(4 * row + 1) = "S-10090-2"
    contents(4 * row + 2) = "S15020-A"
    contents(4 * row + 3) = "33.25 [844.5]"
    
    row = row + 1
    contents(4 * row) = "F27"
    contents(4 * row + 1) = "S-10090-2"
    contents(4 * row + 2) = "S15020-A"
    contents(4 * row + 3) = "33.25 [844.5]"
    
    row = row + 1
    contents(4 * row) = "F28"
    contents(4 * row + 1) = "S-10090-2"
    contents(4 * row + 2) = "S15020-A"
    contents(4 * row + 3) = "33.25 [844.5]"
    
    row = row + 1
    contents(4 * row) = "F29"
    contents(4 * row + 1) = "S-10090-2"
    contents(4 * row + 2) = "S15020-A"
    contents(4 * row + 3) = "33.25 [844.5]"
    
    row = row + 1
    contents(4 * row) = "F30"
    contents(4 * row + 1) = "S-10090-2"
    contents(4 * row + 2) = "S15020-A"
    contents(4 * row + 3) = "33.25 [844.5]"
    
    ' Set the column widths (defaults to the column title width if not specified)
    Dim columnWidths() As Double
    ReDim columnWidths(columnCount - 1)
    columnWidths(0) = 2.5
    columnWidths(1) = 3
    columnWidths(2) = 3
    columnWidths(3) = 3.5
      
    ' Create the custom table
    Dim oCustomTable As CustomTable
    Set oCustomTable = oSheet.CustomTables.Add( _
                    "IMB WELDING", ThisApplication.TransientGeometry.CreatePoint2d(15, 15), _
                    columnCount, rowCount, titles, contents, columnWidths)
End Sub

 

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 5 of 7

S7RM7RPR
Advocate
Advocate
Fantastic thank you so much.

The only modification I'm going to make is to loop it so I can vary my items but I think I can handle that part. I'll post the final code
0 Likes
Message 6 of 7

S7RM7RPR
Advocate
Advocate
Accepted solution

SyntaxEditor Code Snippet

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet


Dim IMB As String = Left(Parameter("IMB.ipt.IMB"),7)
SPIDER_QTY = Parameter("BOT SPIDERS.iam.SPIDER_QTY")
BCD = Parameter("BOT SPIDERS.iam.BCD")
NOTCH = Parameter("IMB.ipt.NOTCH") ' 1 OR 0

' logic start

Dim columnCount As Integer
Dim rowCount As Integer
columnCount = 4
rowCount = 0

For J = 25 To (SPIDER_QTY+24)
    If Parameter("SPIDER" & J & ".ipt.MTG") = True Then
        rowCount = rowCount + 1
    End If
Next

' Set the column titles
Dim titles() As String
ReDim titles(columnCount - 1)
titles(0) = "SPIDER"
titles(1) = "IMB"
titles(2) = "PROCEDURE"
titles(3) = "'A' DIMENSION"

Dim contents() As String
ReDim contents(columnCount *rowCount-1)
Dim row As Integer
Dim PROCEDURE As String

row = 0
For J = 25 To (SPIDER_QTY+24)
    If Parameter("SPIDER" & J & ".ipt.MTG") = True Then
    
        If IMB = "S-10090" Then
            PROCEDURE = "S-15020-"
        ElseIf IMB = "S-10040" Then
            PROCEDURE = "S-15021-"
        ElseIf IMB = "S-10130" Or IMB = "S-10131" Then
            PROCEDURE = "S-15022-"
        Else
            MsgBox("IMB ERROR")
        End If
    
        If Parameter("WELD_BEFORE") = True Then
            PROCEDURE = PROCEDURE & "WB"
        ElseIf Parameter("WELD_AFTER") = True Then
            PROCEDURE = PROCEDURE & "WA"
        End If
        
        If NOTCH = 1 Then
            PROCEDURE = PROCEDURE & "N"
        End If
        
        AdimIN = BCD / 2
        AdimMM = AdimIN * 25.4
        
        contents(4 * row) = "F" & J
        contents(4 * row + 1) = Parameter("IMB.ipt.IMB")
        contents(4 * row + 2) = PROCEDURE
        contents(4 * row + 3) = AdimIN & " [" & AdimMM & "]"
        row = row + 1
    End If
Next

Dim columnWidths() As Double
ReDim columnWidths(columnCount - 1)
columnWidths(0) = 1.5
columnWidths(1) = 2
columnWidths(2) = 2
columnWidths(3) = 3

Dim oCustomTable As CustomTable
oCustomTable = oSheet.CustomTables.Add("IMB WELDING", ThisApplication.TransientGeometry.CreatePoint2d(15, 15),columnCount, rowCount, titles, contents, columnWidths)
0 Likes
Message 7 of 7

aronmatheus
Advocate
Advocate

aronmatheus_0-1615202497502.png

There anyway create a macro to merge the cell "TOTAL MASS" erase the firsts lines in merge the setence "TOTAL MASS"?

There create a macro to calculate the total mass:

 

Sub testTotalMass()

Dim dwg As DrawingDocument
Set dwg = ThisApplication.ActiveDocument

Dim oview As DrawingView
Set oview = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Pick the assembly view")

On Error Resume Next
Dim asm As AssemblyDocument
Set asm = oview.ReferencedDocumentDescriptor.ReferencedDocument
If Err Then
MsgBox ("Not an assembly")
Exit Sub
End If

Dim pl As PartsList
Set pl = dwg.ActiveSheet.PartsLists.Item(1)

Dim plr As PartsListRow
Dim found As Boolean
For Each plr In pl.PartsListRows
If plr.Item(3).Value = "TOTAL MASS" Then
found = True
Exit For
End If
Next

Dim txn As Transaction
Set txn = ThisApplication.TransactionManager.StartTransaction(dwg, "Add total mass")

If found = False Then Set plr = pl.PartsListRows.Add(pl.PartsListRows.Count, False)

plr.Item(3).Value = "TOTAL MASS"
plr.Item(5).Value = Round(asm.ComponentDefinition.MassProperties.Mass, 3) & " kg"

txn.End

End Sub

0 Likes