Mass create folders inside Content Center Library

Mass create folders inside Content Center Library

amarcoc
Advocate Advocate
810 Views
11 Replies
Message 1 of 12

Mass create folders inside Content Center Library

amarcoc
Advocate
Advocate

Hi everybody

 

I need to create 2700+ folders and subfolders in a new content center library.

 

Is there a way to automate this?

 

Thanks everyone

 

(using 2019.4.2 / Windows 10 64 bits)

0 Likes
Accepted solutions (2)
811 Views
11 Replies
Replies (11)
Message 2 of 12

johnsonshiue
Community Manager
Community Manager

Hi Marco,

 

Unfortunately, there isn't a quick way that I am aware of to do that.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 3 of 12

Mark.Lancaster
Consultant
Consultant

@amarcoc 

 

May I ask why you need to create that many categories and sub categories in your content center.  They are not folders..  

 

For all the years that I managed CC I never had a need to create nearly that amount or even close.  Trying to understand what you're trying to accomplish .   Content center is not like File explorer.  

Mark Lancaster


  &  Autodesk Services MarketPlace Provider


Autodesk Inventor Certified Professional & not an Autodesk Employee


Likes is much appreciated if the information I have shared is helpful to you and/or others


Did this resolve your issue? Please accept it "As a Solution" so others may benefit from it.

0 Likes
Message 4 of 12

amarcoc
Advocate
Advocate

Thank you for the replies. 

 

I was trying to replicate a client's full catalogue structure.

 

But in fact, meanwhile I noticed that most of them are not physical parts. So, I cleaned folder structure, and it has currently about 250 folders.

 

Its a lot of work to do. Any API available to do it quicker?

 

I have an excel with folder structure.

 

Thanks!

0 Likes
Message 5 of 12

ludek.sulc
Autodesk
Autodesk

Hi Marco,

I am looking into an undocumented way via our internal API. I have to test it and discuss it with other Devs. Whenever I have a sample code, I will post it here.

 

Best regards.

Ludek



Ludek Sulc
Sr. SW Engineer
Message 6 of 12

ludek.sulc
Autodesk
Autodesk
Accepted solution

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
Message 7 of 12

amarcoc
Advocate
Advocate

Nice!

 

I will look at it.

 

Its OK about the parameter. I will test it.

 

Thanks!

0 Likes
Message 8 of 12

jan_priban
Alumni
Alumni
Accepted solution

Hi Marco,

 

Inventor Content Center API allows you to get library internal name as well

 

Regards

 

Jan Priban

 

Sub ShowUserLibraryInfo()

 

Dim oCC As ContentCenter
Set oCC = ThisApplication.ContentCenter

 

Dim oLibraryMgr As LibraryManager
Set oLibraryMgr = oCC.LibraryManager

 

Dim sServerLibraries As String
sServerLibraries = oLibraryMgr.GetServerLibraries()

 

' Get target r/w library internal name"
Dim xmlDoc As Object
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.async = False
xmlDoc.loadXML sServerLibraries

Dim sMyLibDisplayName As String
sMyLibDisplayName = xmlDoc.selectNodes("/Libraries/Library[@ReadOnly='false']").Item(0).Attributes.getNamedItem("DisplayName").Text
MsgBox sMyLibDisplayName

Dim sMyLibInterName As String
sMyLibInterName = xmlDoc.selectNodes("/Libraries/Library[@ReadOnly='false']").Item(0).Attributes.getNamedItem("InternalName").Text
MsgBox sMyLibInterName

End Sub

Message 9 of 12

amarcoc
Advocate
Advocate

Thank you for the help.

 

I get instant fatal error when running the macro.

 

I already replaced the internal ID for my own idcl file and path of the ICO file.

 

Should I replace anything else?

 

EDIT: My new idcl file is empty. I just used the "Create library" tool.

EDIT: It worked! Thanks

Message 10 of 12

