Add to “Frequently Used Subfolders” collection

<?xml encoding=”UTF-8″>By Adam Nagy (@AdamTheNagy)

As mentioned in this forum post, unfortunately, the relevant API does not work :(

Until it gets sorted, you could use the following workaround: edit directly the Project file (*.ipj), which is in fact an xml file.

The <Path> needs to starts with “Workspace” and then continue with the path to the subfolder you want to add. 

I’m showing how to do it in VBA, but .NET (also accessible from iLogic) has similar support for xml editing.  Just add a reference to the “Microsoft XML, v6.0” library:

MicrosoftXml

Sub AddFrequentlyUsedSubfolder()
Dim oProjectManager As DesignProjectManager
Set oProjectManager = ThisApplication.DesignProjectManager
Dim oProject As DesignProject
Set oProject = oProjectManager.ActiveDesignProject
' Use 'Microsoft XML, v6.0'
Dim xmlDoc As DOMDocument60
Set xmlDoc = New DOMDocument60
xmlDoc.async = False
Dim strProjectPath As String
strProjectPath = oProject.FullFileName
' Load the project file (*.ipj)
Call xmlDoc.Load(strProjectPath)
' Select the  node
Dim xmlProjectPaths As IXMLDOMNode
Call xmlDoc.setProperty("SelectionLanguage", "XPath")
Set xmlProjectPaths = xmlDoc.selectSingleNode("/InventorProject/ProjectPaths")
' Add the new subfolder
' We need to add something like this:
' <ProjectPath pathtype="FrequentlyUsedFolder">
'   <PathName>MyFolder</PathName>
'   <Path>WorkspaceMySubfolder</Path>
' </ProjectPath>
Dim xmlProjectPath As IXMLDOMNode
Set xmlProjectPath = xmlDoc.createNode(1, "ProjectPath", "")
Dim xmlPathType As IXMLDOMAttribute
Set xmlPathType = xmlDoc.createAttribute("pathtype")
xmlPathType.value = "FrequentlyUsedFolder"
Call xmlProjectPath.Attributes.setNamedItem(xmlPathType)
Dim xmlPathName As IXMLDOMNode
Set xmlPathName = xmlDoc.createNode(1, "PathName", "")
xmlPathName.Text = "MyFolder"
Call xmlProjectPath.appendChild(xmlPathName)
Dim xmlPath As IXMLDOMNode
Set xmlPath = xmlDoc.createNode(1, "Path", "")
xmlPath.Text = "Workspace" + "MySubfolder"
Call xmlProjectPath.appendChild(xmlPath)
Call xmlProjectPaths.appendChild(xmlProjectPath)
' Make another project active so that we can save the changes
Call oProjectManager.DesignProjects(1).Activate(False)
' Save the changes
Call xmlDoc.Save(strProjectPath)
' Make our project active again
Call oProject.Activate(False)
End Sub

MyFolder

 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading