[CONNECT C# Standalone] how to start an instance of MS and set the workspace and workset?

i found this post..

https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/179678/how-to-change-workspace-and-workset-to-match-file

but i don't think any of that is accessible for stand alone apps. correct me if im wrong

So the real problem is i have a stand alone app for creating a new workset. We tried to use the out of the box functionality to create a workset but it just does not offer things we need. like logic for which seed files should be added to the workset that already have the correct GCS set for that location of the project and other things..but back to the problem..

I can set up of the workset cfg file, and the workset folder template and put in the needed files. but i need to update the seed dgn files to be "stamped" with the workspace and workset and i dont see a way to do that. Which when starting up an MS app instance you would think one of the main things anyone would need to be able to do is set the workspace and workset to use. after that i can just use a keyin to associate the file with the active workspace/workset.

any one got any idea how to do this??

im temped to do get the users pref file and set the _USTN_WORKSETNAME and )USTN_WORKSPACENAME vars before launching the app so i know i get that as the active workspace/workset. but thats not really the route i want to go.

Parents
  • Hi John,

    Which when starting up an MS app instance

    Do you mean to start MicroStation through COM Interop, which I guess is like to ask Windows to start registered application accordingly to configuration in Windows registry, or to start MicroStation explicitely (similarly to use Windows shell)?

    Regards,

      Jan

  • I have a c# wpf app. I'm gong to late bind ..something like this...

    dynamic objMS;
    objMS = Activator.CreateInstance(Type.GetTypeFromProgID("MicroStationDGN.Application"));

    but I normally early bind at first to help me write everything correctly then switch it to late binding. so for now I'm adding a reference to MicroStationDGN. and starting the instance like this...

    MicroStationDGN.Application MSapp = new MicroStationDGN.Application();

    So I believe that this is COM... but if there is another way I'm open to it.

  • but if there is another way I'm open to it.

    I would think about to start MicroStation process explicitly and do not let Windows to start it for you, which is what happens when you create application object instance.

    I have not tried it, it's an idea only:

    • When background proces is started, in MicroStation case it means Windows calls "microstation.exe -automation" (for CE, unfortunately there is know defect that dummy dialog is opened in such case) or "ustation.exe -automation (for V8, where nothin is displayed in GUI).
    • I assume standard arguments can be used with -automation parameters as well.
    • COM Interop by default prefer to use existing process than to start a new one.

    So my idea is to start MicroStation as new process explicitly, not through Automation object, using syntax

    microstation.exe -automation -WK<workspace> -WW<workset>

    and to attach to this proces in the next step.

    With regards,

      Jan

  • that's a good idea but how would I attach to the process.

    each instance of Microstation does not get added to running object table. so you can only get the first instance and nothing else. I do have an enhancement to add each instance to the ROT as all major applications do this (Autocadd, office projects..) and was told it would be added but no timeline :/

    just in general it would nice if Bentley had a tool where we could just specify a worksetfolder and have it go through and fix the stamp on all the dgn files within to be set to a specified workspace/workset...

    I need something more then a key in that just used the active workset I need to be able to specify the name of the workspace and workset in the key in..then I wouldn't have to worry about what my active workspace/workset is.

  • each instance of Microstation does not get added to running object table.

    I think it has been discussed many times and Bentley have not implemented it yet ... and I think it cannot be implemented by yourself (but my knowledge of how Windows manage running tasks is quite limited).

    My feeling from all discussions I have read is that when you decide to use COM Interop and Automation object, your flexibility is limited and your code will be attached to the first MicroStation task that will be found ... which is one from reasons I have never used this option in any commercial project.

    An alternative approach I have seen in some solutions is to write small initapp code in native code and to communicate with external software using other IPC method than is COM (e.g. memory pipe).

    With regards,

      Jan

  • so I'm basically left with warning the user that all running instances will be closed.. then kill all the running tasks.. then open and pass workspace and workset. then go and get that COM object and then pass the keyin to associate it. all just so I can 'stamp' a dgn file with a certain workspace/workset.

    I'm putting in an enhancement request to have a keyin to 'stamp' the file to a specified workspace/workset.

  • Jan,

    when I try to start a process and pass the workspace, workset and file path it will not work if I also pass the -automation arg as well.

    if I remove the -automation then I get the This file is not part of a WorkSet What do you want to do? prompt. Is there something else Ineed to pass in order to start the process without getting any pop up messages??

     if I leave the -automation arg the MS object I get doesn't have an active file. I can only assume that the -automation is suppressing the No WorkSet Alert message but its waiting for a response to open the file??

    here is my testing code

    Process P = new Process();
        P.StartInfo.FileName = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\MicroStation CONNECT Edition\MicroStation CONNECT Edition\MicroStation CONNECT Edition.lnk";
        P.StartInfo.Arguments = "-automation -WKOHDOT -WWtest " + "\"X:\\CADDServices\\CONNECT_Config\\WorkSpaces\\OHDOT\\WorkSets\\test\\990-WorkSetStandards\\Seed\\OHDOT_DrawingSeed2d.dgn\"";
        P.Start();
        
        dynamic objMS2 = (dynamic)Marshal.GetActiveObject("MicroStationDGN.Application");
        string name = objMS2.ActiveDesignFile.Name;

  • if I leave the -automation arg the MS object

    If you want control over the way MicroStation starts then use its command-line switches.  Forget VBA and COM (the ‑automation switch), which restrict you in various ways.

    I can only assume that the -automation is

    That's all any of us can do: make assumptions.  And assumptions in software development tend to lead up blind alleys.

    Switches -wc, -wk, -ww, -wr and -s give you plenty of flexibility in the way that MicroStation starts.  What you're looking for is a way to suppress, or respond automatically to, those modal dialogs about adding the DGN file to a workset.

     
    Regards, Jon Summers
    LA Solutions

  • I'm not seeing how any of those switches will let me open the dng silently. There has to be a way to launch microstation and not get the stupid workspace/workset dialog box. all I see is that I can set the workspace and workset.

    Am I missing something?

  • Hi John,

    There has to be a way to launch microstation and not get the stupid workspace/workset dialog box.

    I think there is no such way or switch available. I remember it has been discussed several times (not sure whether in MicroStation or Product Administration forum) that it's not possible to switch of workspace identification mechanism. There are vaiables available (MS_WORKSETMISMATCH_ALERT_EXCLUDE_VARS_ALLLEVELS  and MS_WORKSETMISMATCH_ALERT_EXCLUDE_VARS_WORKSPACELEVEL) that can be used to specify folder to be ignored (not checkd for the mismatch, but they do not allow to switch off the functionality completely.

    With regards,

      Jan

  • There has to be a way to launch microstation

    The traditional way of launching MicroStation silently was by writing an InitApp.  An InitApp is written in MDL/C++ and is started either by using the -wa switch at launch or by including it in the list of apps. in the MS_INITAPPS configuration variable.

    An InitApp has to be written in a special way, so that it knows it was started thus.  In particular, it must call function mdlSystem_enterGraphics() at some point if it wants the user to see any views.  Optionally, the InitApp author can call mdlSystem_enterGraphicsExtended() to choose whether or not to show any dialogs.

    I've written InitApps for MicroStation V8 but have had no reason yet to write one for CONNECT.  Whether that's possible in .NET is unknown. It's never been possible using VBA.

    [Edit July 2021] You can write an InitApp using .NET.  The MstnPlatformNet API supplies the AddIn class, from which your AddIn inherits.  The AddIn class has property ApplicationType, which tells you whether your AddIn was started by the user, as a DesignApp or an InitApp.

     
    Regards, Jon Summers
    LA Solutions

  • those variables don't appear to do anything. I have tried setting them to a file directly, tried a folder path. I always get the dialog.

    is there a trick to setting these variables??

Reply Children
No Data