MicroStation Connect Edition object

Greetings,

I am new to MicroStation Connect Edition . I am trying to change some old VB code to c# connect edition

I need to do following in c#

/********************************************/

Set oDGN = oMS.OpenDesignFile(strOpen, True)
   Set oView = oDGN.Views(1)
            Set oElScan = New ElementScanCriteria
            oElScan.ExcludeAllColors
 
 
    oElScan.IncludeColor 5
            oElScan.IncludeColor 6
 
  oElScan.ExcludeAllLevels
  oElScan.IncludeLevel oLev
 
Dim Point As Point3d, PVoid As Point3d
 
 
Point.X = ((1034.3 - 1000) * dblMult) + 1000
                            Point.Y = ((1000.9 - 1000) * dblMult) + 1000
                            Point.z = 0#
 
oMS.CadInputQueue.SendCommand "CHOOSE ELEMENT "
    oMS.CommandState.SetLocateCursor
Set oElement = oMS.CommandState.LocateElement(Point, oView, True)
/****************************/
I started as follows 
ApplicationObjectConnector connector = new ApplicationObjectConnectorClass();
Application mstnApp = connector.Application;
but not sure how to set leel and color and Point3d... 
Please help .Any assistance will be highly appreciated .
Regards
Sunil
Parents
  • I am new to MicroStation Connect Edition. I need to do following in C#

    MicroStation CONNECT has a first-class .NET API.  You must download the MicroStation SDK to obtain that API and its documentation.

    But, as Jan asks, you should tell us what you want to achieve.  What does your program do?

     
    Regards, Jon Summers
    LA Solutions

  • I am trying to do following in external application (Window Console application)

    a. Check if I am able to open a DGN File
    b. Retrieve File Name ,Class name and it's Level
    c. Change Color code externally

    to accomplish this task ,I have following code


    using System;
    using System.Collections.Generic;
    using Bentley.Interop.MicroStationDGN;

    namespace BentlyDrawingsManager.ConnectEditionBusiness
    {
    /// <summary>
    ///
    /// </summary>
    public class ConnectEditionAppBusiness
    {
    public void GetPlist(IList<string> lstInputDGNFiles)
    {

    ApplicationObjectConnector _connector = new ApplicationObjectConnectorClass();
    Application mstn = _connector.Application;
    int iLot = mstn.ActiveSettings.LocateTolerance;
    ///Open File in Read only Mode
    mstn.OpenDesignFile(@"C:\Users\Test\Documents\DGNFiles\0750SS2Z.DGN",true);

    //AS SCAN CRITERIA OUT SIDE AS BUG ,WANT CREATE A CLASS LIB FOR IT WITH IN MICROSTATION
    ElementScanCriteria escan = new mstn ElementScanCriteria
    //RETRIEVE Color Information
    //REtrieve Level
    //CLOSE _connector.


    }
    }
    }

    I am getting error while creating ApplicationObjectConnectorClass while creating object as

    (see attached file) Can not be mebedded .Use the application Interface instead

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Bentley.Interop.MicroStationDGN;
     
    namespace BentlyDrawingsManager.ConnectEditionBusiness
    {
        /// <summary>
        /// 
        /// </summary>
        public class ConnectEditionAppBusiness
        {
            public void GetPlist(IList<string> lstInputDGNFiles)
            {
                
                ApplicationObjectConnector _connector = new ApplicationObjectConnectorClass();
                Application mstn = _connector.Application;
                int iLot = mstn.ActiveSettings.LocateTolerance;
                ///Open File in Read only Mode 
                mstn.OpenDesignFile(@"C:\Users\Test\Documents\DGNFiles\0750SS2Z.DGN",true);
            }
        }
    }

  • No reason to reference Bentley.General1.0 and Bentley.MicroStation.Interfaces.1.0. If I remember right, only Bentley.Interop.MicroStationDGN assembly is necessary.

    I think it's not necessary to specify Reference path in Project configuration, because assemblies are referenced explicitly with complete paths.

    How is your project configured? Is it 64bit?

    Regards,

      Jan

  • I think it's not necessary to specify Reference path in Project configuration, because assemblies are referenced explicitly with complete paths.

    I removed reference settings

    How is your project configured? Is it 64bit?

    Any CPU Preferred 32 Bit    

     

  • Any CPU Preferred 32 Bit 

    MicroStation CE is 64bit application and as you can see, when you will look into Interop assembly, it's also 64bit. So your project should be 64bit.

    In fact, there is probably no serious reason today why to build anything 32bit or AnyCPU. Only when old 32bit apps have to be supported.

    Regards,

      Jan

  • Thank you Jan

    It worked for me . Many Thanks 

    I am able to open DGN File . Working on Scan Criteria .Thank you once again

    • but in Interop, because you access MicroStation from external process, you have to create is specifically in MicroStation. See VBA ElementScanCriteria object documentation for details.

      • Does it mean That I need to create a class lib with MicroStation under C:\Program Files\Bentley\MicroStation CONNECT Edition\MicroStation\Mdlapps
    • for scan criteria
  • Hi,

    please use "quoting feature": Select a text in answer and click on Quote to include it in your post.

    Does it mean That I need to create a class lib with MicroStation

    No, why?

    The only what, accordingly to VBA documentation, is required, is to do not use new to create instance, but to call CreateObjectInMicroStation method. These things are not specific to MicroStation, but have to be solved (in different ways) by any inter-process application.

    Regards,

      Jan

  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Bentley.Interop.MicroStationDGN;
    
    namespace ConnectEditionTestApplication
    {
        class Program
        {
            static void Main(string[] args)
            {
                ApplicationObjectConnector _connector = new   ApplicationObjectConnectorClass();
                Application mstn = _connector.Application;
                int iLot = mstn.ActiveSettings.LocateTolerance;
                ///Open File in Read only Mode 
                var Odgn = mstn.OpenDesignFile(@"C:\Users\Documents\DGNFiles\0750SS2Z.DGN", true);
                var oView = Odgn.Views[1];
                ElementScanCriteria scanCriteria = new ElementScanCriteriaClass();
                scanCriteria.ExcludeAllColors();
                scanCriteria.IncludeColor(5);
                scanCriteria.IncludeColor(6);
                scanCriteria.ExcludeAllLevels();
                for (int i = 1; i <=63; i++)
                {
                    Level oLev = mstn.ActiveDesignFile.Levels.FindByNumber(i);
                    if(oLev!=null)
                    scanCriteria.IncludeLevel(oLev);
                }
                if (mstn.ActiveSettings.LevelLockEnabled)
                {
                    mstn.ActiveSettings.LevelLockEnabled = false;
                   
                }
               
            }
        }
    }
    

    Receiving  error while trying to open DGN File

    This is opening physical Connect edition screen instead of process (Err_2.jpg) 

    Unexpected  error! exception Code:3762504530 in dll 'Bentley.RibbonView,Version=1.0.0.0,Culture=neutral,publicToken =9bfed12b64a9b7df;

     

    Please let me know if I am ding something wrong. 

  • This is opening physical Connect edition screen instead of process (Err_2.jpg) 

    Well, what about to read some documentation (e.g. Connecting to MicroStation from a Separate Process chapter in MicroStation VBA help) and search this web (because Interop was discussed so many times) and to use Internet (because to use Interop is common topic)?

    The code does exactly what you wrote: It starts the process. It's visible because you do not set application to be hidden.

    Receiving  error while trying to open DGN File

    I do not think the problem is in opening the file, but maybe somewhere else. But it's hard to say anything more without knowing detail info about configuration, workspace and make some debugging including stack inspection etc.

    Please let me know if I am ding something wrong. 

    A lot of things.

    You do not care to even read documentation (especially MicroStation VBA) and to study existing discussions:

    As I wrote earlier already (more times), ElementScanCriteria class instance has to be created in a different way. Actually, why to answer when you do not bother to follow the advises?

    Why do you define ElementScanCriteria when you do not use it?

    To iterate levels using numbers 1..63 is completely wrong. This concept was valid in DGN V7 era many years ago.

    With regards,

      Jan

  • Thank you Jan  for the answer .

    "You do not care to even read documentation (especially MicroStation VBA) and to study existing discussions:"

    "As I wrote earlier already (more times), ElementScanCriteria class instance has to be created in a different way. Actually, why to answer when you do not bother to follow the advises?"

    "To iterate levels using numbers 1..63 is completely wrong. This concept was valid in DGN V7 era many years ago."

    I am looking into it and as I looked into element scan criteria and got confused with current organization's existing code (as you can see loop through 1-63) and hence i bring this issue. Really sorry for it and I do not mean to bring unnecessary thing .

    It might be initially challenging ,But I wll look if I can do thing as per advice .

    Thanks again for your support.

    Regards

    Sunil 

  • Hi,

    I am looking into it

    It looks like you not.

    There are quite good documentation of MicroStation VBA available, delivered with MicroStation installation. It contains plenty of examples directly inside chm file, plus some extra mvba files are part of MicroStation installation too.

    Also, because Interop was standard NET API in V8i, and VBA is used often by MicroStation users, searching in this forum will give enormous code snippets and ideas how to solve individual topics (even when there are minor differences between how API is represented in VBA (COM) and Interop (NET)).

    Official documentation of Interop API is in MSTNPlatformNET documentation, which is part of MicroStation SDK, but from my perspective, it's not as useful as MicroStation VBA help.

    There is also a great list of VBA sources available, created by Robert Hook.

    But I wll look if I can do thing as per advice

    If you want to use Interop from external application, you have to learn MicroStation VBA (at least to understand API  well). Otherwise, it's like to try to drive a car without any training - in programming, you will probably not kill yourself, but your project for sure.

    Regards,

      Jan

Reply
  • Hi,

    I am looking into it

    It looks like you not.

    There are quite good documentation of MicroStation VBA available, delivered with MicroStation installation. It contains plenty of examples directly inside chm file, plus some extra mvba files are part of MicroStation installation too.

    Also, because Interop was standard NET API in V8i, and VBA is used often by MicroStation users, searching in this forum will give enormous code snippets and ideas how to solve individual topics (even when there are minor differences between how API is represented in VBA (COM) and Interop (NET)).

    Official documentation of Interop API is in MSTNPlatformNET documentation, which is part of MicroStation SDK, but from my perspective, it's not as useful as MicroStation VBA help.

    There is also a great list of VBA sources available, created by Robert Hook.

    But I wll look if I can do thing as per advice

    If you want to use Interop from external application, you have to learn MicroStation VBA (at least to understand API  well). Otherwise, it's like to try to drive a car without any training - in programming, you will probably not kill yourself, but your project for sure.

    Regards,

      Jan

Children
No Data