Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
MicroStation
  • Product Communities
  • More
MicroStation
MicroStation Wiki Searching and Evaluating Data in a drawing with VBA: Part 7 - Evaluating General 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
    • +Programming Wiki
    • +Visualization Wiki

    You are currently reviewing an older revision of this page.

    • History View current version

    Searching and Evaluating Data in a drawing with VBA: Part 7 - Evaluating General Complex Elements

       
      Applies To 
       
      Product(s): MicroStation
      Version(s): 08.11.09.578
      Environment:  Windows 7 32 bit,Windows 7 64 bit
      Area:  Programming
      Subarea:  VBA
      Original Author: Tristan Anderson, Bentley Technical Support Group
       

     

    We will now look at general complex structures and evaluate when these examples will initially serve cells. Cells are type 2 elements and normally have a name that can be identified similar to how it was with node numbers and text nodes. 

    There are, however, cells with no name that can be elements grouped in with the "Create Group" command.
    A first example of this should be a listing of all cells with the nubmer of sub-elements contained in them. For this, I will use the .GetSubElements instruction by converting this selection into an array to directly read out the number of elements inside. 

    I will be evaluating these two visually identical cells. The left cell, however, has been created as a group of individual elements, while the right cell has been placed as a cell from the cell library.

    Here is a possible approach, saving the output to a file:

    Sub elementinfo()
    Dim ele As Element
    Dim ee As ElementEnumerator
    Dim startpoint, endpoint As Point3d
    Dim header, Line As String
    Dim oL() As Element
    Dim Cellname As String
     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
     Set ele = ee.Current
    If ele.IsCellElement Then
     oL = ele.AsCellElement.GetSubElements.BuildArrayFromContents
     Cellname = ele.AsCellElement.Name
     If Len(Zellname) = 0 Then Zellname = "Ohne Namen"
     line = "Cell < " & Cellname & "> mit " & UBound(oL) - LBound(oL) + 1 & " Element"
     Print #1, line
     End If
    Loop
    Close #1
    End Sub

    With the two elements from the previous screenshot, I got this as the output:

    The result so far shows that in addition to the 3 text elements, there is a circle and a rectangle. 
    Note that here the number of nested elements would be 3 because the 3 texts were summarized into 1 text node. Visually, this is indistinguishable except when using the "Analayze Element" Keyin.

    The Keying "Analyze Element" shows many details that will help us to use the correct procedure for an evaluation in the current context. 
    In the above routine, I used this command to read for the first time:

    oL = ele.AsCellElement.GetSubElements.BuildArrayFromContents

    After applying the .GetSubElements even a transformation of the selection is set in an array. This will allow me to immediately get the number of items read by the term "ubound (OL) - lbound (OL) + 1".

    Ubound represents upper boundary and Lbound represents lower boundary for the filled array elements.

    As a next step, we will list the individual elements of each cell in the output, which can be extended as shown below:

    Sub elementinfo()
    Dim ele As Element
    Dim ee As ElementEnumerator
    Dim startpoint, endpoint As Point3d
    Dim header, line As String
    Dim oL() As Element
    Dim Cellname As String
     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
     Set ele = ee.Current
    If ele.IsCellElement Then
     oL = ele.AsCellElement.GetSubElements.BuildArrayFromContents
     Cellname = ele.AsCellElement.Name
     If Len(Cellname) = 0 Then Cellname = "Nameless"
     line = "Cell < " & Cellname & "> with " & UBound(oL) - LBound(oL) + 1 & " Element"
     Print #1, line
    For i = LBound(oL) To UBound(oL)
     line = TypeName(oL(i))
     Print #1, line
     Next
     End If
    Loop
    Close #1
    End Sub

    This example outputs the following into the .csv file:

    In this example, I have now have the name of the type instead of the type number by using the TypeName function.
    As already previously mentioned, the circle is just a special example of an ellipse, which explains the indication of the EllipseElement.
    If you want to distinguish here specifically, you can use the .PrimaryRadius and Secondary radius to read and compare the data, which should be identical in both circles.

    Many data points of this type is sufficient, but we cannot be sure whether the examined cells are nested or not. Basically, there are no restrictions in nesting, so we have to use a new way of detecting nested cells that contain nested cells. To do this, we will be using recursion for reading data, but we will wait until the next section to do this.

    << RETURN TO PART 6 <<              >> CONTINUE ON TO PART 8 >>

    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

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