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 9 - PropertyHandler for Element Analysis
    • 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

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

    Searching and Evaluating Data in a drawing with VBA: Part 9 - PropertyHandler for Element Analysis

       
      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
       

    So far, we have a number of properties of graphical elements that we can read out which are always accessed directly depending on the type of element characteristics in the DGN Object Browser. Here, I will show an alternate way to access this data and in some cases even more features that are generated by applications. This is a well-known and often used MicroStation function element from the primary toolbox displayed with the icon below:

    If you execute this function and elect a shape for example, you will recieve a similar line-up with member information:

    The information on the elements are divided into categories. In the general catagory, you will find generic element attributes such as levels, colors, etc.
    Each of these pieces of information is marked with a description. I would like to point out here that this is key, because we now want to access this information.
    We need to use the so-called PropertyHander. Here is an example of how to read for example, the layer name:

    Sub elementinfo()
    Dim ele As Element
    Dim ee As ElementEnumerator
    Dim header, line As String
    Dim oPh As PropertyHandler
    Dim file As String
    On Error Resume Next
    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 oPh = CreatePropertyHandler(ee.Current)
    If oPh.SelectByAccessString("Level") Then
    Print #1, "Levelname: " & oPh.GetDisplayString
    End If
    Loop
    Close #1
    End Sub

    We generate scenarios from the respective element and object with all the properties and target a keyboard to the speicific information. For the example, we used the keyboard "Level" in the layer name.
    The output is still in the .csv file so that we are able to find the correct information.

    This information of the layer name can also be read directly from the respective element (preoperty ee.Current.Level.Name). However, there is a range o information that cannot be read directly as a property, particularly if these properties through applications are written to the elements.

    To find out what information might be available, there is the .GetAccessStrings method to read all existing access keys.
    Here, I left this one out in a list l () with strings numbered in the .CSV:

    Sub elementinfo()
    Dim ele As Element
    Dim ee As ElementEnumerator
    Dim header, line As String
    Dim oPh As PropertyHandler
    Dim l() 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 oPh = CreatePropertyHandler(ee.Current)
    l = oPh.GetAccessStrings
    Print #1, "There is possible information " & UBound(l) - LBound(l) + 1 & " at this element"
    For i = LBound(l) To UBound(l)
    Print #1, i & ";" & l(i)
    Next
    Loop
    Close #1
    End Sub

    The excel list starts with the following lines, in the 2nd column listing the exact keywords, which can be accessed via the following information:

    There is possible information Element 57 at this element
    0 Description
    1 Level
    2 ElementID
    3 Model
    4 ModifiedTime
    5 ElementSize

    It should also be noted that not all information is availabe, in which is may cause run-time errors that are ignored with the following statement:

    On error resume next

    Again, we attempt here to read out all data. Note that on the ON ERROR line, we deal with the runtime error. The output is virtually extended to the previous example, but only to the 3rd column:

    Sub elementinfo()
    Dim ele As Element
    Dim ee As ElementEnumerator
    Dim header, line As String
    Dim oPh As PropertyHandler
    Dim l() As String
    Dim file As String
    On Error Resume Next
    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 oPh = CreatePropertyHandler(ee.Current)
    l = oPh.GetAccessStrings
    Print #1, "There is possible information " & UBound(l) - LBound(l) + 1 & " at this element"
    For i = LBound(l) To UBound(l)
    If oPh.SelectByAccessString(l(i)) Then
    Print #1, i & ";" & l(i) & ";" & oPh.GetDisplayString
    End If
    Next
    Loop
    Close #1
    End Sub

    The first few lines of output could look something like this:

    There is possible information Element 57 at this element
    0 Description Shape
    1 Level NewLevel
    2 ElementID 633
    3 Model Default
    4 ModifiedTime 07.07.2014 11:17
    5 ElementSize 140
    6 FilePos 4000001
    7 Linkages 1

    In the following section, we deal exclusively with the reading of attribute data.

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

    • 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: Tue, Jun 23 2015 12:03 PM
    • Tristan Anderson Last revision by Bentley Colleague Tristan Anderson
    • When: Thu, Jun 25 2015 9:44 AM
    • 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