List components from content center

List components from content center

mgrenier2
Collaborator Collaborator
1,030 Views
17 Replies
Message 1 of 18

List components from content center

mgrenier2
Collaborator
Collaborator

I'm trying to list content center components in my assembly. Is there a way to do this? I'm starting to pull my hair off.

 

Here's what I have so far

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

Dim oCompDef As AssemblyComponentDefinition
oCompDef = oAsmDoc.ComponentDefinition

Dim oComp As ComponentOccurrence
Dim report As String = "Content Center components:" & vbCrLf

For Each oComp In oCompDef.Occurrences
    Try
        ' Check if component is from content center
        If oComp.Definition.DocumentDescriptor.IsContentMember Then
            report &= oComp.Name & "  -->  " & oComp.Definition.Document.FullFileName & vbCrLf
        End If
    Catch
        ' Some components may be virtual or not resolved 
    End Try
Next

' Show report
MsgBox(report, vbInformation, "CC List")
0 Likes
Accepted solutions (1)
1,031 Views
17 Replies
Replies (17)
Message 2 of 18

cidhelp
Collaborator
Collaborator

Hello @mgrenier2 ,

 

try changing this line:

If oComp.Definition.DocumentDescriptor.IsContentMember Then

to:

If oComp.Definition.IsContentMember Then

 

 

0 Likes
Message 3 of 18

mgrenier2
Collaborator
Collaborator

Nope, that didn't work. Does it matter if it's a custom(edited) or standard(unedited) cc part?

0 Likes
Message 4 of 18

WCrihfield
Mentor
Mentor

That property is only accessible when the component occurrence references a part (PartComponentDefinition.IsContentMember), not an (assembly or virtual or welds) type component, so some filtering would be necessary to avoid those other types of components.  It would also be wise to include filtering to avoid suppressed occurrences, if your assemblies may contain some of them, because accessing the 'Definition' property of a suppressed occurrence will also throw an error.  And since that property does not exist under the AssemblyComponentDefinition type, or the VirtualComponentDefinition type, or the WeldsComponentDefinition type, it will throw an error when you try to access that property from one of them.  Another place that can be checked is in the Document.PropertySets collection, because ones created by the Content Center will usually contain 1 or 2 extra PropertySets, just for Content Center related information.  Below is a Link to the online API help documentation for the Enum associated with one of those special PropertySets.

https://help.autodesk.com/view/INVNTOR/2026/ENU/?guid=PropertiesForContentLibraryEnum 

Edit:  Here is an updated example code to help:

Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
Dim oReport As New System.Text.StringBuilder()
oReport.AppendLine("Content Center Components Report:")
For Each oOcc As ComponentOccurrence In oADoc.ComponentDefinition.Occurrences
	If oOcc.Suppressed Then Continue For
	If Not TypeOf oOcc.Definition Is PartComponentDefinition Then Continue For
	Dim oOccPDef As PartComponentDefinition = oOcc.Definition
	If Not oOccPDef.IsContentMember Then Continue For
	oReport.AppendLine(oOcc.Name & " --> " & oOcc.ReferencedDocumentDescriptor.FullDocumentName)
Next
MsgBox(oReport.ToString(), vbInformation, "CC List")

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 18

mgrenier2
Collaborator
Collaborator

I'm just getting an empty MsgBox, besides the title and Content Center Components Report:

0 Likes
Message 6 of 18

m_baczewski
Advocate
Advocate

 

Hello

 

@mgrenier2 


Check this 

 

Sub main
	
	Dim oDoc As AssemblyDocument =TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	Dim oAsseCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oOccs As ComponentOccurrences = oAsseCompDef.Occurrences
	
	Dim contentCenter As String 
	For Each oRefDoc As Document In oDoc.AllReferencedDocuments
		
		If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
			Dim partDoc As PartDocument = oRefDoc
			If contentCenter <> "" Then
                    contentCenter = contentCenter & ", "
            End If
            contentCenter = contentCenter & partDoc.DisplayName
		End If
	Next
	MsgBox(contentCenter)
End Sub
0 Likes
Message 7 of 18

