[CONNECT C#] switch activedgnfile

Been searching the help docs and can't seem to find how to switch the active dgn file to a new file using the .net apis.

I see the Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile. but I have searched through all the session members and don't see one for switching the master/active dgn file.

surely this has to be in there im just missing it.

Can any one help me out here?

that's the correct way to switch the master/active dgn file to a different file?

I have been using the DgnDocument, fileowner, loadgnfile methods to programmically interact with dgnfile but that loads the files in the background.

I feel like I have wasted a lot of time trying to figure out how to do something so simple.

JD 

Parents Reply Children
  • Hello Robert,

    I must say I was pretty chocked that Connect c# doesn't have a method to activate and display a model. Coming from VBA that seems to be one of the most elementary functions. But it is what it is and I am waiting for a full integration of this functionality.

    I have been looking at ways to use the "DllImport" for the "mdlModelRef_activateAndDisplay" function. I've found the start of it beeing:

    [DllImport ("ustation.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
    internal static extern StatusInt mdlModelRef_activateAndDisplay (IntPtr newModelRef);

    But honestly, I don't have a clue whats next. Can you provide me with a few lines to explain how to use the old mdl function?

    Kind regards.

    Wim A.

    Wim Aerts

    4D select nv

  • I know your asking about the activateAndDisplay call but there is also the COM api.

    which is pretty simple

     
    Bentley.Interop.MicroStationDGN.Application MSApp = Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp;
    Bentley.Interop.MicroStationDGN.DesignFile curfile2 = MSApp.ActiveDesignFile;
    curfile2.Models[selSheet.propModelName].Activate();

    or if you need to open it the file first switch this line in

    Bentley.Interop.MicroStationDGN.DesignFile curfile2 = MSApp.OpenDesignFile(selSheet.propLocalPath, false);

    just grabbed that from my code so the model name is coming from elsewhere. it should show you how to use it.This is what I have done in place of not being able to use .NET stuff. it does suck when most of the code is using .net stuff and then to come across something and need to use a COM function and having to manage the COM objects with the .net objects

    Also for future references you should submit a new question

  • Hallo John,

    You are a lifesaver. This piece of code is exactly what I need.

    I should have started a new question. But this discussion got so close to solving my problem I couldn't help myself. I will remember this for the future.

    Thank you and kind regards.

    Wim A.

    Wim Aerts

    4D select nv

  • your welcome,

    if a post helps you, you can hit the this helped me button on the post and/or vote it up