Insert Content Center Part

<?xml encoding=”UTF-8″>By Adam Nagy

You can insert Content Center parts programmatically. The following sample is looking through the whole Content Center content in order to find a specific part based on its display name.

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
Public Sub CcTest()
Dim asm As AssemblyDocument
Set asm = ThisApplication.ActiveDocument
Dim cf As ContentFamily
Set cf = GetFamily("CCPart", Nothing)
Dim member As String
Dim ee As MemberManagerErrorsEnum
member = cf.CreateMember(1, ee, "Problem")
Dim tg As TransientGeometry
Set tg = ThisApplication.TransientGeometry
Call asm.ComponentDefinition.Occurrences.Add( _
member, tg.CreateMatrix())
End Sub

The API Help File (C:UsersPublicDocumentsAutodeskInventor 2017Local Helpadmapi_21_0.chm) also contains a couple of samples concerning this topic:
– Place Content Center Parts API Sample
– Replace content center part API Sample


Comments

3 responses to “Insert Content Center Part”

  1. Adam,
    I ran this code in Inventor 2019, but get an Error 91 when executing the line:
    member = cf.CreateMember(1, ee, “Problem”)
    The variable, ‘ee’, is declared, but doesn’t seem to have a value before it is assigned to ‘member’.
    Should this code work with Inventor 2019?
    Regards,
    Jerry

  2. Are you running it using VBA?

  3. hamed ashrafi Avatar
    hamed ashrafi

    this github library makes it super easy to add content center into an assembly
    https://github.com/HYMMA/InventorToolBox/blob/master/InventorToolBoxConsole/Program.cs

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading