Place every item from a family that is not suppressed (content center)

Place every item from a family that is not suppressed (content center)

FrankHermens4Y53K
Contributor Contributor
295 Views
1 Reply
Message 1 of 2

Place every item from a family that is not suppressed (content center)

FrankHermens4Y53K
Contributor
Contributor

Hello,

 

I found a code online in VBA that places every item from a content center family in a assembly (this works). I want make it so that it wil only place the items that are not suppressed. I found this in a post but i cant figure out how to add it in the code that i already have. some help would be appreciated

 

the code that i found + link:

            If Not oFamily.TableRows.Item(i).IsSuppressed Then
                strContentPartFileName = oFamily.CreateMember(i, ErrorType, strErrorMessage)
End If

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/create-every-possible-instance-of-a-...

 

The code i found online that works:

Public Sub PlaceFromContentCenter()
    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.Documents.Add(kAssemblyDocumentObject)
    
    Dim asmDef As AssemblyComponentDefinition
    Set asmDef = asmDoc.ComponentDefinition
    
    ' Get the node in the content browser based on the names of the nodes in the hierarchy.
    Dim hexHeadNode As ContentTreeViewNode
    Set hexHeadNode = ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners").ChildNodes.Item("Washers").ChildNodes.Item("Plain")
    
    ' Find a specific family.  In this case it's using the display name, but any family
    ' characteristic could be searched for.
    Dim family As ContentFamily
    Dim checkFamily As ContentFamily
    For Each checkFamily In hexHeadNode.Families
        If checkFamily.DisplayName = "Sluitring th.vz." Then
            Set family = checkFamily
            Exit For
        End If
    Next
    
    Dim i As Integer
    If Not family Is Nothing Then
        ' Place one instance of each member.
        Dim offset As Double
        offset = 0
        Dim row As ContentTableRow
        For Each row In family.TableRows
            ' Create the member (part file) from the table.
            Dim failureReason As MemberManagerErrorsEnum
            Dim failureMessage As String
            Dim memberFilename As String
            memberFilename = family.CreateMember(row, failureReason, failureMessage, kRefreshOutOfDateParts)
            
            ' Place the part into the assembly.
            Dim transMatrix As Matrix
            Set transMatrix = ThisApplication.TransientGeometry.CreateMatrix
            transMatrix.Cell(2, 4) = offset
            Dim Occ As ComponentOccurrence
            Set Occ = asmDef.Occurrences.Add(memberFilename, transMatrix)
            
            ' Compute the position for the next placement based on the size of the part just placed.
            Dim minY As Double
            Dim maxY As Double
            minY = Occ.RangeBox.MinPoint.Y
            maxY = Occ.RangeBox.MaxPoint.Y
            offset = offset + ((maxY - minY) * 1.1)
        Next
    End If
End Sub

 

With kind regards,

Frank.

 

0 Likes
Accepted solutions (1)
296 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor
Accepted solution

Here is the modified code. The trick here is to put a check statement  in the row object just before the member is created. 

Public Sub PlaceFromContentCenter()
    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.Documents.Add(kAssemblyDocumentObject)
    
    Dim asmDef As AssemblyComponentDefinition
    Set asmDef = asmDoc.ComponentDefinition
    
    ' Get the node in the content browser based on the names of the nodes in the hierarchy.
    Dim hexHeadNode As ContentTreeViewNode
    Set hexHeadNode = ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners").ChildNodes.Item("Washers").ChildNodes.Item("Plain")
    
    ' Find a specific family.  In this case it's using the display name, but any family
    ' characteristic could be searched for.
    Dim family As ContentFamily
    Dim checkFamily As ContentFamily
    For Each checkFamily In hexHeadNode.Families
        If checkFamily.DisplayName = "Sluitring th.vz." Then
            Set family = checkFamily
            Exit For
        End If
    Next
    
    Dim i As Integer
    If Not family Is Nothing Then
        ' Place one instance of each member.
        Dim offset As Double
        offset = 0
        Dim row As ContentTableRow
        For Each row In family.TableRows
            ' Create the member (part file) from the table.
            Dim failureReason As MemberManagerErrorsEnum
            Dim failureMessage As String
            Dim memberFilename As String
       If Not row.IsSuppressed = True  Then  
memberFilename = family.CreateMember(row, failureReason, failureMessage, kRefreshOutOfDateParts) ' Place the part into the assembly. Dim transMatrix As Matrix Set transMatrix = ThisApplication.TransientGeometry.CreateMatrix transMatrix.Cell(2, 4) = offset Dim Occ As ComponentOccurrence Set Occ = asmDef.Occurrences.Add(memberFilename, transMatrix) ' Compute the position for the next placement based on the size of the part just placed. Dim minY As Double Dim maxY As Double minY = Occ.RangeBox.MinPoint.Y maxY = Occ.RangeBox.MaxPoint.Y offset = offset + ((maxY - minY) * 1.1) End If
Next End If End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes