Silently Creating A Workspace
I'm trying to silently add a workspace to a database and set the name, all through code. There seems to be little on the IManNewWorkspaceCmd or IManNewWorkspaceDlg in the documentation, and the Workspaces collection has a lot of confusing functions and properties, and I'm not sure which ones to use in which order, and most seem to be read-only! In short, I'm very confused on how this is done, so I'll lay out what I've tried and found.
Using the Workspaces collection
AddWorkspace needs a workspace passed to it, but the IManWorkspace is public non-creatable
AddWorkspace also seems to be adding to a read-only collection, so I don't see how that's ever going to work
IManNewWorkspaceCmd
I have worked out that this needs the NRTSession, rather than IManSession (as it says in the SDK), but it displays a dialog, and there is no NoCmdUI context item to silence it. I cannot see any way to automatically pre-fill any fields, which would allow the possibility of using one of the forms events to execute the OK as soon as it loads.
IManNewWorkspaceDlg
Again, there is the possibility of using this and executing the OK, but when the dialog displays and I manually fill in the information and click Save, no workspace is created.
Any help of this will be very appretiated
My Code
An app with 3 buttons, one for each of the above methods:
Private Sub Command1_Click()
Dim objDMS As NRTDMS
Dim objIManDB As IManDatabase
Dim hWnd As Long
Dim objWorkspace As IManWorkspace
Set objDMS = Word.Application.COMAddIns("iManO2K.AddinForWord2000").object.Context("NRTDMS")
Set objIManDB = objDMS.Sessions(1).Databases(1)
hWnd = FindWindow("OpusApp" & Chr$(0), Chr$(0))
Set objWorkspace = objIManDB.CreateWorkspace
With objWorkspace
.Name = "AT LAST!"
.AddToRecentWorkspaces
End With
objIManDB.Workspaces.AddWorkspace objWorkspace
Unload Me
End Sub
Private Sub Command2_Click()
Dim objDMS As NRTDMS
Dim objIManDB As IManDatabase
Dim hWnd As Long
Dim objAddCmd As New IManNewWorkspaceCmd
Dim objContextItems As New ContextItems
Dim objWorkspace As IManWorkspace
Dim aobjImanSessions(1 To 1) As NRTSession
Set objDMS = Word.Application.COMAddIns("iManO2K.AddinForWord2000").object.Context("NRTDMS")
Set objIManDB = objDMS.Sessions(1).Databases(1)
hWnd = FindWindow("OpusApp" & Chr$(0), Chr$(0))
With objContextItems
.Add "ParentWindow", hWnd
Set aobjImanSessions(1) = objIManDB.Session
.Add "SelectedNRTSessions", aobjImanSessions
.Add "IManDestinationObject", objIManDB
End With
With objAddCmd
.Initialize objContextItems
Rem Check it's OK before executung
If .Status = nrActiveCommand Then
.Execute
End If
End With
objIManDB.Workspaces.AddWorkspace objWorkspace
Unload Me
End Sub
Private Sub Command3_Click()
Dim objDMS As NRTDMS
Dim objIManDB As IManDatabase
Dim hWnd As Long
Dim objWorkspace As IManWorkspace
Dim aobjImanSessions(1 To 1) As NRTDatabase
Set objDMS = Word.Application.COMAddIns("iManO2K.AddinForWord2000").object.Context("NRTDMS")
Set objIManDB = objDMS.Sessions(1).Databases(1)
hWnd = FindWindow("OpusApp" & Chr$(0), Chr$(0))
Set dlg = New IManNewWorkspaceDlg
With dlg
.Database = objIManDB
Set aobjImanSessions(1) = objIManDB
.DatabasesArray = aobjImanSessions
.CloseOnOK = True
.SetAttributeValueByID nrName, "Hello", False
.Show hWnd
End With
Unload Me
End Sub