mgrenier2
Collaborator
Collaborator

This is exactly what I was hoping to achieve. Thanks you so much!!

 

It does list some unwanted components that are not from content center though

0 Likes
Message 8 of 18

WCrihfield
Mentor
Mentor

That's odd, because when I use it on one of my assemblies that contains parts, sub assemblies, and some content center fasteners, I get the expected report containing the component occurrence names followed by the full document name of the CC part they reference.  I am using Inventor Pro 2024.4 & Vault Pro 2024, but not sure if that matters though, because the PartComponentDefinition.IsContentMember Property was created back in the 2010 version of Inventor.  If I either suppress or delete the content center components, then run the rule again, I also get the result you described (title and first line only).  When components are suppressed, then we can not dig down into their definitions to check the value of that property, so they are skipped over.

However, that simplistic rule only iterates over the 'top level' components, and does not go down into any sub components.  So, if all the content center stuff is down within sub assemblies, and you want the rule to find them, then the code would need to be further developed to recurse down into the lower levels of the assembly.  If that is what you need, I can help.

WCrihfield_0-1761224581120.png

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 18

WCrihfield
Mentor
Mentor

Here is a 'recursive' example that will recurse down through all levels of components.  This will record an entry for each occurrence in every level of the assembly that is from the content center.  If you only need one entry line for each 'referenced document', not from each occurrence, then iterating through the AllReferencedDocuments collection may be a better fit, but would not include the names of the occurrences.  There is a way to get what all occurrences reference a specific referenced document through, if that would suit your needs better.  We simply don't have all the information about your intentions for this information yet.

Edit:  Another thing to keep in mind is the BOM, and the settings that effect whether components will be included in it or not.  The codes shown here so far do not obey or follow the BOM rules, other than Suppression.  It pays no attention to the BOMStructure settings (Normal, Reference, Purchased, Phantom, etc.) of each component.  If you need it to, then once again, the code would need to be further developed to enable that level of functionality.

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	'initialize the global variable that was declared between routines
	oReport = New System.Text.StringBuilder()
	'write heading line into the report
	oReport.AppendLine("Content Center Components Report:")
	'call custom Sub routing to recurse through all components in all levels
	RecurseComponents(oADoc.ComponentDefinition.Occurrences)
	'show report message
	MsgBox(oReport.ToString(), vbInformation, "CC List")
End Sub

'declare this variable between routines to make it globally accessible
Dim oReport As System.Text.StringBuilder

Sub RecurseComponents(occs As Inventor.ComponentOccurrences)
	For Each oOcc As Inventor.ComponentOccurrence In occs
		If oOcc.Suppressed Then Continue For
		If TypeOf oOcc.Definition Is PartComponentDefinition Then
			Dim oOccPDef As PartComponentDefinition = oOcc.Definition
			If oOccPDef.IsContentMember Then
				oReport.AppendLine(oOcc.Name & " --> " & _
				oOcc.ReferencedDocumentDescriptor.FullDocumentName)
			End If
		End If
		If TypeOf oOcc.Definition Is AssemblyComponentDefinition AndAlso
			oOcc.SubOccurrences.Count > 0 Then
			'call this same routine to run on the sub occurrences (recursion)
			RecurseComponents(oOcc.SubOccurrences)
		End If
	Next
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 18

mgrenier2
Collaborator
Collaborator

I think the issue is that I'm trying to list them from inside of a welded assembly and sh*t hits the fan because of this

0 Likes
Message 11 of 18

mgrenier2
Collaborator
Collaborator

Capture d’écran 2025-10-23 095557.png

0 Likes
Message 12 of 18

mateusz_baczewski
Advocate
Advocate
Sub main
	
	Dim oDoc As AssemblyDocument =TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	Dim oAsseCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oOccs As ComponentOccurrences = oAsseCompDef.Occurrences
	
	Dim contentCenter As String 
	For Each oRefDoc As Document In oDoc.AllReferencedDocuments
		
		If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
			Dim partDoc As PartDocument = oRefDoc
			If partDoc.ComponentDefinition.IsContentMember
				If contentCenter <> "" Then
                    contentCenter = contentCenter & ", "
	            End If
	            contentCenter = contentCenter & partDoc.DisplayName
			End If
		End If
	Next
	MsgBox(contentCenter)
