[V8i VB.Net] Opening new Map instance with desired workspace

I have application written in VB.Net that has to write xfm features in Map opened with
specified user workspace. For now it connects to the first opened design file and tries
to write in it. It's not good because user can have multiple files opened with
different user workspaces and every workspace has it's own features. So my goal is to
start new instance of Map with specified user workspace, open design file and write in it.

1. I know how to start Map with user ws by using shell command but I don't know how
connect to dgn file opened like that if there are more than one of Map instances
opened. I realize that is COM problem and tried to implement accessing via Processes MainWindowHandle by without success

2. I tried to change configuration variable when creating new Map process with ApplicationObjectConnector:

    Private Sub testWS()

        Dim mApp As MicroStationDGN.Application
        Dim mConn As MicroStationDGN.ApplicationObjectConnector = New MicroStationDGN.ApplicationObjectConnectorClass
        mApp = mConn.Application

        'any other configuration variable?
        mApp.ActiveWorkspace.AddConfigurationVariable("_USTN_USERNAME", "myTestUser", False)

        Dim dgn As MicroStationDGN.DesignFile = mApp.OpenDesignFile("C:\ftTempl.dgn", False, Bentley.Interop.MicroStationDGN.MsdV7Action.AskUser)

    End Sub


After opening dgn in this way I can see that right ucf is loaded (Workspace-About). But nothing is loaded (features, menus, toolbars, seed files, vba projects). After adding few more variables I completely corrupted all my workspaces and had to reinstall Map and all wokspaces.

3. Change of variable _USTN_USERNAME ' in file "..\config\appl\msgeo.cfg" results that my Map instance created with ApplicationObjectConnector loads as it should. I could programatically always change that file but there is warning that This file should never be changed by users! Any changes to the configuration should be made in one of the files included by that file so I'm not sure where else I can programatically change _USTN_USERNAME variable so that map loads as it should.

Is there any other way of opening/accessing Map with specific user ws or I can somehow improve one of my ways?

  • Hi brenks,

    a few my comment. Please be aware I have not played with OLE Automation and the application object too much, so they are just my guess and memories what I saw and read (so I can be wrong)...

    In my opinion they are some limitations both in Bentley Map and OLE Automation technology:

    Bentley Map: If you want to use a particular workspace, you have to set it when BM starts. It's not possible to change workspace later (and it's the reason why the workflow in point 2 doesn't work and cannot be used). Probably the best way how to start BM with the chosen workspace is to start from shell using proper -wp and -wu arguments.

    OLE Automation: If there are more running instances, as far as I know there is no way how you can choose to what you will connect using ApplicationObjectConnector. I have never read about working reliable solution. This is OLE Automation (which is pretty old technology) issues and Bentley Map cannot break it.

    From a technical point of view I see two possible solutions:

    • To assure there will be no running instances of BM, which means the application has to check for the instances and to close them before an own new instance will be created with a correct workspace. I guess it's the only reliable way how to be sure you will connect to the instance with the right workspace.
    • To change your application from external exe process to BM addin. In this scenario there are no problems with running instances, because addins run in BM instance domain and are not shared between instances. You have to solve two issues: To start BM with the correct workspace and to load the addin, which should be easy admin task. The second issue maybe more complex: The code migration itself. It's not clear what your application does and what external dependencies exist. Does your application communicate with some other processes?

    With regards,

      Jan

  • Hi Jan,

    tnx for an answer.

    1. User must have multiple running instances

    2. Our app has to be standalone exe, we can only export feature data as XML from our app and then we can write features with .Net new addin. But i'm not sure if my colleagues will be satisfied with this solution so i'll fist run more tests with my third solution and make few more conclusions.
  • Unknown said:
    Our app has to be standalone exe, we can only export feature data as XML from our app and then we can write features with .Net new addin.

    I can imagine it can be enhanced in such way a manual interaction process will be not required. It's just a theoretical guess, but you would define own communication pipe (I expect some NET library should make it easy enough) between external exe process and internal addin. So external exe can start BM with defined workspace and automatically started addin. After addin will be started, exe can pass the data to be processed inside BM. When the process will be finished, addin will inform exe about it and will end Bentley Map.

    To implement it in a general way is huge task, but for a particular case it would be not so complex. Maybe just to hand over serialized xml data?

    Regards,

      Jan

  • Addin should send UUID properties of newly created features back to main applicatin. I'll run some tests.
  • Unknown said:
    Addin should send UUID properties of newly created features back to main applicatin.

    Should be no problem to implement.

    Maybe this chart will help you.

    I browsed quickly on Internet and it seems WCF can help you to establish communication between external app and BM addin. There are plenty of examples, e.g. this one for NamedPipe.

    Regards,

      Jan