Project XML
Home Products Services VBA for ADT

Project XML

In Autodesk Architectural Desktop 2004, a new collection of files was introduced. Within the Project Navigation System this most prevalent. Each project is controlled through an APJ file that contains all the information for that project. Also, each drawing file controlled by the Project Navigation System has an accompanying XML file that contains information of where this drawing exists within the project structure.

In general, both files are XML files. That being said, VBA will be required to use an XMLDom ActiveX control to modify these files. The XMLDom ActiveX control that will be used is the Microsoft XML, v3.0. Also in this section, the Microsoft Scripting Runtime control will be used to access file information.

Finding the Project XML

Function findDrawingProject() As File

    Dim fs As New FileSystemObject, reg As New Registry, pth As String

    pth = reg.GetSetting("HKEY_CURRENT_USER",  "Software\Autodesk\AutoCAD\R16.0\ACAD-204:409\Recent Project List",  "Project1")

    If pth <> "" Then

        If fs.FileExists(pth) Then

            Set findDrawingProject = fs.GetFile(pth)

        End If

    End If

End Function

 

Accessing the Project XML

Function getProjectXML(APJfname As String) As DOMDocument

    If APJfname = "" Then Exit Function

    Dim doc As New DOMDocument

    doc.Load APJfname

    Set getProjectXML = doc

End Function

 

Project Attributes

The Attributes of a project that can be modified allow are outlined in the list below.  These Attributes must exist within the project file.

Attrtibute

Description

Name

Name of the Project

Number

Number of the project

ProjectLocation

Full path to the APJ file being edited

UseNumberPrefix

Toggle (Yes/No) that defines whether the Number information listed above will be added to all file names.  This information will not be assigned to the name of the Element, Construct, View, or Sheet.

 

Project Attributes

Function getProjectElement(xDoc As DOMDocument) As IXMLDOMElement

    Set getProjectElement = xDoc.getElementsByTagName("Project")(0)

End Function

The following is an example o how to use the Project Access code.

Sub RenameProject()

    Dim def As String, name As String, pName As String

    Dim xDoc As DOMDocument, xElem As IXMLDOMElement

   

    pName = findDrawingProject

    Set xDoc = getProjectXML(pName)

    Set xElem = getProjectElement(xDoc)

   

    On Error Resume Next

   

    name = xElem.getAttribute("Name")

    def = ThisDrawing.Utility.GetString(True, "Project name<" & name & ">: ")

   

    If def <> "" Then

        xElem.setAttribute "Name", def

        xDoc.Save pName

       

        ThisDrawing.SendCommand "._aecRefreshProject "

    End If

   

    Set xElem = Nothing

    Set xDoc = Nothing

End Sub

 

Project Description

Function getProjectDescElement(xDoc As DOMDocument) As IXMLDOMElement

    Set getProjectDescElement = xDoc.getElementsByTagName("Description")(0)

End Function

The following is an example o how to use the Project Access code.

Sub ProjectDescription()

    Dim def As String, desc As String, pName As String

    Dim xDoc As DOMDocument, xElem As IXMLDOMElement

   

    pName = findDrawingProject

    Set xDoc = getProjectXML(pName)

    Set xElem = getProjectDescElement(xDoc)

   

    On Error Resume Next

   

    desc = xElem.text

    def = ThisDrawing.Utility.GetString(True, "Project Description <" & desc & ">: ")

   

    If StrComp(def, desc, 1) <> 0 Then

        xElem.text = def

        xDoc.Save pName

       

        ThisDrawing.SendCommand "._aecRefreshProject "

    End If

   

    Set xElem = Nothing

    Set xDoc = Nothing

End Sub

Project Details

Function getProjectDetails(xDoc As DOMDocument) As IXMLDOMNodeList

    Set getProjectDetails = getProjectElement(xDoc).getElementsByTagName("Details")

End Function

The following is an example o how to use the Project Access code.

