Scan the elements without open the file.

Dear All,

     I'm using Microstation V8i (Select series 4) with c# language. I'm trying to scan the elements without opening the dgn files. I used the following function, but i observed co-ordinates are not matching with the actual element coordinates. Could anyone correct me, or else if any other method is available to scan elements without opening the dgn files. Thanks in advance

BCOM.DesignFile dgnfile = app.OpenDesignFileForProgram(_strfile);
int modelint = dgnfile.MdlModelRefP();
BCOM.ModelReference modref = app.MdlGetModelReferenceFromModelRefP(modelint);
List<BCOM.Element> _eles = modref.Scan(esc).BuildArrayFromContents().ToList();
foreach (BCOM.Element ele in _eles)
{
    if (!ele.IsLineElement()) continue;
    List<BCOM.Point3d> _lstPts = ele.AsLineElement().GetVertices().ToList();
    //something as per requirement............ :-)
}
dgnfile.Save(); 

Thanks & Regards,

Karthik Keyan

Parents
  • I'm trying to do XXX without opening the dgn files

    Why do people ask that question so often?  There's no magic available here: you can't look inside a file unless you open it.  That's the way computers work.  In the case of MicroStation, you can't scan a DGN file or DGN model unless you open it first.

    The question you may have intended to ask is: "How do I open a DGN file without showing the file to the user?"

    I'm trying to scan the elements

    You don't scan a DGN file to find elements.  Elements live in a DGN model.  A DGN file contains one or more DGN models.  You open a DGN, get a reference to a DGN model, then scan that model for DGN elements.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Jon,

        Thanks for your response. Actually we have to process this tool on thousands of files and while opening each dgn, tool is consuming time. So that we are looking into an alternate process without opening the dgn file. For example: Initially we will open a seed file, then we need to process the input files (i.e. thousands in count) without opening them.

    Thansk & Regards,

    Karthik Keyan

  • Initially we will open a seed file, then we need to process the input files

    How does it help you by opening a seed file first?

    then we need to process the input files (i.e. thousands in count) without opening them

    How do you process a file without opening it?

    MicroStation Init App

    The way to process multiple files without displaying graphics is to write an app. that is designed to run as an MS_INITAPP.  Your code then has the opportunity to open a DGN file before MicroStation starts its graphic engine.  That approach lets you process multiple files without displaying them.  When processing thousands of files, you save a lot of time because MicroStation doesn't have to fire up its graphics engine for each file.

    For the MicroStation V8 generation, the only way to write such an app. is using MDL (C++).  Volker Hüfner hinted at that approach above. VBA doesn't offer the ability to work without graphics.  

     
    Regards, Jon Summers
    LA Solutions

  • Initially we will open a seed file,

    In addition to , using a seed file for this purpose is not a good idea IMHO. The chance this process over thousands of file operations will crash is high, and you may destroy your seed-file.

    Better use an empty DGN of no value.

    Mit freundlichen Grüßen / Best regards
    Volker Hüfner

    |  AB_DATE Engineering  Software   |  ab-date.de  |

  • Hi Karthik,

    you did not answer my question, so I can only add my notes to Jon's and Volker's answers:

    without opening the dgn file

    Please! (interesting everybody have asked you for that, but you have ignored it) do not use "open designfile" formulation and be precise: In MicroStation a design file can be opened in these ways:

    • As a main design file, with one model active, so to say "open as active design file" is fine term.
    • At a background as "work DGN" (MDL terminology used by Volker) or "for program" (terminology used by VBA API). .To say "open a file as workfile" is perfect and everybody will understand what do you mean.

    There is nothing like "open design file", because it's not clear what do you mean and what function/method you use, so you effectively make readers confused (and angry later). And to say "I want to work with design file but do not want to open it" is complete nonsense, as Jon explained already.

    Actually we have to process this tool on thousands of files

    What exactly does it mean? What do you want to do with the files? When the file is opened as a main file, all MicroStation submodules are initialized and full access is available. But when the same design file is opened as work file, the access and API features are limited. So when you need to (only) scan simple elements, it's fine, but things like references, rasters, styles etc. are not available, because work file is just binary stream interpreted as DGN without the complex context of workspace configuration.

    while opening each dgn, tool is consuming time.

    Again, be precise. Did do you any benchmarking? There are plenty of issues with smaller or bigger influence to MicroStation speed, both HW, SW and "environmental" (e.g. is DGN file opened as active including references despite of it's not necessary?).

    You have not answered my question whether your code is MicroStation addin or external application. It's also something that can lead to faster or slower processing. But when the performance is your priority, to use C# through Interop is simply bad choice and native code (MDL / C++) is preferred.

    or else if any other method is available to scan elements

    You also did not answered my question why your code is so weird and you do not use standard ModelReference.Scan method, which I assume should work both for active model and models from work DGN.

    With regards,

      Jan

  • Hi Jan,

    You have not answered my question whether your code is MicroStation addin or external application.

                Sorry for the inconvenience. Actually i used microstation Addin. 

    Actually we have to process this tool on thousands of files

    What exactly does it mean? What do you want to do with the files?

                 I want to collect the line elements vertices from the thousands files  and i generate the report (ex: printing the coordinates value) . 

           Once again i say sorry for i am struggling to convey my problem to you guys. i ll explain my problem here. actually i collect the all micro station DGN files from the provided path and open the each file using "app.OpenDesignFile(FileName)" method  then i collect the Vertices from line elements and generate the report. but my client said this tool taking time to generate report. that's why i am looking "open a file as workfile" method for do the requirement. 

  • I collect the vertices from line elements and generate the report

    So that part of your code is working correctly?

    but my client said this tool taking time to generate report

    Customer has asked you to improve the performance?

    that's why i am looking "open a file as workfile" method

    If all you want is line vertices, then the workfile approach (OpenDesignFileForProgram) should be OK.  As Jan warned you, however, if you want to extract resource information (e.g. line style, text style) or reference attachment information then the workfile is not a good approach.

    However, you're still calling the VBA COM from C# via an InterOp.  That is not efficient: Windows must perform marshaling at the C#/VBA process boundary.  Your customer may remain dissatisfied with the performance of the app. when processing thousands of files.  If that is the case, then you must move to C++ and MDL.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Jan,

                Thanks for the reply.

    If all you want is line vertices, then the workfile approach (OpenDesignFileForProgram) should be OK.

                 Ok,  I have verified with the actual coordinates and  collecting the coordinates there is mismatches coming.. for this volker said the following point.

    You said you had problem with mismatching coordinates. Every DGN came with its own “resolution” and its own global origin. It is your responsibility to recalculate these, by using the information from the Modelreferences.

    If it's the solution please tell me how to recalculate the global origin.

    Thank & Regards,

    Karthik Keyan

  • tell me how to recalculate the global origin

    ModelReference.GlobalOrigin is documented in
    VBA Help
    VBA help .

    Take a look at Units and coordinate systems.

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: Bentley User29 

  • Does C# offer the ability to work without graphics for MicroStation Connect Edition. If so, are there code examples available in BDN?

  • Does C# offer the ability to work without graphics for MicroStation Connect Edition

    Yes: start MicroStation with the -wa switch and write your AddIn to behave accordingly. 

    private void RegisterEventHandlers()
    {
        //ReloadEvent += ReloadEventHandler;
        //UnloadedEvent += UnloadedEventHandler;
        Session.Instance.OnMasterFileStart += OnMasterFileStart;
        //Session.Instance.OnModelRefActivate += OnModelActivate;
        //NewDesignFileEvent += NewDesignFileEventHandler;
    }
    private static void OnMasterFileStart(DgnFile dgnFile)
    {
        string s = null;
        switch (s_YourAddIn.ApplicationType)
        {
            case MdlApplicationType.DesignApp:
                s = $"Opening DGN file '{dgnFile.GetFileName()}' as DGNAPP";
                break;
            case MdlApplicationType.User:
                s = $"Opening DGN file '{dgnFile.GetFileName()}' as USER";
                break;
            case MdlApplicationType.InitApp:
                s = $"Opening DGN file '{dgnFile.GetFileName()}' as INITAPP";
                break;
        }
        //  Enable debug messages in MicroStation's Message Center to see MessageType.Debug
        MessageCenter.Instance.ShowMessage(MessageType.Debug, s, s, MessageAlert.None);  
    }
    
    private YourAddIn (IntPtr mdlDesc) : base(mdlDesc)
    {
        RegisterEventHandlers();
    }

    If you have more questions, please start a new thread about InitApp.

     
    Regards, Jon Summers
    LA Solutions

Reply
  • Does C# offer the ability to work without graphics for MicroStation Connect Edition

    Yes: start MicroStation with the -wa switch and write your AddIn to behave accordingly. 

    private void RegisterEventHandlers()
    {
        //ReloadEvent += ReloadEventHandler;
        //UnloadedEvent += UnloadedEventHandler;
        Session.Instance.OnMasterFileStart += OnMasterFileStart;
        //Session.Instance.OnModelRefActivate += OnModelActivate;
        //NewDesignFileEvent += NewDesignFileEventHandler;
    }
    private static void OnMasterFileStart(DgnFile dgnFile)
    {
        string s = null;
        switch (s_YourAddIn.ApplicationType)
        {
            case MdlApplicationType.DesignApp:
                s = $"Opening DGN file '{dgnFile.GetFileName()}' as DGNAPP";
                break;
            case MdlApplicationType.User:
                s = $"Opening DGN file '{dgnFile.GetFileName()}' as USER";
                break;
            case MdlApplicationType.InitApp:
                s = $"Opening DGN file '{dgnFile.GetFileName()}' as INITAPP";
                break;
        }
        //  Enable debug messages in MicroStation's Message Center to see MessageType.Debug
        MessageCenter.Instance.ShowMessage(MessageType.Debug, s, s, MessageAlert.None);  
    }
    
    private YourAddIn (IntPtr mdlDesc) : base(mdlDesc)
    {
        RegisterEventHandlers();
    }

    If you have more questions, please start a new thread about InitApp.

     
    Regards, Jon Summers
    LA Solutions

Children
No Data