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
  • Hi Sunil,

    at first, please follow the best practices: Always specify exactly the used product and version, preferably using standardized subject format. There have been released 18 versions of MicroStation CONNECT Edition so far, and in some cases, it's crucial to know the version.

    Also, please use Insert > Insert code tool every time you want to share a code snippet. I think you will agree to try to understand your not formatted plain text is pretty complicated.

    I started as follows 

    The problem is that what you shared is not code, but just some not related lines.

    I recommend to define what do you want to achieve, because even when I will try to imagine what original code does, it's wrong.

    but not sure how to set leel and color and Point3d... 

    See examples available in MicroStation VBA help and also mvba examples delivered with MicroStation installation.

    ApplicationObjectConnector connector

    It means you are accessing MicroStation process from external one. In such case, read VBA documentation for ElementScanCriteria object, because to use new ElementScanCriteria command outside MicroStation is bug.

    With regards,

      Jan

  • 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

  • Old code is coded in VB code , using microstation externally
    Microstation Version :Microstaion V8i

    Converting old code into c# using connection edition
    Version : 10.00.15.12

    I am trying to Get List of Valid File based on scan using certain criteria
    Following
    /*** This is old VB Code need same functionality in c#****/

    Set oMS = CreateObject("MicroStationDGN.Application")
    Set oDGN = oMS.OpenDesignFile(<DGN File Path>, True)
    Set oView = oDGN.Views(1)
    Set oElScan = New ElementScanCriteria
    oElScan.ExcludeAllColors

    then include only color 5,6
    oElScan.IncludeColor 5
    oElScan.IncludeColor 6
    //SAME FOR LEVEL
    oElScan.ExcludeAllLevels
    //Included some levels
    //Then check with origin
    if(oView.Origin.X < some value)
    //then setting some Point 3d
    Dim Point As Point3d, PVoid As Point3d
    Point.X = ((1033.9 - 1000) * dblMult) + 1000
    Point.Y = ((1000.3 - 1000) * dblMult) + 1000
    Point.z = 0#
    //Then
    oMS.CadInputQueue.SendCommand "CHOOSE ELEMENT "
    oMS.CommandState.SetLocateCursor

    I need to replicate above code in c# where I can user MicroStation externally . I looked into MICROSTAION SDK examples and API , all examples are related to registering class library with microstaion not how to use it externally.

    I also looked into VBA code documentation and based on code scan criteria code is written for it fails .

  •  I looked into MICROSTAION SDK examples and API , all examples are related to registering class library with microstaion not how to use it externally.

  • I need to replicate above code in c# where I can user MicroStation externally
    Set oElScan = New ElementScanCriteria

    From VBA help (for MicroStation V8 and MicroStation CONNECT): A program that runs outside of MicroStation or needs to create an ElementScanCriteria object in another MicroStation process should use app.CreateObjectInMicroStation ("MicroStationDGN.ElementScanCriteria") where app is an object reference to the Application object for that process.

     
    Regards, Jon Summers
    LA Solutions

  • I still do not see any properly formatted code, using available syntax highlighter tool :-(

    I need to replicate above code in c#

    No, you do not have to. It's bad idea to try to replicate wrong code (e.g. there probably no reason to call CHOOSE ELEMENT key-in). It's the reason why I and Jon asked for functionality.

    It's usually simpler to answer questions like "how to select all green element in level xyz" than to try understand why somebody wrote some weird code and what it does.

    and based on code scan criteria code is written for it fails .

    Sorry, but I do not understand. What is written for VBA is nearly always valid for C#, as well as for external processes. When you wrote "fail", what does it mean?

    where I can user MicroStation externally

    It's very limiting, but when it's necessary, you have to use VBA / COM API, so C# code will be similar to existing VB.

    I need to replicate above code in c# where I can user MicroStation externally

    And where is your program in C#?

    Because VBA and Interop are based on the same COM API, code is very similar (I would say the same).

    It's not clear what help do you achieve: Somebody will write the new code for you?

    As explained in VBA help, there are more ways how to connect to MicroStation process, depending whether new instance should be started or external program should connect to existing one. It can look like:

    static void Main(string[] args)
    {
        ApplicationObjectConnector connector = new ApplicationObjectConnectorClass();
        Application mstnApp = connector.Application;
        ...
        mstnApp.OpenDesignFile("myfile.dgn");
        ...
        mstnApp.Quit();
    }
    

    Regards,

      Jan

  • Thank you Jan and Jon. 

    Your comment guiding to think about origin of this code  and helping me to understand MicroStation connect edition call externally.

    I At this point I really do not know  the motive as I was trying to replicate it as is. I might be able to know it in couple of hrs and then I might be able to answer counter questions. 

    As I am very new your guide line definitely gave me think about the approach. 

      

  • 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);
            }
        }
    }

  • I am using Connect edition Version 10.00.15.12  and net framework 4.7.2

  • Hi,

    I have following code

    please use Insert > Insert code tool every time you want so share a code snippet (even one line of text) with properly set language. I am not sure why the code is duplicated.

    //AS SCAN CRITERIA OUT SIDE AS BUG ,WANT CREATE A CLASS LIB FOR IT WITH IN MICROSTATION

    Two issues there:

    • It should be (in normal addin code)

    ElementScanCriteria escan = new ElementScanCriteriaClass();

    • 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.
    Can not be mebedded .Use the application Interface instead

    Yes, it cannot be embedded and it should not be embedded.

    How do you reference Bentley.Interop.MicroStationDGN.dll assembly? I assume you have Embed Interop Types set to True, but it should be False (to behave in the same way as NET Framework 3.5).

    Regards,

      Jan