Extracting the coordinates of polygonal features

Let us suppose that I have 5 3D polygons in my DGN file. I wish to extract the coordinates of the vertices in the DGN file. My questions are as follows:

(a) Is it possible to assign tags / attributes either programmatically or through front end to each of the 3D polygons?

(b) Is it possible to query the polygons present in the DGN file based on the attributes?

(c) Is it possible to extract the coordinates of the vertices of each of the polygons.

Thanks in advance.I am asking this question because I cannot understand the documentation.

Parents
  • Unknown said:
    I am asking this question because I cannot understand the documentation

    You have my sympathy.  It's not always easy to make sense of formal documentation.

    Terminology

    Let's be clear on terminology.  A DGN file is a container.  It contains one or more models.  A model is a 2D or 3D drawing space where you create graphic elements.

    In MicroStation, a polygon is represented by a shape element.  You can create a shape element in 3D space, but the shape itself should be planar.

    Unknown said:
    Let us suppose that I have 5 3D polygons in my DGN file

    I interpret your statement like this: you have a DGN file that contains a 3D model.  In that model are five shape elements.  You want to extract the coordinates of those shapes.

    Scanning a Model

    Unknown said:
    Is it possible to query the polygons

    The MicroStation idiom to query a model is the scanner.  A ModelReference has a Scan method.  You filter the results of a scan by setting the ScanCriteria class properties.  The result of a scan is an ElementEnumerator object.  Iterate the ElementEnumerator to see each element that passed the scan criteria.

    This article discusses Scanning a Model using MicroStation VBA.  There are also examples in VBA help.

    Unknown said:
    Is it possible to extract the coordinates of the vertices of each of the polygons?

    Yes.  ShapeElement.GetVertices provides an array of Point3d data.

     
    Regards, Jon Summers
    LA Solutions

  • Please let me know what is the problem here. I have done almost the same as what Jon Summers suggested.

    Sub myDumVertices()
    Dim theListOfElements As ElementEnumerator
    Dim theElement As ShapeElement
    Dim myVertexList() As Point3d
    Dim myScanCriteria As ElementScanCriteria

    'create new scan criteria
    Set myScanCriteria = New ElementScanCriteria

    'set scan criteria to remove annotations
    myScanCriteria.ExcludeNonGraphical

    'scan elements and set to element enumerator
    Set theListOfElements = ActiveModelReference.Scan(myScanCriteria)

    'iterate over each of the elements now
    Do While theListOfElements.MoveNext
        'catch the current element
        Set theElement = theListOfElements.Current
        
        'catch the list of vertices
        Set myVertexList = theElement.GetVertices()
        
        'process the list of points here
        myProcessList myVertexList
    Loop

    End Sub

    The code cries, cannot assign to Array!!

Reply
  • Please let me know what is the problem here. I have done almost the same as what Jon Summers suggested.

    Sub myDumVertices()
    Dim theListOfElements As ElementEnumerator
    Dim theElement As ShapeElement
    Dim myVertexList() As Point3d
    Dim myScanCriteria As ElementScanCriteria

    'create new scan criteria
    Set myScanCriteria = New ElementScanCriteria

    'set scan criteria to remove annotations
    myScanCriteria.ExcludeNonGraphical

    'scan elements and set to element enumerator
    Set theListOfElements = ActiveModelReference.Scan(myScanCriteria)

    'iterate over each of the elements now
    Do While theListOfElements.MoveNext
        'catch the current element
        Set theElement = theListOfElements.Current
        
        'catch the list of vertices
        Set myVertexList = theElement.GetVertices()
        
        'process the list of points here
        myProcessList myVertexList
    Loop

    End Sub

    The code cries, cannot assign to Array!!

Children
  • Hi,

    without testing your code, I see these problems:

    • Don't use Set myVertexList = theElement.GetVertices(), but only myVertexList = theElement.GetVertices().
      I recommend to check examples for GetVertices method in MicroStation VBA help file, there are at least three different examples available.
    • You try to use .GetVertices method to all graphical elements you process in Element Enumerator, which will probably fail, because not all types of elements support this method. As demonstrated Mark in his former answer, you should check type of element (e.g. If oEnum.Current.IsSmartSolidElement Then) to be sure you work with the right element type.
    • It's not error, but (only) bad coding style, to define all variables at the method beginnig. It's recommended in the most languages to create variables immediately before they are used for the first time. Ocasionally it's necessary to break this recommendation from some reasons, but usually not.

    With regards,

      Jan

  • Jan,

    If I use,

    myVertexList = theElement.GetVertices()

    VBA Cries with the following message:

    "Class does not support Automation or does not support expected interface'

    Therefore, I used your suggestion, and coded the following:

    Sub myDumVertices()
    'create new scan criteria
    Dim myScanCriteria As ElementScanCriteria
    Set myScanCriteria = New ElementScanCriteria

    'set scan criteria to remove annotations
    myScanCriteria.ExcludeNonGraphical

    'scan elements and set to element enumerator
    Dim theListOfElements As ElementEnumerator
    Set theListOfElements = ActiveModelReference.Scan(myScanCriteria)

    'iterate over each of the elements now
    Do While theListOfElements.MoveNext
        'catch the current element
        Dim theElement As Element
        Set theElement = theListOfElements.Current
        
        If theElement.IsShapeElement Then
            
            'catch the list of vertices
            Dim myVertexList() As Point3d
            myVertexList = theElement.AsShapeElement.GetVertices()
        
            'process the list of points here
            myProcessList myVertexList
        End If
    Loop

    End Sub

    Sub myProcessList(thePoints() As Point3d)
    Dim i As Integer

    For i = LBound(thePoints) To UBound(thePoints)
        Debug.Print "The vertex item " + CStr(i) + " is " + CStr(thePoints(i).X) + ", " + CStr(thePoints(i).Y) + ", " + CStr(thePoints(i).Z)
    Next i
    End Sub

    This works!

    Thanks for your help. Hope my programming looks better now!

    Answer Verified By: Suddhasheel Ghosh