Add one custom row to an existing content centre family

<?xml encoding=”UTF-8″>By Xiaodong Liang 

Issue 
If I place the part from content centre, Inventor lists the available rows of a family, and I select one of them to insert to the assembly. But not all options I need are there. For example one family has a diameter and a length . Inventor would provide:

Diameter     Length
10              1000
20              1000
30              1000

But I need a part with diameter =  10 and length = 2000.

How to add the required row?

Solution

ContentFamily.TableRows.Add provides you with the ability to add a new row. This applies to custom library only.

The VB definition is:

<strong>Sub</strong> <strong>Add</strong>(<strong>ByRef</strong> <strong>RowData</strong> <strong>As</strong> SAFEARRAY(BSTR), <br>        <strong>ByRef</strong> <strong>Position</strong> <strong>As</strong> [defaultvalue(-1)] <strong>long</strong>, <br>        <strong>Result</strong> <strong>As</strong> [out, retval] <a href="Inventor__ContentTableRow.html">ContentTableRow</a>*)

RowData:  Input String array that contains the new values for the row. The array should be the same size as the number of columns and the values are defined in the same order as the column order.  Position:  Optional input Long that defines the position within the table where the new row should be created. If this argument is not supplied or is out of range the row will be created at the end of the table. 

And please note: any changes to the table are not actually applied until the ContentFamily.Save method is called.

Following is a small VB.NET code demo.

 

Sub addCCFamilyRow()

 

    ‘ assume Inventor application is available

     Dim m_inventorApp As Inventor.Application = Nothing        

     m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject(“Inventor.Application”)

 

 

    ‘ get Content Center

    Dim oContentCenter As ContentCenter

    oContentCenter = m_inventorApp.ContentCenter

 

    ‘ Get the content node (category) “Fasteners:Bolts:Hex Head”

    Dim oContentNode As ContentTreeViewNode

    oContentNode =

        oContentCenter.TreeViewTopNode.ChildNodes.Item(“Fasteners”).

        ChildNodes.Item(“Bolts”).

        ChildNodes.Item​(“Hex Head”)

 

    ‘ Get the “ISO 4015” Family object.

    Dim oFamily As ContentFamily

    For Each oFamily In oContentNode.Families

        If oFamily.DisplayName = “ISO 4015” Then

            Exit For

        End If

    Next

 

    ‘ get the first row

    Dim oOneRow As ContentTableRow

    oOneRow = oFamily.TableRows(1)

 

    ‘just a demo. we reuse the values of first row

    ‘ and change the value of one

 

    ‘ a dynamic array

    Dim oNewRow()  As String

    ‘ each cell

    Dim oCell As ContentTableCell

    Dim i As Integer

    i = 0

    For Each oCell In oOneRow

        ‘ get the value of each cell

        ReDim Preserve oNewRow(i)

        oNewRow(i) = oCell.Value

 

 

        ‘ In this case

        ‘Fa​steners >>Bolts>>Hex Head

        ‘we will modify [Bolt Length]

        ‘ which is number 10 column

 

        ‘ Note: the array bases from 0

 

        If i = 10 Then

         ‘ set the new value

         ‘ e.g. set a special value

         oNewRow(i) = “10.11111”

        End If

 

        i = i + 1

    Next

 

    ‘add a new row

    oFamily.TableRows.Add( oNewRow)

    ‘save family to save the change

    oFamily.Save

End Sub


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading