Hi again!
I am back. 🙂 ...the solution I found has a problem -> you won't be able to define any parameters for the categories. I haven't found any way how to do that via API, so please let me know, if your success depends on being able to create also some category parameters. If so, I will try to find a way, but I doubt it exists.
To run the code, just bring up the Inventor's VBA window (Alt+F11) and paste it in "Module".
Now here is the code snippet (do not forget to replace "user" and "release number" in paths, please mind also comments about how to find Internal Name of your Read Write Library in LibraryList.xml):
Public Sub AddCategoryAnSubCategory()
Dim oCC As ContentCenter
Set oCC = ThisApplication.ContentCenter
Dim oFamilyMng As FamilyManager
'desired functionality can be found in CategoryManager object, particulary in its AddCategory method
Set oCatMgr = oCC.CategoryManager
Dim strNewCatID As String
Dim strNewSubCatID As String
Dim strNewCatXML As String
'new category XML - Library attribute must contain internal name of the RW library, customize also DisplayName and Mnemonic attributes
'the Internal name of the Library can be found in C:\Users\<user>\AppData\Local\Autodesk\Inventor 2021\Content Center\CMCache\DesktopContent\LibraryList.xml
'look for <Item Key="YOUR_RW_LIBRARY_NAME"> in LibraryList.xml, nearby you can see its internal name <Property Name="InternalName" Value="1cba5044-b449-4e1d-92bb-de34780bcfc1">
'In this case the new category XML looks like this:
strNewCatXML = "<?xml version=""1.0"" encoding=""UTF-16""?>" & _
"<Category InternalName="""" DisplayName=""My Top Level Category"" RevisionId="""" Mnemonic=""MY TOP LEVEL CATEGORY"" SpecialAuthoring=""false"" Hidden=""false"" Library=""1cba5044-b449-4e1d-92bb-de34780bcfc1""><Icon><File FullFileName=""C:\Users\user\AppData\Local\Autodesk\Inventor 2021\Content Center\PC\My Top Level Category.ico""/></Icon></Category>"
'create top level category
strNewCatID = oCatMgr.AddCategory("", strNewCatXML, "1cba5044-b449-4e1d-92bb-de34780bcfc1")
'Use strNewCatID to create sub category. Reuse the xml, just replace names.
strNewSubCatXML = Replace(strNewCatXML, "My Top Level Category", "My Sub Category")
strNewSubCatXML = Replace(strNewSubCatXML, "MY TOP LEVEL CATEGORY", "MY SUB CATEGORY")
'create sub category - just use parent category ID, returned after creation of the parent category - strNewCatID
strNewSubCatID = oCatMgr.AddCategory(strNewCatID, strNewSubCatXML, "1cba5044-b449-4e1d-92bb-de34780bcfc1")
'strNewSubCatID contains category ID of newly created sub category
'please notice that these created categories do not have any parameters defined and it is not possible to add them later
End Sub
Please feel free to ask any questions.
Best regards,
Ludek
Ludek Sulc
Sr. SW Engineer