ludek.sulc
Autodesk
Autodesk

I am glad it works for you!

 

Have a nice weekend!

Best regards

Ludek



Ludek Sulc
Sr. SW Engineer
0 Likes
Message 11 of 12

amarcoc
Advocate
Advocate

Hi again.

 

I am personalizing the macro, and I noticed that it will create several "CAT1" instead of reusing the same.

 

You notice it if you delete the subcategories and top categories in content center editor.

 

Could this be fixed?

 

Here is the code I am using:

 

Public Sub CreateFoldersContentCenter()
    Call AddCategoryAnSubCategory("AMCCAT2", "AMCSUBCAT1", ShowUserLibraryInfo())
    Call AddCategoryAnSubCategory("AMCCAT2", "AMCSUBCAT2", ShowUserLibraryInfo())
    Call AddCategoryAnSubCategory("AMCCAT2", "AMCSUBCAT3", ShowUserLibraryInfo())
End Sub

Public Sub AddCategoryAnSubCategory(NewCatName As String, NewSubCatName As String, IdLibrary As String)
    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
    
    strNewCatXML = "<?xml version=""1.0"" encoding=""UTF-16""?><Category InternalName="""" DisplayName=""" & NewCatName & """ RevisionId="""" Mnemonic=""" & NewCatName & """ SpecialAuthoring=""false"" Hidden=""false"" Library=""" & IdLibrary & """><Icon><File FullFileName=""C:\Users\amc\AppData\Local\Autodesk\Inventor 2019\Content Center\PC\My Top Level Category.ico""/></Icon></Category>"
    strNewCatID = oCatMgr.AddCategory("", strNewCatXML, IdLibrary) 'create top level category
    strNewSubCatXML = Replace(strNewCatXML, NewCatName, NewSubCatName) 'Use strNewCatID to create sub category. Reuse the xml, just replace names.
    strNewSubCatID = oCatMgr.AddCategory(strNewCatID, strNewSubCatXML, IdLibrary) 'create sub category - just use parent category ID, returned after creation of the parent category - strNewCatID
    '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


Public Function ShowUserLibraryInfo() As String
    Dim oCC As ContentCenter
    Set oCC = ThisApplication.ContentCenter
    
    Dim oLibraryMgr As LibraryManager
    Set oLibraryMgr = oCC.LibraryManager
    
    Dim sServerLibraries As String
    sServerLibraries = oLibraryMgr.GetServerLibraries()
    
    ' Get target r/w library internal name"
    Dim xmlDoc As Object
    Set xmlDoc = CreateObject("MSXML2.DOMDocument")
    xmlDoc.async = False
    xmlDoc.loadXML sServerLibraries
    
    Dim sMyLibInterName As String
    sMyLibInterName = xmlDoc.selectNodes("/Libraries/Library[@ReadOnly='false']").Item(0).Attributes.getNamedItem("InternalName").Text
    ShowUserLibraryInfo = sMyLibInterName
End Function

 

Message 12 of 12

ludek.sulc
Autodesk
Autodesk

Hi Marco,

to reuse the existing category as a parent, you just need to provide its internal ID for creation of the sub category:

strNewCatID = oCatMgr.AddCategory("", strNewCatXML, IdLibrary) - this creates top level category, because the first parameter (parent category ID) is empty string. It returns ID of created category into strNewCatID.

Now if you want to create category under it, you just need use the parent ID - strNewCatID as a first parameter:

strNewSubCatID = oCatMgr.AddCategory(strNewCatID, strNewSubCatXML, IdLibrary)

 

In your code, you create both a new top level category and its sub category everytime you call AddCategoryAnSubCategory.

You need to retrieve the existing parent category ID (like keep it in global dictionary and consume it in the code, or make your method to return IDs of created categories) and create method which creates sub categories under provided category IDs.

 

Best regards

Ludek

 



Ludek Sulc
Sr. SW Engineer