Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 518

Get Specific Table Row of Content Center Family

$
0
0

By Xiaodong Liang

In general, we call ContentFamily.CreateMember to create the instance of a content family row by inputting index of this row. However, sometimes, we would need to pick one row which has specific cell value such as diameter, radius, length etc. I do not find a direct way to get specific table row. while we could still iterate the table rows and find out the specific item by the cell value(s).

In the other blog, my colleague Adam shared a code demo on how to get specific family. I produced another code based on that. The code tries to get the table row with one column: 'radius is 0.25". 

Note: the method ContentTableRow.GetCellValue accepts the column index, or its internal name. e.g. in this case, the internal name of column 'radius' is 'RR'. In addition,  in this demo code, I input one column only, however obviously, in family 'Bolt GB/T 35', there are many rows whose radius is also '0.25'.  So you would need to input other columns and cell values, in order to get the unique row.

One more thing: if you have known the member id of a row, you could also get ContentTableRow by a direct method:ContentCenter.GetContentObject. In the blog, my colleague Wayne introduced it. 

 


Public Function GetFamily( _
name As String, node As ContentTreeViewNode) _
As ContentFamily
  Dim cc As ContentCenter
  Set cc = ThisApplication.ContentCenter
  If node Is Nothing Then Set node = cc.TreeViewTopNode
  Dim cf As ContentFamily
  For Each cf In node.Families
    If cf.DisplayName = name Then
      Set GetFamily = cf
      Exit Function
    End If
  Next
  Dim child As ContentTreeViewNode
  For Each child In node.ChildNodes
    Set cf = GetFamily(name, child)
    If Not cf Is Nothing Then
      Set GetFamily = cf
      Exit Function
    End If
  Next
End Function'input: specific content family'       internal name of specific ContentTableColumn (ContentTableColumn.internalName)'       the cell value of this column'Note: you would need to input other columns and cell values, in order to get the unique row.
Public Function GetSpecificRow(cf As ContentFamily, colInternalName As String, cellValue As Variant)

    Dim oRow As ContentTableRow
    Dim oCol As ContentTableColumn
    
    Dim oFound As Boolean
    oFound = False
    For Each oRow In cf.TableRows

        'check the cell value of the specific column
        Dim oCellV As String
        oCellV = oRow.GetCellValue(colInternalName)
        If oCellV = cellValue Then
            oFound = True
            Exit For
        End If
    Next

    If oFound Then
      Set GetSpecificRow = oRow
    Else
      Set GetSpecificRow = Nothing
    End If
    
    
End Function

Public Sub CcTest()
   Dim asm As AssemblyDocument
   Set asm = ThisApplication.ActiveDocument
    
   'get specific family
   Dim cf As ContentFamily
   Set cf = GetFamily("Bolt GB/T 35", Nothing)'get specific table row
   Dim oOneTableRow As ContentTableRow
   Set oOneTableRow = GetSpecificRow(cf, "RR", "0.25")'create this member
   Dim member As String
   Dim ee As MemberManagerErrorsEnum
   member = cf.CreateMember(oOneTableRow, ee, "Problem")
   Dim tg As TransientGeometry
   Set tg = ThisApplication.TransientGeometry'inser the member to the assembly
   Call asm.ComponentDefinition.Occurrences.Add( _
    member, tg.CreateMatrix())
End Sub

Viewing all articles
Browse latest Browse all 518

Trending Articles