Content Center Library project configuration

Content Center Library project configuration

BromanSillito
Advocate Advocate
1,010 Views
3 Replies
Message 1 of 4

Content Center Library project configuration

BromanSillito
Advocate
Advocate

Is there a way in VB to programmatically check the Content Center libraries  "In-Use" checkbox in the "Configure Libraries" box for a Design Project as shown below?

CC_Lib_Config.JPG

 

0 Likes
Accepted solutions (1)
1,011 Views
3 Replies
Replies (3)
Message 2 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support

@BromanSillito,

 

Usually, content center library informations can be read as xml tags from the respective "Design Project" through Inventor API. which looks look like below.

 

<ContentCenterConfig>
          <ConfiguredLibraries>
                <Library DisplayName="Inventor ANSI" InternalName="7c4b738e-bdd6-4b6b-8700-5bf288a284c0" IsReadOnly="True" LibraryAttachName="AI2019_Inventor ANSI" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor DIN" InternalName="8b22eb12-e4e8-449b-a97b-ae3d5bbbfd12" IsReadOnly="True" LibraryAttachName="AI2019_Inventor DIN" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor Feature" InternalName="4367dfbc-f228-49f6-b4da-1a8b0df49d3f" IsReadOnly="True" LibraryAttachName="AI2019_Inventor Feature" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor ISO" InternalName="2558d7ef-04ac-43eb-8a44-e3748e516d14" IsReadOnly="True" LibraryAttachName="AI2019_Inventor ISO" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor JIS GB" InternalName="42d3d0d7-3c4b-4ae9-970d-954ebb779482" IsReadOnly="True" LibraryAttachName="AI2019_Inventor JIS &amp; GB" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor OTHER" InternalName="271cc27b-14af-45c8-8686-bc036143cde5" IsReadOnly="True" LibraryAttachName="AI2019_Inventor OTHER" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor Parker" InternalName="e759e04d-3827-4431-81a2-046642bff133" IsReadOnly="True" LibraryAttachName="AI2019_Inventor Parker" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor GOST" InternalName="5d735970-f300-11db-8314-0800200c9a66" IsReadOnly="True" LibraryAttachName="Inventor GOST" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor Sheet Metal" InternalName="0ec56ebe-3a6e-11dc-8314-0800200c9a66" IsReadOnly="True" LibraryAttachName="AI2019_Inventor Sheet Metal" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor Routed Systems" InternalName="92f6856b-8619-4dbf-ac8b-636b5161eabb" IsReadOnly="True" LibraryAttachName="AI2019_Inventor Routed Systems" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor Mold Imperial" InternalName="51dd6d3f-f272-4019-a724-002be458a6de" IsReadOnly="True" LibraryAttachName="Inventor Mold Imperial" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor Mold Meusburger" InternalName="512f8b67-01f6-4de7-9c9d-0e6cc2b64fb6" IsReadOnly="True" LibraryAttachName="Inventor Mold Meusburger" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor Mold Metric" InternalName="22c81190-8bba-44ee-94bd-e4dfe60d0815" IsReadOnly="True" LibraryAttachName="AI2019_Inventor Mold Metric" ServerName="DesktopContent"/>
                <Library DisplayName="Inventor IDF" InternalName="f436ed6d-3e79-40c4-95f7-ef53c8feba9e" IsReadOnly="True" LibraryAttachName="AI2019_Inventor IDF" ServerName="DesktopContent"/>
                <Library DisplayName="My Library" InternalName="2f1b22d8-e1e5-4955-81d6-f1cf62eab229" IsReadOnly="False" LibraryAttachName="My Library" ServerName="DesktopContent"/>
          <Library DisplayName="My Library" InternalName="2f1b22d8-e1e5-4955-81d6-f1cf62eab229" IsReadOnly="False" LibraryAttachName="My Library" ServerName="DesktopContent"/>
        </ConfiguredLibraries>
      </ContentCenterConfig>

 

Try below VBA code to check "My Library" in content center libraries.

 

