Generate all components in Content Center Family

Generate all components in Content Center Family

dsl145
Advocate Advocate
937 Views
4 Replies
Message 1 of 5

Generate all components in Content Center Family

dsl145
Advocate
Advocate

I know that I've seen this done before... but does anyone know how to generate all the parts of a content center family to be created (say in an assembly). The reason is so that I can generate them all, attach them all to respective items, sync the generated item numbers and then lock them all down so that others don't screw them up.

0 Likes
Accepted solutions (2)
938 Views
4 Replies
Replies (4)
Message 2 of 5

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @dsl145 

 

Here's a quick example I had on hand.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 


Dim asmDoc As AssemblyDocument
asmDoc = ThisApplication.Documents.Add(kAssemblyDocumentObject)

Dim asmDef As AssemblyComponentDefinition
asmDef = asmDoc.ComponentDefinition

' Get the node in the content browser based on the names of the nodes in the hierarchy.
Dim hexHeadNode As ContentTreeViewNode
hexHeadNode = ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners").ChildNodes.Item("Bolts").ChildNodes.Item("Hex Head")

' 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 = "DIN EN 24016" Then
		family = checkFamily
		Exit For
	End If
Next

Dim i As Integer
If Not family Is Nothing Then
	' Place one instance of each member.
	Dim off As Double
	off = 0
	Dim row As ContentTableRow
	
	'use these 2 lines to run 10 rows
	For iRow = 1 To 10
		row = family.TableRows.Item(iRow)
		
	''or comment out those 2 lines and 
	'use the line below To run the entire table
	'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
		transMatrix = ThisApplication.TransientGeometry.CreateMatrix
		transMatrix.Cell(2, 4) = offset
		Dim Occ As ComponentOccurrence
		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
		off = off + ((maxY - minY) * 1.1)
	Next
End If

 

EESignature

0 Likes
Message 3 of 5

dsl145
Advocate
Advocate
Accepted solution

@Curtis_Waguespack , I'm sure your code would work, but it actually reminded me of how it was done in the past and I was able to dig up the file that contained it. This version is more generic and instead just dumps out the remaining parts of the content center part first inserted into the assembly.

 

        'active assembly s
        Dim oMainAsm As AssemblyDocument = ThisDoc.Document
        Dim oAsmDef As AssemblyComponentDefinition = oMainAsm.ComponentDefinition

        ' get the occurrence by its position in the occurrences collection
        Dim oOcc As ComponentOccurrence = oAsmDef.Occurrences.Item(1)
        Dim oDef As PartComponentDefinition = oOcc.Definition
        Dim oDoc As PartDocument = oDef.Document

        'reference to the CC properties - oProps
        Dim oPropSets As PropertySets = oDoc.PropertySets
        Dim oProps As PropertySet = oPropSets.Item("Content Library Component Properties")

        ' family id
        Dim oProp As Inventor.Property = oProps.Item("FamilyId")
        Dim FamilyId As String = oProp.Value
        'MsgBox("FamilyId: " + FamilyId)

        'reference to the ContentFamily
        Dim oContentCenter As ContentCenter = ThisApplication.ContentCenter
        Dim oFamily As ContentFamily = oContentCenter.GetContentObject("v3#" + FamilyId + "#")
        'MsgBox("Content Family DisplayName:  " + oFamily.DisplayName & vbNewLine & _'        "Rows in Family:  " & oFamily.TableRows.Count )'
        ''create new member file
        Dim ErrorType As MemberManagerErrorsEnum
        Dim strContentPartFileName As String
        Dim strErrorMessage As String

        ' Do a loop here for all the rows.
        For i As Integer = 1 To oFamily.TableRows.Count
            strContentPartFileName = oFamily.CreateMember(i, ErrorType, strErrorMessage)
        Next

        ' Msgbox to alert the process is done.
        MsgBox("All " & oFamily.TableRows.Count & " c/c family items are created.")

 

0 Likes
Message 4 of 5

jamesmTKN9N
Participant
Participant

i ran this script and it works how i expected it to, only thing that would be ideal is if it would only do this for unsuppressed parts in that family rather than all of those items. we have some unused items suppressed that way we dont use them in our assemblies. this would also cut down on the time it takes to run. If this is a possibility, it would same an immense amount of time in deleting unused parts from the assembly

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

I don't really interact with the CC by code that much, but my guess is that you would have to incorporate a check of the ContentTableRow.IsSuppressed property while iterating the rows, and when it is True, use something like 'Continue For' to skip to the next row, instead of creating/generating a model for that row.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes