Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
MicroStation
  • Product Communities
MicroStation
MicroStation Wiki Searching and Evaluating Data in a drawing with VBA: Part 6 - Evaluating Simple Complex Elements
    • Sign In

    • -MicroStation Wiki
      • +Learning Tips
      • -MicroStation
        • +3D Printing - MicroStation
        • +Animation - MicroStation
        • +Archive / Backup - MicroStation
        • +Base Geometry - MicroStation
        • +Batch Processing - MicroStation
        • +CONNECT Advisor - MicroStation
        • CONNECT Integration - MicroStation
        • +CONNECTION Client
        • +Cells - MicroStation
        • +Change Tracking - MicroStation
        • +Configuration - MicroStation
        • +Coordinate Systems - MicroStation
        • +Curves - MicroStation
        • +Custom Linestyles - MicroStation
        • +DGN - MicroStation
        • +DWG - MicroStation
        • +Database - MicroStation
        • +Detailing Symbols - MicroStation
        • +Dimensions - MicroStation
        • +Documentation & Help - MicroStation
        • +Drawing Aids - MicroStation
        • +Exception - MicroStation
        • +FAQ - MicroStation
        • +Feature Based Solids Modeling - MicroStation
        • +File Access - MicroStation
        • +GUI - MicroStation
        • +General - MicroStation
        • +Graphics Display - MicroStation
        • +Groups - MicroStation
        • +Hardware / Input Devices - MicroStation
        • +Import/Export - MicroStation
        • +Installation - MicroStation
        • +Interchange - MicroStation
        • +Interference - MicroStation
        • +Internationalization - MicroStation
        • +Levels - MicroStation
        • +Licensing - MicroStation
        • +Manipulation - MicroStation
        • +Markup / Redline - MicroStation
        • +Measure - MicroStation
        • +Mesh - MicroStation
        • +Models - MicroStation
        • +Multi-Lines - MicroStation
        • +OLE - MicroStation
        • +Other - MicroStation
        • +Parametrics - MicroStation
        • +Patterning - MicroStation
        • +Point Cloud - MicroStation
        • +Printing - MicroStation
        • -Programming - MicroStation
          • +General - Programming - MicroStation
          • +Macro Recorder - Programming - MicroStation
          • +MDL - Programming - MicroStation
          • -VBA - Programming - MicroStation
            • Automatic execution when opening or closing drawings
            • Automatic Subroutine Loading
            • Automatically generate plots with VBA
            • Avoiding Inaccuracies in VBA Methods - .FacetSolidAsShapes for SmartSolids
            • Bring All Text to a New Level with VBA
            • Browsing References for Specific Items
            • Calculating the range of Rotated Cells
            • Changing Colors of Levels in VBA
            • Changing display priority for references
            • Changing Element Colors from RGB to Indexed Color
            • Changing Layer Colors from RGB to an Indexed Color
            • Changing the Alignment of All Texts with VBA
            • Changing the display order of elements
            • Changing the presentation order of Layers
            • Changing the Transparency Settings of Levels with VBA
            • Cleaning Property Data with VBA
            • COM Server error
            • Create Engineering (HTML) Links in VBA
            • Creating Coordinates as Latitude and Longitude using VBA Lines
            • Creating VBA Levels - 'Level name is duplicate'
            • Deleting Lines of Length 0 Using VBA
            • Errors Attempting to Load VBA Projects
            • Errors while attempting to load VBA
            • Exporting the RGB Values of the Color Table to a Text File in VBA
            • Forms in an .mvba do not open some pc's
            • How to read the RGB values of the Attached Color Table
            • Keyin to load the VBA Project Manager in MicroStation Connect
            • Leaving a VBA Tools Dialog Box Open
            • Linking to VBA Elements with User Attributes
            • New Text Font Cannot be Assigned
            • Placing annotation cells with VBA
            • Print Organizer Control with VBA
            • Printing all Sheet Models to PDF Using VBA
            • Reading the Length of All Arcs
            • Removing All Object Data from Selected Cells in VBA
            • Replacing Points with Circles Using VBA
            • Replacing Text with VBA - Part 1: Introduction
            • Replacing Text with VBA - Part 2: Complex Structures
            • Running a VBA Routine by Keyin
            • -Searching and Evaluating Data in a drawing with VBA
              • Searching and Evaluating Data in a drawing with VBA: Part 1 - Preparation.
              • Searching and Evaluating Data in a drawing with VBA: Part 10 - Reading Attribute Data
              • Searching and Evaluating Data in a drawing with VBA: Part 2 - Reading properties of Elements
              • Searching and Evaluating Data in a drawing with VBA: Part 3 - Reading Properties of Elements and Exporting to a Text File
              • Searching and Evaluating Data in a drawing with VBA: Part 4 - Saving data to a formatted CSV file
              • Searching and Evaluating Data in a drawing with VBA: Part 5 - Reading More General Properties of Elements
              • Searching and Evaluating Data in a drawing with VBA: Part 6 - Evaluating Simple Complex Elements
              • Searching and Evaluating Data in a drawing with VBA: Part 7 - Evaluating General Complex Elements
              • Searching and Evaluating Data in a drawing with VBA: Part 8 - Evaluating Nested Complex Elements
              • Searching and Evaluating Data in a drawing with VBA: Part 9 - PropertyHandler for Element Analysis
            • Searching and Selecting Text Fields with VBA
            • Updating sequence control with VBA
            • Using a VBA Macro
            • Using the VBA object PropertyHandler to change the Element Information
            • VBA - Interface Error: 0x80040502
            • VBA Error in Execution: Project or Library Not Found
            • What are these "Default.mvba" files?
        • +Project Navigation - MicroStation
        • +Properties - MicroStation
        • +RSS Feeds - MicroStation
        • +Reference - MicroStation
        • +Security - MicroStation
        • +Selection - MicroStation
        • +Settings - MicroStation
        • +Sheet Composition - MicroStation
        • +Solids - MicroStation
        • +Standards - MicroStation
        • +Surfaces - MicroStation
        • +Tables - MicroStation
        • +Text - MicroStation
        • +UI Customization - MicroStation
        • +Units - MicroStation
        • +View - MicroStation
        • +Visualization - MicroStation
        • Welcome Page - MicroStation
        • +Accreditation - MicroStation
        • +i.Models - MicroStation
        • +ProjectWise Integration
        • +Raster - MicroStation
    • +Administration Wiki
    • +Annotations Wiki
    • +Bentley View Wiki
    • +MicroStation PowerDraft
    • +Printing and Plotting
    • +Programming Wiki
    • +Visualization Wiki
    • Window List Dialog for Missing Tool Dialog Boxes

     
     Questions about this article, topic, or product? Click here. 

    Searching and Evaluating Data in a drawing with VBA: Part 6 - Evaluating Simple Complex Elements

       
      Applies To 
       
      Product(s): MicroStation
      Version(s): 08.11.09.578
      Environment:  N\A
      Area:  Programming
      Subarea:  VBA
      Original Author: Tristan Anderson, Bentley Technical Support Group
       

     In the previous sections, we looked at retrieving data from elements such as lines, circles, and text. For more complex structures, we need more functions to get detailed information.

    We will start again with text nodes. Text nodes are interesting elements because you can access targeted text without knowing the exact position by using the text node number. Text nodes, although usually comprised of text, can also be empty, or have one or more lines of text. 

    An essential function in accessing text of a node is the .GetSubElements method.
    This will give us a range of elements, similar to those we have already gotten when using the ElementEnumerator. In the evaluation of elements, we will encounter complex elements that we can break down into simpler individual elements. This will help us extract data from groups or cells much more easily. In text nodes, however, there is no further nesting, because a text node only contains text with a size of 0 to n.

    Using the previous examples as a basis for the evaluation of text nodes, we can create a simple routine for evaluating text nodes that might look something like this:

    Sub elementinfo()
    Dim ele As Element
    Dim ee As ElementEnumerator
    Dim eeSub As ElementEnumerator
    Dim startpoint, endpoint As Point3d
    Dim header, Line As String
     Dim file As String
    If ActiveWorkspace.IsConfigurationVariableDefined("MeineAusgabeFile") Then
     file = ActiveWorkspace.ConfigurationVariableValue("MeineAusgabeFile")
    Else
     MsgBox "The variable MyOutputFile is not defined. Stopped processing", vbCritical
     Exit Sub
    End If
    Open file For Append As #1
    Set ee = ActiveModelReference.GraphicalElementCache.Scan()
    Do While ee.MoveNext
    If ee.Current.IsTextNodeElement Then
     Set eeSub = ee.Current.AsTextNodeElement.GetSubElements
     Do While eeSub.MoveNext
     Set ele = eeSub.Current
    Lin e = "TextNode#: " & ee.Current.AsTextNodeElement.NodeNumber & ";"
     If ele.Type = msdElementTypeText Then
     Line = Line & ele.Type & ";Origin (xy) = " & ele.AsTextElement.Origin.X & "," & ele.AsTextElement.Origin.Y & ";"
     Line = Line & "Height: " & ele.AsTextElement.TextStyle.Height & ";"
     Line = Line & "Text: " & ele.AsTextElement.Text
     Print #1, Line
     End If
     Loop
    End If
    Loop
    Close #1
    End Sub

    The text output will be the same as before, with the exception of the node number of the text node at the beginning.

    I have put a two line text node 3 different times using the place text command. The issue here is that the text nodes are automatically numbered, so that when a new text node is placed, it gets the next available node number.

    The evaluation of many drawings have always presented problems from the fact that both texts and text nodes can be present. Text nodes may occur when hitting the return key while creating a text element so that there are 2 lines of text, but the second one is blank. Visually, they will look the same, but the element types will have changed.

    The method that we have learned (.GetSubElements) is important to know when extracting data from nested structures if you know that text nodes are in any nested structures such as groups, cells, or pseudo-cells.

    Before we continue to go deeper into this, let's first take a look at other complex data structures that have direct access possibilities.
    In addition, I have drawn the following shapes: a red line, a blue line string, and a green shape:

    Whatever differentes or similarities these elements have, I read out the geometric data using the key points of the elements with the previously stated method.

    The line is only a special case of a line string except with only 2 vertices.

    To read vertices, I define an array of points:

    Dim l() As Point3d

    With the query:

    If ee.Current.IsLineElement Then ...

    I can identify both the line and the line string. Because I can identify the shape, I add another option:

    If ee.Current.IsLineElement Or ee.Current.IsShapeElement Then ...

    The following analysis should be able to write the vertices of the elements in a file. However, because the number of vertices per element is previously unclear, I will output one line per vertex. 

    The module could look something like this:

    Sub elementinfo()
    Dim ele As Element
    Dim ee As ElementEnumerator
    Dim startpoint, endpoint As Point3d
    Dim header, Line As String
    Dim l() As Point3d
     Dim file As String
    If ActiveWorkspace.IsConfigurationVariableDefined("MyOutputFile") Then
     file = ActiveWorkspace.ConfigurationVariableValue("MyOutputFile")
    Else
     MsgBox "The variable MyOutputFile is not defined. Stopped processing", vbCritical
     Exit Sub
    End If
    Open file For Append As #1
    Set ee = ActiveModelReference.GraphicalElementCache.Scan()
    Do While ee.MoveNext
     If ee.Current.IsLineElement Or ee.Current.IsShapeElement Then
     l = ee.Current.AsVertexList.GetVertices
     Line = "Typ: " & ee.Current.Type & " with " & UBound(l) - LBound(l) + 1 & " Vertices"
     Print #1, Line
     For i = LBound(l) To UBound(l)
     Line = "Vertex # " & i + 1 & "(xyz);"
     Line = Line & l(i).X & ";" & l(i).Y & ";" & l(i).Z
     Print #1, Line
     Next
     End If
    Loop
    Close #1

    The example with 3 different elements has the following output:

    With the coordinates, you can see that the last item is a closed element.

    In the next section, we will look at complex structures such as cells.

    << RETURN TO PART 5 <<              >> CONTINUE ON TO PART 7 >>

    • Windows 7 32 bit
    • MicroStation
    • VBA
    • Windows 7 64 bit
    • Programming
    • en
    • 08.11.09.578
    • SELECTsupport
    • Share
    • History
    • More
    • Cancel
    • Tristan Anderson Created by Bentley Colleague Tristan Anderson
    • When: Mon, Jun 22 2015 1:15 PM
    • Tristan Anderson Last revision by Bentley Colleague Tristan Anderson
    • When: Mon, Jun 22 2015 1:21 PM
    • Revisions: 3
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies