[v8i MDL] How can I export the DGN default model to an image file without open the DGN?

Hi,

I'm programming with pure MDL (it's a huge application not migrated yet to C++) over MicroStation and Bentley Map SS4.

I need to create programmatically an image file (JPEG, BMP or similar) from the default model of a DGN, but without open the DGN with mdlSystem_newDesignFile.

I know how to to do it when the DGN is open (capturing the screen, printing to JPEG plot driver, etc), but now I need to do ii in that way.

It doesn't matter if the file image is small in size or the quality is not optimal, because I need the image to embed it in a sheet model for plotting.

I've tried the following (via thumbnail) and I can get the JPEG file, but the contents of this file is incorrect (see image below).

 

                   int estat;
                    char fileName[MAXFILELENGTH], fJpg[MAXFILELENGTH];
                    byte *imageBufferP=NULL;
                    int imageSize;
                    byte redPalette[256], grnPalette[256], bluPalette[256];
                    int paletteSize, colorMode;
                    Point2d size;

                    strcpy (fileName, "C:\\dgn\\MapIndex.dgn");
                    strcpy (fJpg, "C:\\dgn\\MapIndex.jpg");
 
                    // Open the thumbnail of the selected dgn.
                    estat = mdlSystem_openFileThumbnail (NULL, NULL, NULL, NULL, fileName, &imageBufferP, &imageSize);

                    if (estat == SUCCESS)

                    {
                      //
                      mdlImage_getExportSupport (&colorMode, NULL, NULL, NULL, NULL, NULL, IMAGEFILE_JPEG);

                      mdlImage_getScreenPalette (redPalette, grnPalette, bluPalette, &paletteSize, statedata.current.screenNumber);

                      size.x = 300;
                      size.y = 300;

                      mdlImage_createFileFromBuffer (fJpg, IMAGEFILE_JPEG, colorMode, &size, imageBufferP, IMAGEFORMAT_BitMap, NULL, NULL, NULL, paletteSize, 0, NULL);
 
                     // Clear buffer.
                     if (imageBufferP)
                     {
                        mdlSystem_freeFileThumbnail (&imageBufferP);
                     }

                  }

 

Please, any hint to solve this question?

Thanks a lot for your help.

Toni

  • Hi Hola,

    You can try the following code, and I hope it will help you.

    using BMI = Bentley.MicroStation.InteropServices;
    using BIMDgn = Bentley.Interop.MicroStationDGN;

    BIMDgn.Application app = BMI.Utilities.ComApp;
    BIMDgn.Point3d Origin = default(BIMDgn.Point3d);
    Origin.X = (Origin.Y = (Origin.Z = 0.0));
    BIMDgn.Point3d Scale = default(BIMDgn.Point3d);
    Scale.X = (Scale.Y = (Scale.Z = 1.0));
    app.AttachCellLibrary(cellLibraryPath,  BIMDgn.MsdConversionMode.Prompt); // cellLibraryPath is DGN FileName

    Matrix3d matrix3d = app.Matrix3dIdentity(); // you can change  matrix3d to change image display
    BIMDgn.CellElement cellElement = app.CreateCellElement2(cellName, ref Origin, ref Scale, false, ref matrix3d); // cellName is Default Model Name
    if (cellElement != null)
    {
    cellElement.DrawToFile("C:\\image.jpg", 100, 100, false);
    }

  • Hi Jon and Jan,

    Thanks a lot, one more time, for your wise replies to my question.

    After reading your replies I decided to change my first approach. Now I'm reading the DGN via WorkDgn functions and I'm scaling and translating all its elements to fit them into a rectangle in the sheet model to plot, without using any kind of image files. Now I have what I wanted, but in a different way.

    Thanks for your help.

    Regards,

    Toni

  • Thumbnail

    An approach you can consider, that avoids MDL completely, is the Win32 API.  A V8 DGN file implements Microsoft's Alternate Data Streams technology, and the thumbnail image is stored separately from the DGN contents.

    Here are some references …

     
    Regards, Jon Summers
    LA Solutions

  • Hi Toni,

    to extend Jon's answer: I think there are three possible ways (a spolier: only full opening works ;-) when talking about converting DGN content to image:

    • Thumbnail as the approach you tried. A problem I see here is that it's not ensured the thumbnail represents default model content. How and when the thumbnail is created can be configured, by default it's a content of View 1 content when Save Settings (Ctrl+F) is activated.  So it can contain black background only, content of another model etc. Or the thumbnail would not be available at all. So to use the thumbnail is not good approach.
    • To open DGN file as work DGN (open for program). Such file can is opened at background, but the problem is that this access does not provide the same functionality as opening DGN as active file (not all MicroStation module are activated and APIs available), so maybe you would be able to create a capture of the file content, but probably a lot of own code is required to receive acceptable result.
    • To open DGN file "normally" as active design file. I agree with Jon, this is the right solution.

    With regards,

      Jan

  • How can I export ... file without opening the file?

    In general, the answer is: You can't.  Whatever the file — DGN or Word or Excel or something else — you must open the file to be able to read its contents.

    I'm programming with pure MDL

    The question you may be asking is: How do I open a DGN file and process it without showing any graphics to the user?  That is, you want to batch-process a DGN file without opening a graphics window.

    You can do that in MDL by writing an MS_INITAPP program.  The key is to start your MDL app. using the -wa command line switch.  Write your MdlMain() function to detect that you have been started as an MS_INITAPP program.   Your code will run in MicroStation, but MicroStation will not display graphics unless you use mdlSystem_enterGraphics().

    You must nevertheless use mdlSystem_newDesignFile() to open a DGN file!  I believe that there is an example of an MS_INITAPP in the SDK examples.

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: Toni P.