Sub displayDetailNodes()

    Dim fn As String, xDoc As DOMDocument

    Dim i As Long, elem As IXMLDOMElement

   

    fn = findDrawingProject

    If fn = "" Then Exit Sub

   

    Set xDoc = getProjectXML(fn)

   

    Dim nodes As IXMLDOMNodeList

    Set nodes = getProjectDetails(xDoc)

   

    ThisDrawing.Utility.Prompt vbCrLf & vbCrLf & "Project Detail Nodes..."

    For i = 0 To nodes.Length - 1

        Set elem = nodes(i)

        ThisDrawing.Utility.Prompt vbCrLf & vbTab & elem.getAttribute("Name")

    Next

End Sub

Project Detail Section

Function getProjectDetailSection(pDetails As IXMLDOMNodeList, _

        sName As String) As IXMLDOMElement

    Dim i As Long, elem As IXMLDOMElement

    Dim name As String

    For i = 0 To pDetails.Length - 1

        Set elem = pDetails(i)

        name = elem.getAttribute("Name")

        If StrComp(name, sName, 1) = 0 Then

            Set getProjectDetailSection = elem

            Exit Function

        End If

    Next

End Function

The following is an example o how to use the Project Access code.

Function getProjectDetailEntry(pDetails As IXMLDOMNodeList, _

        sName As String, eName As String) As IXMLDOMElement

   

    Dim i As Long, name As String

    Dim dElem As IXMLDOMElement, eElem As IXMLDOMElement

    Set dElem = getProjectDetailSection(pDetails, sName)

   

    If dElem Is Nothing Then Exit Function

 

    For i = 0 To dElem.childNodes.Length - 1

        Set eElem = dElem.childNodes(i)

        name = eElem.getAttribute("Name")

        If StrComp(name, eName, 1) = 0 Then

            Set getProjectDetailEntry = eElem

            Exit Function

        End If

    Next

End Function

 

Project Templates

The Attributes of a project that can be modified allow are outlined in the list below.  These Attributes must exist within the project file.

Function getProjectTemplates(xDoc As DOMDocument) As IXMLDOMElement

    Set getProjectTemplates = getProjectElement(xDoc).getElementsByTagName("Templates").Item(0)

End Function

Function getProjectSubElement(element As IXMLDOMElement, name As String) As IXMLDOMElement

    Set getProjectSubElement = element.getElementsByTagName(name).Item(0)

End Function

The following is an example o how to use the Project Access code.

Sub displayProjectTemplates()

    Dim fn As String, xDoc As DOMDocument

    fn = findDrawingProject

    If fn = "" Then Exit Sub

   

    Set xDoc = getProjectXML(fn)

   

    Dim xElem As IXMLDOMElement

    Set xElem = getProjectTemplates(xDoc)

   

    Dim str As String

   

    str = "Element: " & getProjectSubElement(xElem, "ElementTemplate").firstChild.text

    str = str & vbLf

    str = str & "Constructs: " & getProjectSubElement(xElem, "SystemTemplate").firstChild.text

    str = str & vbLf

    str = str & "Views: " & getProjectSubElement(xElem, "ViewTemplate").firstChild.text

    str = str & vbLf

    str = str & "Sheets: " & getProjectSubElement(xElem, "DocumentTemplate").firstChild.text

    str = str & vbLf

   

    MsgBox str

   

End Sub

File Locations

The File Locations Section is a Node containing 5 Child Nodes.  These nodes control the file locations for various items within the project.  The following table lists the available nodes and their descriptions.

Node

Description

ProjectImagePath

Full path name of the image that would be assigned to the project.

ProjectBulletinBoardPath

Full Path to the HTML file displaying information about this project.  This location cannot be a WEB location.

StandardsLocation

Reserved…Not currently used (but leads to some pretty interesting questions)

PropertySetLocation

Full Path name of the file containing the Property Set Definitions for this project.

PalettesLocation

Reserved…Not currently used (but leads to some pretty interesting questions)

 

