How to Add New Collum in Content Center Itens by Code?

How to Add New Collum in Content Center Itens by Code?

welinton.zanotto
Explorer Explorer
698 Views
7 Replies
Message 1 of 8

How to Add New Collum in Content Center Itens by Code?

welinton.zanotto
Explorer
Explorer

Hello everyone,


I have a question about the possibility of programmatically adding new columns to existing items within the Content Center. I need to add these 2 new columns to all items, and I would like to do it via an API, is that possible?


I am trying with the code below, but when executing cf.TableColumns.Add it returns an unhandled error. Please, is the code correct, or is there another way to do this? Thank you in advance!

[TestMethod]
public void AddCollums()
{

string id = "Inventor User Defined Properties";

// Content center itens
ContentTreeViewNode treeViewTopNode = InvApp.App.ContentCenter.TreeViewTopNode;

var fm = treeViewTopNode.ChildNodes["Recursos"].ChildNodes["Bicos pulverizadores"];

foreach (ContentFamily cf in fm.Families)
{
Console.WriteLine("\t" + cf.DisplayName);

cf.TableColumns.Add("ModelCode", "", ValueTypeEnum.kStringType,false,false, id, "ModelCode");
cf.TableColumns.Add("ModelName", "Nome", ValueTypeEnum.kStringType,false, "{PARTNUMBER}", id, "ModelName");
cf.Save();
}
}

0 Likes
699 Views
7 Replies
Replies (7)
Message 2 of 8

bradeneuropeArthur
Mentor
Mentor

First you need a read/write family.

Do you have that?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 8

welinton.zanotto
Explorer
Explorer

Hello Arthur, thank you for your response.

Yes, the library is set for read/write, and I'am able to manually add and remove items or columns using the CC Editor.

0 Likes
Message 4 of 8

bradeneuropeArthur
Mentor
Mentor
Ok!
Could you give me the complete familyname?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 8

welinton.zanotto
Explorer
Explorer

yes, the names are in my code, commented alongside the methods
is this what you asked for?

[TestMethod]
public void AddCollums()
{
string id = "Inventor User Defined Properties";

// Contentcenter itens
ContentTreeViewNode treeViewTopNode = InvApp.App.ContentCenter.TreeViewTopNode;

var fm = treeViewTopNode.ChildNodes["Recursos"].ChildNodes["Bicos pulverizadores"];

Console.WriteLine(fm.FullTreeViewPath); // Recursos:Bicos pulverizadores
Console.WriteLine(fm.DisplayName); // Bicos pulverizadores

foreach (ContentFamily cf in fm.Families)
{
Console.WriteLine("\t" + cf.LibraryName); // MCL VALE
Console.WriteLine("\t" + cf.DisplayName); // BICO INOX 304 UMICONTROL MOD. UM-4-10 CM Ø2,8MM
Console.WriteLine("\t" + cf.MemberDirectory); // BICO INOX 304 UMICONTROL MOD. UM-4-10 CM Ø2,8MM ANGULO 60° 1-8 MACHO BSP

//// **** this CODE below fails *****
cf.TableColumns.Add("ModelCode", "", ValueTypeEnum.kStringType, false, false, id, "ModelCode");
cf.TableColumns.Add("ModelName", "Nome", ValueTypeEnum.kStringType,false, "{PARTNUMBER}", id, "ModelName");
cf.Save();
}
}

0 Likes
Message 6 of 8

bradeneuropeArthur
Mentor
Mentor

So this is the FamilyName, correct?:

BICO INOX 304 UMICONTROL MOD. UM-4-10 CM Ø2,8MM

And this the columns to be added?:

ModelCode

ModelName

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 8

bradeneuropeArthur
Mentor
Mentor

@welinton.zanotto 

This will work:

Sub main
Dim oContentCenter As ContentCenter= ThisApplication.ContentCenter
Dim a As ContentTreeViewNode = oContentCenter.TreeViewTopNode

loopCC(a)

	End Sub		
		
	Public Sub loopCC(c As ContentTreeViewNode)
		Dim f1 As ContentFamily
		Dim  id As String = "Inventor User Defined Properties"
		For Each c In c.ChildNodes
			If c.Families.Count > 0 Then
				For Each f As ContentFamily In c.Families

					If f.DisplayName = "BICO INOX 304 UMICONTROL MOD. UM-4-10 CM Ø2,8MM"
						f1 =f
						MsgBox(f1.DisplayName & " " & f1.IsModifiable)
						f1.TableColumns.Add("ModelCode", "", ValueTypeEnum.kStringType,False, ,id , "ModelCode")
						f1.TableColumns.Add("ModelName", "Nome", ValueTypeEnum.kStringType,False, "{PARTNUMBER}", id, "ModelName")
						f1.Save()
					Exit For
					End If
				Next
			Else
				loopCC(c)
		End If
			Next
	End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 8 of 8

tgregory3G7FA
Advocate
Advocate
bradeneuropeArthur wrote:

@welinton.zanotto 

This will work:

 

Sub main
Dim oContentCenter As ContentCenter= ThisApplication.ContentCenter
Dim a As ContentTreeViewNode = oContentCenter.TreeViewTopNode

loopCC(a)

	End Sub		
		
	Public Sub loopCC(c As ContentTreeViewNode)
		Dim f1 As ContentFamily
		Dim  id As String = "Inventor User Defined Properties"
		For Each c In c.ChildNodes
			If c.Families.Count > 0 Then
				For Each f As ContentFamily In c.Families

					If f.DisplayName = "BICO INOX 304 UMICONTROL MOD. UM-4-10 CM Ø2,8MM"
						f1 =f
						MsgBox(f1.DisplayName & " " & f1.IsModifiable)
						f1.TableColumns.Add("ModelCode", "", ValueTypeEnum.kStringType,False, ,id , "ModelCode")
						f1.TableColumns.Add("ModelName", "Nome", ValueTypeEnum.kStringType,False, "{PARTNUMBER}", id, "ModelName")
						f1.Save()
					Exit For
					End If
				Next
			Else
				loopCC(c)
		End If
			Next
	End Sub

 


This code does exactly what I'm looking for.  Only issue I have is it takes a long while to iterate through all sub categories.  Is it possible to target it directly to a sub category?

0 Likes