Get or Read Content Center Category

Get or Read Content Center Category

Guido.LangeTuchscherer
Enthusiast Enthusiast
1,428 Views
8 Replies
Message 1 of 9

Get or Read Content Center Category

Guido.LangeTuchscherer
Enthusiast
Enthusiast

Hello there, 

having a part open and running a rule I check wether it is generated by the content center:

If doc.PropertySets.PropertySetExists("ContentCenter") = True

an alternative would be:

			'If Err.Number = 0 then it is a CC-part
			If Err.Number = 0 Then 
				'If True then custom CC-part
				If iProperties.Value("ContentCenter", "IsCustomPart") = True Then 
					MessageBox.Show("Custom CC-part")
				Else 
					MessageBox.Show("Standard CC-part")
				End If

I would now like to check which category the part originates from, not the family, similar to the following i guess?

ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes.Item("Profile")

How do i simply read the DisplayName of the category or likely?

 

Thanks for your help in advance.

0 Likes
Accepted solutions (1)
1,429 Views
8 Replies
Replies (8)
Message 2 of 9

FINET_Laurent
Advisor
Advisor
Dim sString As String = ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes.Item(1).DisplayName
MsgBox(sString)

EDIT : Wait maybe i Understand your question wrong..

 

Regards,


FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 9

Guido.LangeTuchscherer
Enthusiast
Enthusiast

@FINET_Laurent 

 

Thanks for the quick Answer, getting closer 🙂

I need the information what ?? is for the current part:

ThisApplication.ContentCenter.TreeViewTopNode.ChildNodes.Item(??).DisplayName

 

0 Likes
Message 4 of 9

Anyone please:

 

Do I need to use this instead somehow?

ThisDoc.Document.PropertySets.Item(??)

 

0 Likes
Message 5 of 9

JhoelForshav
Mentor
Mentor

Hi @Guido.LangeTuchscherer 

I just modified my code from here: https://forums.autodesk.com/t5/inventor-customization/extract-type-of-a-part-when-it-is-either-a-bol... a little and I think it's what you're looking for. Try this. Just run the code and pick your content member. It'll give you the first childnode to the top node that this member can be reached from.

Sub Main
	Dim oOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick _
	(kAssemblyLeafOccurrenceFilter, "Pick occurrence")
	If oOcc.DefinitionDocumentType <> _
		kPartDocumentObject Then
		MsgBox("The occurrence is not a CC part.")
		Exit Sub
	End If
	Dim oOccDef As PartComponentDefinition = oOcc.Definition
	Dim oContentCenter As ContentCenter = ThisApplication.ContentCenter
	Dim propSet As PropertySet
	Try
	propSet = oOccDef.Document.PropertySets.Item("{B9600981-DEE8-4547-8D7C-E525B3A1727A}")
	Catch
		MsgBox("The occurrence is not a CC part.")
		Exit Sub
	End Try
	Dim familyId As Inventor.Property = propSet.Item("FamilyId")
	Dim oContentFamily As ContentFamily = oContentCenter.GetContentObject("v3#" & familyId.Value & "#")
	Dim oContentNode As ContentTreeViewNode = oContentCenter.TreeViewTopNode
	For Each oNode As ContentTreeViewNode In oContentNode.ChildNodes
		If SearchNode(oNode, oContentFamily) Then MsgBox(oNode.DisplayName)
	Next
End Sub
Function SearchNode(oNode As ContentTreeViewNode, oFamily As ContentFamily) As Boolean
	Dim FamFound As Boolean = False

	For Each oFam As ContentFamily In oNode.Families
		If oFam Is oFamily
			FamFound = True
			Return True
		End If
	Next
	If oNode.ChildNodes.Count > 0
		For Each oChild As ContentTreeViewNode In oNode.ChildNodes
			If SearchNode(oChild, oFamily) = True
				FamFound = True
				Return True
			End If
		Next
	End If
	Return FamFound
End Function
Message 6 of 9

JhoelForshav
Mentor
Mentor
Accepted solution

I just realized you wanted to run the rule from within the part. Not pick the part from an assembly.

Try this instead then 🙂

 

Sub Main
	Dim oDoc As PartDocument = ThisDoc.Document
	Try
		propSet = oDoc.PropertySets.Item("{B9600981-DEE8-4547-8D7C-E525B3A1727A}")
	Catch
		MsgBox("The Part is not a CC part.")
		Exit Sub
	End Try
	Dim CatName As String
	Dim oContentCenter As ContentCenter = ThisApplication.ContentCenter
	Dim familyId As Inventor.Property = propSet.Item("FamilyId")
	Dim oContentFamily As ContentFamily = oContentCenter.GetContentObject("v3#" & familyId.Value & "#")
	Dim oContentNode As ContentTreeViewNode = oContentCenter.TreeViewTopNode
	For Each oNode As ContentTreeViewNode In oContentNode.ChildNodes
		If SearchNode(oNode, oContentFamily) Then
			CatName = oNode.DisplayName
			Exit For
		End If
	Next
	'The node name is stored in variable CatName
	MsgBox(CatName)
End Sub
Function SearchNode(oNode As ContentTreeViewNode, oFamily As ContentFamily) As Boolean
	Dim FamFound As Boolean = False

	For Each oFam As ContentFamily In oNode.Families
		If oFam Is oFamily
			FamFound = True
			Return True
		End If
	Next
	If oNode.ChildNodes.Count > 0
		For Each oChild As ContentTreeViewNode In oNode.ChildNodes
			If SearchNode(oChild, oFamily) = True
				FamFound = True
				Return True
			End If
		Next
	End If
	Return FamFound
End Function
Message 7 of 9

Guido.LangeTuchscherer
Enthusiast
Enthusiast

@JhoelForshav 

Thanks for the code, yes the result is what i need, just wondered if it could be done a bit lighter, as I really just need to know the Content Center Category or "TopContentTreeViewNode"?

 

Like this gives me back the Family Table:

MsgBox(ThisApplication.ActiveDocument.PropertySets.Item("{B9600981-DEE8-4547-8D7C-E525B3A1727A}")("Family").Value)

Is there not a way to read directly the Current Node, is the Content Center not saving these anywere in the file, so just the Familyname?

 

0 Likes
Message 8 of 9

JhoelForshav
Mentor
Mentor

Hi @Guido.LangeTuchscherer 

From what I can tell there's no property in the document containing this information. That's why I wrote this code to use the family and search for it through the nodes in CC to determine its top node 🙂

Message 9 of 9

Guido.LangeTuchscherer
Enthusiast
Enthusiast

@JhoelForshav 

Thanks for your help, since I startet using the content center from 2021 it is a bit slow, so I will probably add a Row in the content center families we use, simply containing the information, to make the read quicker.

 

But that is another matter 🙂