Sub CCTest()
    Dim oDP As DesignProject
    Set oDP = ThisApplication.DesignProjectManager.ActiveDesignProject
         
    Dim xNode As IXMLDOMNode
    Dim XDoc As MSXML2.DOMDocument
    
    Dim strXML As String
    strXML = oDP.ContentCenterConfiguration.ConfigurationXML

    Set XDoc = New MSXML2.DOMDocument

    If Not XDoc.LoadXML(strXML) Then  'strXML is the string with XML'
        Err.Raise XDoc.parseError.ErrorCode, , XDoc.parseError.reason
    End If
    
    Set xNode = XDoc.lastChild.lastChild
    
    Dim oNew As IXMLDOMElement
    Set oNew = XDoc.createElement("Library")
    
    Dim att As IXMLDOMAttribute
    Set att = XDoc.createAttribute("DisplayName")
    att.Text = "My Library" 'This is library name to be enabled.
    
    Dim att1 As IXMLDOMAttribute
    Set att1 = XDoc.createAttribute("InternalName")
    att1.Text = "2f1b22d8-e1e5-4955-81d6-f1cf62eab229"
    
    Dim att2 As IXMLDOMAttribute
    Set att2 = XDoc.createAttribute("IsReadOnly")
    att2.Text = "False"
    
    Dim att3 As IXMLDOMAttribute
    Set att3 = XDoc.createAttribute("LibraryAttachName")
    att3.Text = "My Library"
    
    Dim att4 As IXMLDOMAttribute
    Set att4 = XDoc.createAttribute("ServerName")
    att4.Text = "DesktopContent"
    
    Call oNew.Attributes.setNamedItem(att)
    Call oNew.Attributes.setNamedItem(att1)
    Call oNew.Attributes.setNamedItem(att2)
    Call oNew.Attributes.setNamedItem(att3)
    Call oNew.Attributes.setNamedItem(att4)
    
    Call xNode.appendChild(oNew)
    
    Debug.Print XDoc.xml
    
    strXML = XDoc.xml
    
    oDP.ContentCenterConfiguration.ConfigurationXML = strXML
     
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 4

BromanSillito
Advocate
Advocate

Thank you for the response. When I run the code it creates a duplicate library node and checks it as shown below. I'm not very good with xml but I'm wondering if the function is creating a new node instead of finding the existing node or the Internal name that is used isn't matching the internal name of my library? Is there a function to read the internal name of my library to verify the internal name?

 

 CC_Lib_Config1.JPG

0 Likes
Message 4 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

@BromanSillito,

 

Internal names of libraries are varies from one system to another. Currently, Internal name of "My Library" in your system is different . So, it need to update(highlighted in red color) in below code.

 

Sub CCTest()
    Dim oDP As DesignProject
    Set oDP = ThisApplication.DesignProjectManager.ActiveDesignProject
         
    Dim xNode As IXMLDOMNode
    Dim XDoc As MSXML2.DOMDocument
    
    Dim strXML As String
    strXML = oDP.ContentCenterConfiguration.ConfigurationXML

    Set XDoc = New MSXML2.DOMDocument

    If Not XDoc.LoadXML(strXML) Then  'strXML is the string with XML'
        Err.Raise XDoc.parseError.ErrorCode, , XDoc.parseError.reason
    End If
    
    Set xNode = XDoc.lastChild.lastChild
    
    Dim oNew As IXMLDOMElement
    Set oNew = XDoc.createElement("Library")
    
    Dim att As IXMLDOMAttribute
    Set att = XDoc.createAttribute("DisplayName")
    att.Text = "My Library" 'This is library name to be enabled.
    
    Dim att1 As IXMLDOMAttribute
    Set att1 = XDoc.createAttribute("InternalName")
    att1.Text = "2f1b22d8-e1e5-4955-81d6-f1cf62eab229" 'Internal name varies from system to system.
    
    Dim att2 As IXMLDOMAttribute
    Set att2 = XDoc.createAttribute("IsReadOnly")
    att2.Text = "False"
    
    Dim att3 As IXMLDOMAttribute
    Set att3 = XDoc.createAttribute("LibraryAttachName")
    att3.Text = "My Library"
    
    Dim att4 As IXMLDOMAttribute
    Set att4 = XDoc.createAttribute("ServerName")
    att4.Text = "DesktopContent"
    
    Call oNew.Attributes.setNamedItem(att)
    Call oNew.Attributes.setNamedItem(att1)
    Call oNew.Attributes.setNamedItem(att2)
    Call oNew.Attributes.setNamedItem(att3)
    Call oNew.Attributes.setNamedItem(att4)
    
    Call xNode.appendChild(oNew)
    
    Debug.Print XDoc.xml
    
    strXML = XDoc.xml
    
    oDP.ContentCenterConfiguration.ConfigurationXML = strXML
     
End Sub

To get internal names of content center libraries, check all libraries in content center configuration and run below code. In Immediate window, it prints all Library name and internal names as well.

Sub CCTest()
    Dim oDP As DesignProject
    Set oDP = ThisApplication.DesignProjectManager.ActiveDesignProject
         
    Dim xNode As IXMLDOMNode
    Dim XDoc As MSXML2.DOMDocument
    
    Debug.Print oDP.ContentCenterConfiguration.ConfigurationXML
End Sub
    

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network