how to use ustation.dll in c#

why cant I import ustation.dll in my project with visual studio 2008?

In this assebly there's a lot of interesting object  but i cant use them. Why?

I mean that i cant use object like:

  • Bentley.Internal.MicroStation.Elements.Solid
  • Bentley.Internal.MicroStation.Elements.Element

the problem is that if i declare an object of this type debugger say to me :

"cannot load file or assebly ustation" . Why?

thks.

Previdi.

Parents Reply Children
  • there's a way to get property of a solid element in c#(External application)? Property like volume, centroid, face area etcc?

    Grazie.

    Andrea.

  • This consoleApplication will write properties of selected solid elements...

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Bentley.Interop.MicroStationDGN;
    using SRIS = System.Runtime.InteropServices;
    using BMI = Bentley.MicroStation.InteropServices;
    using BIM = Bentley.Interop.MicroStationDGN;

    namespace ExternalCOMAndMDL
    {
        class Program
        {
            static void Main(string[] args)
            {

                BIM.ApplicationObjectConnector ustnConnector;
                BIM.Application ustn;

                try
                {
                    ustnConnector = (BIM.ApplicationObjectConnector)
                    SRIS.Marshal.GetActiveObject("MicroStationDGN.ApplicationObjectConnector");
                    ustn = ustnConnector.Application;
                }
                catch
                {
                    Console.WriteLine("No MicroStation is running...");
                    Console.ReadKey();
                    return;
                }

                if (ustn.ActiveModelReference.AnyElementsSelected != true)
                {
                    Console.WriteLine("No elements are selected in " + ustn.Caption);
                    Console.ReadKey();
                    return;
                }

                BIM.ElementEnumerator ee;
                BIM.Element cEl;
                System.String cExpression;
                double volume, area, cX, cY, cZ;

                ee = ustn.ActiveModelReference.GetSelectedElements();
                Console.WriteLine("Processing " + ustn.Caption);

                while (ee.MoveNext())
                {
                    cEl = ee.Current;
                    cExpression = "mdlMeasure_volumeProperties(&tcb->uc_a[0]," +
                                  "&tcb->uc_a[1], ((void*)0), &tcb->uc_a[2], " +
                                  "((void*)0), ((void*)0), ((void*)0), ((void*)0),"+
                                  "((void*)0), ((void*)0), " + 
                                  cEl.MdlElementDescrP(false) + ", 0.1, ((void*)0))";

                    if (0 == (int) ustn.GetCExpressionValue(cExpression, null))
                    {
                        volume = (double) ustn.GetCExpressionValue("tcb->uc_a[0]"null);
                        area = (double) ustn.GetCExpressionValue("tcb->uc_a[1]"null);
                        cX = (double) ustn.GetCExpressionValue("tcb->uc_a[2]"null);
                        cY = (double) ustn.GetCExpressionValue("tcb->uc_a[3]"null);
                        cZ = (double) ustn.GetCExpressionValue("tcb->uc_a[4]"null);

                        Console.WriteLine( "Volume: " + Math.Round(volume, 5).ToString() + 
                                           " Area: " + Math.Round(area, 5).ToString() +
                                           " Centroid: " + Math.Round(cX, 3).ToString() + 
                                           " " + Math.Round(cY, 3).ToString() + 
                                           " " + Math.Round(cZ, 3).ToString());
                    }
                }

                Console.ReadKey();
            }
        }
    }

  • try this (from the docs)

    Solid Properties

    Sub ShowSolidPropertyStrings(ele As Element)
    Dim oPH As PropertyHandler
    Set oPH = CreatePropertyHandler(ele)

    oPH.SelectByAccessString "Description"
    If oPH.GetValue = "Smart Solid" Then
    ShowDisplayString oPH, "Description"
    ShowDisplayString oPH, "NumElems"
    ShowDisplayString oPH, "RotationAngle"
    ShowDisplayString oPH, "ScaleX"
    ShowDisplayString oPH, "ScaleY"
    ShowDisplayString oPH, "ScaleZ"
    End If

    ShowDisplayString oPH, "Volume"
    ShowDisplayString oPH, "SurfaceArea"
    End Sub
    Sub ShowSolidPropertyValues(ele As Element)
    Dim oPH As PropertyHandler
    Set oPH = CreatePropertyHandler(ele)

    oPH.SelectByAccessString "Description"
    If oPH.GetValue = "Smart Solid" Then
    ShowValue oPH, "NumElems", False, False
    ShowValue oPH, "RotationAngle", False, False
    ShowValue oPH, "ScaleX", False, False
    ShowValue oPH, "ScaleY", False, False
    ShowValue oPH, "ScaleZ", False, False
    End If
    ShowValue oPH, "Volume", False, False
    ShowValue oPH, "SurfaceArea", False, False
    End Sub
    Private Sub ShowDisplayString(oPH As PropertyHandler, accessString As String)
    On Error GoTo HandleError

    If Not oPH.SelectByAccessString(accessString) Then
    Debug.Print "NOT FOUND!!"
    Else
    Debug.Print oPH.GetDisplayString
    End If

    Exit Sub
    HandleError:
    Debug.Print Err.Description
    End Sub
    Private Sub ShowValue(oPH As PropertyHandler, accessString As String, isDlong As Boolean, isPoint As Boolean)
    On Error GoTo HandleError

    If Not oPH.SelectByAccessString(accessString) Then
    Debug.Print "NOT FOUND!!"
    Else
    If isPoint Then
    Dim pnt As Point3d

    pnt = oPH.GetValueAsPoint3d
    Debug.Print "(" & pnt.X & "," & pnt.Y & "," & pnt.Z & ")"
    ElseIf isDlong Then
    Debug.Print DLongToString(oPH.GetValueAsDLong)
    Else
    Debug.Print oPH.GetValue
    End If
    End If

    Exit Sub
    HandleError:
    Debug.Print Err.Description
    End Sub

    You should property handlers from external applications.

    HTH,

    mark anderson [Bentley]