End Sub
If you found it helpful, a "Like" would be much appreciated!
If this post solved your problem, please mark it as "Solution.".

0 Likes
Message 13 of 18

marcin_otręba
Advisor
Advisor
Accepted solution

hi,

 

@mgrenier2 i think that you want to list profiles placed from CC then it this will not work, you can check if that part has property sets named : ContentCenter or Content Library Component Properties

 

like:

 

Sub Main
	
	Dim oDoc As AssemblyDocument =TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	Dim oAsseCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition

	
	Dim contentCenter As String 
	For Each oRefDoc As Document In oDoc.AllReferencedDocuments
		
		If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject
			Dim partDoc As PartDocument = oRefDoc
			Dim cc As String = ""
			Try
				cc=oRefDoc.PropertySets.Item("ContentCenter").Name
			Catch ex As Exception
			End Try
			
			If partDoc.ComponentDefinition.IsContentMember Or cc="ContentCenter" Then
			
			If contentCenter <> "" Then
                    contentCenter = contentCenter & ", "
            End If
            contentCenter = contentCenter & partDoc.DisplayName
		End If
		End If
	Next
	MsgBox(contentCenter)
End Sub

 

 

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 14 of 18

WCrihfield
Mentor
Mentor

I am not sure why that one property is not working as expected for you, but yet another thought would be to get the full folder path of where your Content Center model files get stored, then as you iterate through referenced files, check if their full file path starts with the path to the Content Center.  I think that may only work when your Content Center stuff is not being stored in Vault though.  See example below.

Sub Main
	Dim oADoc As Inventor.AssemblyDocument = TryCast(ThisDoc.FactoryDocument, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	Dim sCCPath As String = ThisApplication.DesignProjectManager.ActiveDesignProject.ContentCenterPath
	Dim bCCPathIsEmpty As Boolean = String.IsNullOrWhiteSpace(sCCPath)
	Dim oReport As System.Text.StringBuilder = New System.Text.StringBuilder()
	For Each oRefDoc As Inventor.Document In oADoc.AllReferencedDocuments
		If Not TypeOf oRefDoc Is Inventor.PartDocument Then Continue For
		Dim oRefPDoc As Inventor.PartDocument = oRefDoc
		Dim bIsCC As Boolean = oRefPDoc.ComponentDefinition.IsContentMember
		If (Not bIsCC) And (Not bCCPathIsEmpty) Then bIsCC = (oRefPDoc.FullFileName.StartsWith(sCCPath))
		If bIsCC Then
			If oReport.Length = 0 Then oReport.AppendLine("Referenced Content Center Files Report:")
			oReport.AppendLine(oRefPDoc.FullFileName)
		End If
	Next
	MsgBox(vbCrLf & oReport.ToString())
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 15 of 18

marcin_otręba
Advisor
Advisor

@WCrihfield if i assumed correctly, and i think i did, @mgrenier2 wants to list cc profiles placed in assembly and when you place profiles from CC after you write desired length save window will pop up to save it at chosen location, this means that user can choose project folder (and i think it does), wchich means that code provided by you will not work.

Hi, maybe you want to vote my:

Ideas

or check my apps:

DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 16 of 18

mgrenier2
Collaborator
Collaborator

Using the file path won't cut it, they're customized content center parts so they don't get saved in the regular content center path, and the path will be different for each projects.

 

 marcin_otręba came up with something that worked just fine.

 

Thank you all

0 Likes
Message 17 of 18

WCrihfield
Mentor
Mentor

I was just trying to cover all possible paths forward, and did not know that they were all 'custom' ones, or I would not have suggested it.  I did mention the special PropertySets angle back in Message 4, but did not include their names, or a code example going that route, which I should have.  Glad something finally worked for you though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 18 of 18

mgrenier2
Collaborator
Collaborator

No worries guys

0 Likes