[Connect v17 C#] Issues With Key Ins in Addin Program Run From MS_DGNAPPS

Hi everyone, I hope someone can help me with the following issue:
I wrote a simple C# addin program that I intend to run automatically, via the MS_DGNAPPS config variable, when Connect is started and a dgn loaded. This addin program just needs to submit a few key in commands such as DMSG CLOSEDIALOG -79 to close the element selector dialog box and db=fakeu/fakepw@fakealias to connect the dgn file to our database.

Since this addin is loaded automatically via MS_DGNAPPS, I first put the session keyin calls in the addin's run method, which is run after the addin is loaded. The key ins didn't seem to take even though there were no errors. The element selector was open and not closed after the dgn file was fully loaded.

I figured that maybe these keyins were being submitted too early in the process of loading the dgn. I knew the addin class has event handlers, so I just assumed I would be able to find one for when the dgn file is fully loaded and I could just add the key ins there. I checked the documentation but was surprised to find out that no such event handler exists, as far as I can tell.

I tried many other event handlers including CmdWindowOpenEventHandler, ModelChangedEvent, BeforeNewDesignFileEvent etc.. But the behavior was no different than when I had the keyins in the run method.

When I used the NewDesignFileEvent event, it showed me that my theory was correct: Unlike the other events that I tried, with this event the element selector is visible on the screen when this event is fired. I could then see that when my code runs the element selector dialog does disappear, but for some reason Connect then shows the element selector dialog after it leaves my event handler while it finishes loading the dgn.

Note as test, I put my key ins into the LevelChangeEvent eventhandler in the addin class and then manually changed the level after the dgn file was fully loaded and my key ins worked perfectly, so I know my code is good. The issue is just the point the the process that my code is running when Connect is loading a dgn that is the issue.

Questions:
Am I missing something or is there an eventhandler for the addin class that fires when Connect fully loads a dgn file? This seems like such a basic requirement.

Is there possibly another way to automatically fire a key in command after Connect has fully loaded a dgn file? We do not want our users to have to manually key in commands.

Parents
  • Hi Brenden,

    in addition to Yongan's answer:

    I checked the documentation but was surprised to find out that no such event handler exists, as far as I can tell.

    Be aware NET API wraps C++ world, but not completely. So when you are interested in detail monitoring of MicroStation engine and related events, in some cases only C++ API provides the right tools. Also, in some situations more solutions / approaches exist.

    This addin program just needs to submit a few key in commands

    In my opinion there are two separate topics:

    • When to interact with MicroStation (what is the event that should be monitored and whether it can be done in NET)
    • What is the best way to interact with MicroStation (to use key-ins is simple, but not always the best)
    When I used the NewDesignFileEvent event

    I guess this addin event wraps SystemFunc_NewDesignFile system hook. As described in C++ API help (which should always be checked): UserFunction called when a new design file is opened. So it is probably fired when "it happens", not when "it is finished".

    Am I missing something or is there an eventhandler for the addin class that fires when Connect fully loads a dgn file? This seems like such a basic requirement.

    I think two solutions can be tried:

    To try Session.OnMasterFileStart event. As described in Session class documentation, it is fired when a file become "master file" and the session starts.

    If it is not enough (e.g. OnMasterFileStart is still "too early event"), you can register for the same (or any other available, informing that file or model changed) and when it happens, to register for EnterIdleEvent. It is available in Interop (and in C++), but not in new NET API. It is fired when MicroStation processed everything in input queue, so when monitored after the model is opened, it can be interpreted "MicroStation finished the loading process". Of course, application must unregister immediately and wait for next file/model open event.

    With regards,

      Jan

  • Jan,

    Unfortunately, the OnMasterFileStart session event happens too early also.  I'm trying to subscript to the EnterIdleEvent event via InputCallback_SetEnterIdleFunction in c++.  Thus far it is not working, in that my event handler in c# is not firing.

Reply Children