[C# CONNECT] How to make preview image of DGN file?

I would like to know how I can make a preview image of a DGN file upon closing Microstation. Could someone please assist? I am programming in Visual Studio 2017 and C# on .Net Framework 4.6.1.

Parents
  • How I can make a preview image?

    Searching for thumbnail may prove more profitable.  If you can't find anything in the MstnPlatformNet or DgnPlatformNet docs, then look in the MicroStationAPI.

     
    Regards, Jon Summers
    LA Solutions

  • Thanks for your answer, Jon. I need to also say that the DGN file will need to have preview images taken from each side upon closing. I do have source code, but it's not working correctly. May I send the source code to you to inspect and give some advise?

  • I just want to know which API/method the "Utilities -> Save Multiple (Render multiple image files)" menu option calls

    No idea!  But you may be able to glean clues by recording a VBA macro.  Record a VBA macro while exercising the Save Multiple Images Dialog.  Twiddle the settings to ensure something changes and is possibly recorded.  Use the VBA IDE to examine the recording.    The recording may reveal app names and app variables that you modified.

     
    Regards, Jon Summers
    LA Solutions

  • Hi ,

    IPrinter API

    Another approach, for real programmers, is the IPrinter interface.  Unfortunately, there are no examples.

    FYI. Yes and No.  Yes currently there are no direct .NET C# (.cs) examples provided in the SDK.  However a .NET C++/CLI (.cpp) .NET example is provided under: examples\Printing\PrintSet\ReadMe.txt.

    The operations performed in this example likely transition and work equally well in a respective C# .NET project referencing the Print API assemblies:

    Assemblies\Bentley.PrintAPI.dll
    Assemblies\Bentley.PrintDefinitions.dll
    Assemblies\Bentley.PrintEngine.dll
    Assemblies\Bentley.PrinterConfigurationEditor.dll
    Assemblies\Bentley.PrintFoundation.dll
    Assemblies\Bentley.PrintHandlers.dll
    Assemblies\Bentley.PrintManager.dll
    Assemblies\Bentley.PrintOrganizer.dll

    HTH,
    Bob 



  • Hi,

    What was confirmed is that the sofware that I need to create will be doing exactly what the "Utilities -> Save Multiple (Render multiple image files) menu option in the ribbon currently does.

    there is no API for this functionality, maybe key-ins are available.

    In fact, you do the topic more complicated, because your original question was about "preview", whereas the mentioned tool allows (and is used often) to start full rendering.

    Whenever a user closes a DGN file or the Microstation application, then this add-in needs to render images of all the 8 views of the DGN.

    Really? I cannot imagine how it can work, because to render image takes usually minutes (tens or hundreds of minutes). Even when only view preview (quick rendering processed by graphic card based on display style setting) will be done, it increase closing time substantially in my opinion. But I do not know the context like how complex your models are etc.

    I just want to know which API/method the "Utilities -> Save Multiple (Render multiple image files)" menu option calls to do this?

    It's misunderstanding what MicroStation API is for. It does not (some exceptions exist) there to access user tools, but to access MicroStation engine functionality. So similarly as there is no API for SmartLine tool, but you can implement own tool with the same or similar functionality, there is also no API to access Save Multiple images tool, but you can use API to create own tool.

    If you question is not about rendering (done by Luxology engine), but about capturing view content as they are displayed in MicroStation GUI, it can be done I guess.

    I think you should use C++ API, not NET, because C++ API is better suited and recommended for tight integration (monitor and react on events like design file closing) and also function to capture a view content is available there. NET API does not provide enough functionality (limited monitoring, no public method to capture view content...).

    Regards,

      Jan

  • Thank you, Bob. I appreciate your assistance. I will work on this and let you know if all went well. Go well.

  • Off topic, but just to clarify: the VBA "print" additions in MS CE were limited to replacing the functionality of the removed MS BASIC macro feature that was an obscure, rarely-used feature of the MS pen table application.  As such, the VBA PrintManager is focused entirely on element substitution and resymbolization -- in effect a pen table / design script in Visual Basic.  It doesn't offer any methods that can be used to initiate printing such as the print keyins or the .NET and native code Print APIs.

    Also, the IPrinter (both native code and .NET variants) interface is just a part of the overall Print API.  IPrinter is designed to encapsulate the properties of a printer driver configuration (.pltcfg) file, and is not a "top level" class.  When I was last involved, the MS CE SDK did include examples on how to drive the printing system directly using either native code or .NET.  I'd be surprised if they were removed (look for PrintDesc and PrintSet examples).  However, VBA can only be used to sent print keyins (and in that regard is no different than V8i).

          
    .

  • Thank you for your answer, Jan. What I need to do is this:

    I am trying to convert my saved view to an image. You can use the Save Multiple Images function in MicroStation CONNECT to do this but i would like to automate this in code. Is there any code working for this function. Has anybody done something like this?

    I unfortunately do not have any experience in C++, so that is why I am using C#.net. I am keen on learning C++, but I do not have enough time to learn the language in order to fulfill this task.

  • Hi Clive,

    What I need to do is this:

    I think (and confirmed earlier) you explained your needs well enough, no reason to repeat it again.

    Is there any code working for this function

    In my opinion it was answered already: MicroStation APIs provide access to features, not to end user tools (a few, but quite rare, exceptions exist). The primary focus of APIs is to allow 3rd party developers to implement own user tools.

    Consequently, no API is available to access Save multiple images tool, but you can use (quite low level) API to capture an image content.

    Has anybody done something like this?

    Was answered already too, plus discussed many times in the past (did you search this web for this topic?).

    This need is quite rare /but you can find similar discussion) and as far as I remember, it always ended at C functions (e.g the one Yongan.Fu mentioned).

    I unfortunately do not have any experience in C++, so that is why I am using C#.net.

    I have heard the same sentence so often. And even when I understand it (and I have used it in different language/technology combinations also ;-), one from the core rules in software development is completely opposite: Analyze a problem, find the best tool to solve it (technology, language, framework...), use it. When the result does not fit with existing knowledge, it's not problem of the language or API (and we have to learn it or to hire somebody with required knowledge).

    I am keen on learning C++, but I do not have enough time to learn the language in order to fulfill this task.

    I do not know any develop who has enough time for learning. That's the reality :-(

    You should be aware C++ is primary MicroStation API, so often you will find that some functionality is not available in NET API and using C++ is required. In these cases, to use e.g. C++/CLI (which is one from the most weird languages invented by Microsoft ;-) is recommended way to implement own wrapper (bridge) to NET.

    But in the discussed case, P/Invoke (mentioned in the discussion already) seems to be enough, because mdlImage_ function mentioned by Yongan.Fu is exported in ustation.dll. To be able to use P/Invoke is one from important skills in NET development, because NET does not cover everything and to call e.g. Win32 API is required from time to time. Microsoft is aware of that and P/Invoke is available (and documented and discussed) from NET Framework 1.0.

    So it's the place where you should start: Try to use this function in your code. Next challenge will be how to interpret received byte array.

    With regards,

      Jan

  • Has anybody done something like this?

    Yes, many years ago.  Customer wanted a mechanism to cut a DGN file into tiles to match map tiles from a mapping agency.  In those days I used the MDL functions mentioned earlier in this thread.  With CONNECT, things don't seem to have advanced much, either in the MicroStationAPI or with the availability of wrapper methods for .NET.

    I do not have enough time to learn the [C++] language

    Well, that's your decision.  You have found that .NET is wanting, for your particular requirements.  You can wait for the .NET APIs to catch up with C++, or learn C++.  Given that MicroStation CONNECT has been around for at least five years, that would have been sufficent time to start learning.  Continuing to wait for .NET wrappers may not lead to a deterministic outcome.

     
    Regards, Jon Summers
    LA Solutions

  • Thank you for your insightful answer, Jan. I do apologize for repeating myself as I thought that I was explaining myself incorrectly or that I was not clear. Anyhow, C++ is definitely the more prevalent language when it comes to integrating with the Bentley environment and I will endeavor to learn the language as I go along. Thank you once again for your assistance and patience up to now. I will mark Yongan's answer as the one that helped. 

  • Thank you for your answers, Jon. Much appreciated. I think that the best route to take is to carry on with C# as I am and then learn C++ as I go along. All the best.

Reply Children
No Data