Function getProjectFiles(xDoc As DOMDocument) As IXMLDOMElement

    Set getProjectFiles = getProjectElement(xDoc).getElementsByTagName("FileLocations").Item(0)

End Function

The following is an example o how to use the Project Access code.

Sub displayProjectFiles()

    Dim fn As String, xDoc As DOMDocument

    fn = findDrawingProject

    If fn = "" Then Exit Sub

   

    Set xDoc = getProjectXML(fn)

   

    Dim xElem As IXMLDOMElement

    Set xElem = getProjectFiles(xDoc)

   

    Dim str As String

   

    str = "Images: " & getProjectSubElement(xElem, "ProjectImagePath").firstChild.text

    str = str & vbLf

    str = str & "ProjectBulletinBoardPath: " & getProjectSubElement(xElem, "ProjectBulletinBoardPath").firstChild.text

    str = str & vbLf

    str = str & "StandardsLocation: " & getProjectSubElement(xElem, "StandardsLocation").firstChild.text

    str = str & vbLf

    str = str & "PropertySetLocation: " & getProjectSubElement(xElem, "PropertySetLocation").firstChild.text

    str = str & vbLf

    str = str & "PalettesLocation: " & getProjectSubElement(xElem, "PalettesLocation").firstChild.text

    str = str & vbLf

   

    MsgBox str

   

End Sub

 

Level Information

The Level Section is a collection of Nodes within the Project.  Any number of Levels can be added to a Project and is one of the only sections of the Project file that will allow for new additions.  Each Level Section must have a unique name.  Each Level contains 6 Attributes that control the actions of the Level.  The following table lists the available attributes and their descriptions.

Attribute

Description

Name

Unique name of the Level.

Description

Description of the Level.

Elevation

Elevation of the Level provided as a real number (converted to a string)

Height

Floor to floor height of the Level provided as a real number (converted to a string)

Id

A Unique ID of the current floor, usually expressed as an integer.

ScheduleId

Value that will be use within the Level property of the project based schedule data.  Usually is the same as the Name.

 

Function getProjectLevels(xDoc As DOMDocument) As IXMLDOMNodeList

    Set getProjectLevels = getProjectElement(xDoc).getElementsByTagName("Level")

End Function

The following is an example o how to use the Project Access code.

Function getProjectLevel(levels As IXMLDOMNodeList, name As String) As IXMLDOMElement

    Dim i As Long, elem As IXMLDOMElement, val As String

    For i = 0 To levels.Length - 1

        Set elem = levels(i)

        val = elem.getAttribute("Name")

        If StrComp(name, val, 1) = 0 Then

            Set getProjectLevel = elem

            Exit Function

        End If

    Next

End Function

 

Division Information

The Division Section is a collection of Nodes within the Project.  Any number of Divisions can be added to a Project and is one of the only sections of the Project file that will allow for new additions.  Each Division Section must have a unique name.  Each Division contains 4 Attributes that control the actions of the Division.  The following table lists the available attributes and their descriptions.

Attribute

Description

Name

Unique name of the Division.

Description

Description of the Division.

Id

A Unique ID of the current floor, usually expressed as an integer.

ScheduleId

Value that will be use within the Division property of the project based schedule data.  Usually is the same as the Name.

 

Function getProjectDivision (xDoc As DOMDocument) As IXMLDOMNodeList

    Set getProjectDivision= getProjectElement(xDoc).getElementsByTagName("Division")

End Function

The following is an example o how to use the Project Access code.

Function getProjectDiv(Divisions As IXMLDOMNodeList, name As String) As IXMLDOMElement

    Dim i As Long, elem As IXMLDOMElement, val As String

    For i = 0 To Divisions.Length - 1

        Set elem = Divisions(i)

        val = elem.getAttribute("Name")

        If StrComp(name, val, 1) = 0 Then

            Set getProjectDiv = elem

            Exit Function

        End If

    Next

End Function