This group of objects encapsulates the database capabilities of the Application. Two major object models exist to support this group: the database engine (McDBLib) and the data manager (McAddinData).  The database capabilities of the applicaiton include:

 

Examples:

The following examples illustrate some of the more common uses of the Database capabilities of the application and demonstrate some aspects of both object models described above.  All applications may be run in either VBA or compiled Visual Basic.

Creating and manipulating a database.

Public Sub MakeTwoFolderDatabase()

   ' Use DataManager's CreateDatabase to create an application compliant database

   Application.DataManager.CreateDatabase "MyAppDB"

   ' Use Datamanager's TargetDataNodes to open the database and to save a current path position.

   Application.DataManager.TargetDataNodes.Current.SetNode "//MyAppDB\"

   ' Add a Database folder to the saved current path position.

   Application.DataManager.TargetDataNodes.AddFolder "MyFolder in MyAppDB"

   ' Add another Database folder to the saved current path position.

   Application.DataManager.TargetDataNodes.AddFolder "AnotherFolder in MyAppDB"

   ' Application.DataManager.TargetDataNodes.Current will continue to hold "//MyAppDB\"

   ' after this function ends

End Sub

 

 

Public Sub CreateNewMcFilesField()

   ' Add an attribute (field) to all objects of type 'McFiles' in Demo database

   Application.Databases("Demo").Types("McFiles").Attributes.Add("RelatedProject", mcdbString)

End Sub

 

Note that if the above macro fails with a run-time error 91: Object variable or With block variable not set, it is likely because the Demo database is not open or does not exist.

 

 

Storing images and files

Public Sub StoreActiveImageToTarget()

   ' Add the image object to database and remember the new database object.

   Dim dbnodeAdded as McDBNode

   Set dbnodeAdded = Application.DataManager.TargetDataNodes.AddObject( Application.ActiveImage )

 

   ' Now assign a new value to the Description

   dbnodeAdded.Attributes("Description") = "Added by a Macro"

End Sub

 

Public Sub StoreFileToTarget()

   ' Add the file at the given path into the database as a child of 'Target'.

   Application.DataManager.TargetDataNodes.AddFile "C:\Temp\SomeFile.txt"

End Sub

 

Dim WithEvents MyDataManagerVariable as McDataManager
Set MyDataManagerVariable = Application.DataManager

Public Sub MyDataManagerVariable_AfterAddNodeFile(ByVal pnoderefCurrent As McDataNodeRef, _                                                                                     ByVal pmcdbnodeAddedNode As McDBNode, _                                                                                ByVal eStorage As McDataNodeStorageMethods)

      ' Is the file being added to the 'Target'?

    If pnoderefCurrent.ID = Application.DataManager.TargetDataNodes.Current.ID Then

       ' Display the original author and path of the new database object to the VBA debug window

       Debug.Print pmcdbnodeAddedNode.Path(True), "Author was:"; pmcdbnodeAddedNode.Attributes("Author")

       ' Assign Marco Macro to the Author attribute

       dbnodeAdded.Attributes("Author") = "Marco Macro"

       ' ReDisplay the author and path of the new database object to the VBA debug window

       Debug.Print pmcdbnodeAddedNode.Path(True), "Author is:"; pmcdbnodeAddedNode.Attributes("Author")

   End If

End Sub

 

Note that the above macro requires proper scoping of the MyDataManagerVariable object (e.g. within a UserForm).  To see the effects of this macro from VBA, create a UserForm and place the Dim statement in its Declarations section and place the Set command the UserForm's Show event.  Then display the UserForm modeless (mccdsModeless), set the Target, and add a File to the Target.  The results will appear in the VBA immediate window and the Author attribute of the added file in the database user interface.

 

Retrieving and displaying images and data

Public Sub OpenSelection()

       Application.DataManager.SelectedDataNodes.NodeOpen

End Sub

 

Public Sub OpenDemoSamples()

   ' Clear the ActiveDataNodes

   Application.DataManager.ActiveDataNodes.Selection.RemoveAll

   ' Add all children of Samples in the Demo Database

   Application.DataManager.ActiveDataNodes.Selection.AddChildren "//Demo\Sample\"

   ' Open the .Data on all of the selected objects

   Application.DataManager.ActiveDataNodes.NodeOpen 

End Sub

 

Public Sub GetNodeAttributes()

   ' Find and remember the first child of //Demo\Samples

   Dim dbnodeChild as McDBNode

   Dim ThisAttribute as Variant

   set dbnodeChild = Application.Databases.RetrieveNode("//Demo\Sample").Children(0)

   ' Display the Attributes of the retrieved McDBNode

   Debug.Print "Attributes of node: "; dbnodeChild.Path(True, True)

   For Each ThisAttribute in dbnodeChild.Attributes

       Debug.Print ThisAttribute, "=";                    ' The Attribute's name

       Debug.Print dbnodeChild.Attributes(ThisAttribute)  ' The Attribute's value

   Next

End Sub

 

Note: The results from this macro will appear in the VBA immediate window.

 

Querying a database

Public Sub MakeQueryResults()

   ' Create and remember a search query for the whole 'Demo' database.

   Dim mcdbqueryDemo as McDBQuery

   Set mcdbqueryDemo = Application.Databases.Item("Demo").CreateQuery

   If mcdbqueryDemo Is Nothing then Stop

 

   ' set the search criteria to objects whose 'FileFormat' is "SEQ" and FrameCount is greater

   ' than or equal to 1.

   mcdbqueryDemo.SetAttribute "FileFormat", "SEQ", mcdbEQ Or mcdbIgnoreCase

   mcdbqueryDemo.SetAttribute "FrameCount", 1, mcdbGTE

 

   ' Execute the query and save the resultant database object to a folder in the Journal.

   Application.DataManager.MakeQuery mcdbqueryDemo, mcdatmqc_UseQuery, , , _

      "Sequences in Demo Database"

End Sub

 

Where to go from here

Understanding of both the McDBLib and McDataAddin object models is necessary to fully utilize the database capabilities of the application, as each model serves a particular purpose.  The McDataAddin objects facilitate accomplishment of most tasks.  As the examples illustrate, McDataAddin objects can create and manipulate databases, store images, and automatically generate and store core information about them.  However, the objects representing the information in a database, even those created or manipulated by the McDataAddin, are McDBLib objects, so understanding of these objects and their interactions is likely necessary to do customized processessing or manipulation of data.  Further, some advanced features, such as database security and transactions, may only be manipulated through McDBLib objects.