@J_Dumont,
I too wanted to learn how to insert Content Center parts using VB.NET.
Could you provide an example of the NND and NLG you want to place?
I found this source code, which originally inserted all the parts of a family.
Place Content Center Parts API Sample
I converted the code to a subroutine that receives arguments similar to the iLogic command. Currently, it supports a single column filter. In my case, I know StockNumber is unique.
Private Sub Main()
Break
Call PlaceFromContentCenter("Fasteners", "Washers", "Plain", "NMC Flat Washer - Inch", "Stock Number", "030-0254")
End Sub
''' <summary>
''' Place a component from Content Center using VB.NET
''' </summary>
''' <param name="oNode1">Category</param>
''' <param name="oNode2">Subcategory</param>
''' <param name="oNode3">SubSubCategory</param>
''' <param name="oFamilyName">Family name</param>
''' <param name="oColName">Column name</param>
''' <param name="oValue">Value to find</param>
Public Sub PlaceFromContentCenter(oNode1 As String, oNode2 As String, oNode3 As String, oFamilyName As String, oColName As String, oValue As String)
Break
logger.Trace("Entering PFCC")
Dim asmDoc As AssemblyDocument = ThisApplication.Documents.Add(kAssemblyDocumentObject)
Dim asmDef As AssemblyComponentDefinition = asmDoc.ComponentDefinition
' Get the node in the content browser based on the names of the nodes in the hierarchy.
' Dim hexHeadNode As ContentTreeViewNode = ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners").ChildNodes.Item("Washers").ChildNodes.Item("Plain")
Dim hexHeadNode As ContentTreeViewNode = ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes.Item(oNode1).ChildNodes.Item(oNode2).ChildNodes.Item(oNode3)
' 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 = "NMC Flat Washer - Inch" Then
If checkFamily.DisplayName = oFamilyName Then
family = checkFamily
Exit For
End If
Next
Dim i As Integer = 0
If Not family Is Nothing Then
' Place one instance of each member.
Dim offset As Double
offset = 0
Dim row As ContentTableRow
' Get column
Dim oSNcol As Integer = 0
For i = 1 To family.TableColumns.Count
' If family.TableColumns.Item(i).DisplayHeading = "Stock Number" Then
If family.TableColumns.Item(i).DisplayHeading = oColName Then
oSNcol = i
Exit For
End If
Next i
' create member if value is found
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 oSNcol <> 0 Then
' If row.Item(oSNcol).Value = "030-0254" Then
If row.Item(oSNcol).Value = oValue Then
memberFilename = family.CreateMember(row, failureReason, failureMessage, kRefreshOutOfDateParts)
Else
memberFilename = Nothing
End If
End If
Break
' Place the part into the assembly.
If Not IsNothing(memberFilename) AndAlso memberFilename.Length <> 0 Then
Dim transMatrix As Matrix = ThisApplication.TransientGeometry.CreateMatrix
transMatrix.Cell(2, 4) = offset
Dim Occ As ComponentOccurrence = 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
In the example above, I am searching for a plain flat washer having a specific stock number. Since the code originally placed multiple parts, you could remove a large portion of the code in lines 75-86 that increments the insertion point. For a single part, your would just need line 78.
I left commented lines in the code that represent the hard-coded search for that specific washer.
All that code above can make one appreciate how much work is going on inside the iLogic 'Components.AddContentCenterPart'
Dim Washer1 = Components.AddContentCenterPart(
"Washer1",
"Fasteners:Washers:Plain",
"NMC Flat Washer - Inch",
{ "StockNumber", "030-0254" },
position := Nothing, grounded := False,
visible := True, appearance := Nothing)
Let us know if this is helpful. Please mark as 'Accepted' if this answers your question.
Regards,
Jerry
-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional