Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
MicroStation
  • Product Communities
MicroStation
MicroStation Wiki Using VBA To Detect The Current Or Last Used Command
    • Sign In

    • +MicroStation Wiki
    • +Administration Wiki
    • +Annotations Wiki
    • +Bentley View Wiki
    • +MicroStation PowerDraft
    • +Printing and Plotting
    • -Programming Wiki
      • A class to help create and modify text element
      • A Complete Example
      • A MicroStation VBA Example With Bentley ProjectWise
      • AddIn Development Using VB.NET
      • C# .NET Template with IPrimitiveCommandEvents Class
      • Capturing Graphics in Dynamic Views
      • Compiling MDL Applications
      • Database Manipulation
      • Debugging Native Code MDL Applications
      • Developing Code in VBA
      • Developing MicroStation Applications For DWG Files
      • Drag and Drop in MicroStation
      • Error: "Cannot save changes to VBA project 'Support' because it is read-only"
      • Getting And Setting Elements Using Graphic Groups In VBA [CS]
      • Getting Started with Visual Basic
      • How To Write A Recursive Routine In MicroStation VBA [CS]
      • Introducing Segment3D Methods In MicroStation V8 2004 Edition
      • Known issues in MDL and MicroStationAPI
      • Launching VBA Applications As Initapps Or Dgnapps [CS]
      • Learning MicroStation Addins Step by Step
      • MDL - Getting Started With XAttributes In MicroStation V8 XM Edition
      • MDL - Native Code Application Development
      • MDL Or MicroStation BASIC Choosing The Right Tool [TN]
      • MFC Dialog And Native Window Support
      • Microsoft Office VBA Patch Utility
      • MicroStation BASIC FAQ
      • MicroStation BASIC Limits [FAQ]
      • MicroStation Developer Documentation and Example Code
      • MicroStation Programming Advice
      • MicroStation SDK
      • MicroStation V8 Programming Tools Readme
      • MicroStation V8 VBA Programming Resources [CS]
      • MicroStation V8 XM Edition View Code Updates
      • MicroStation VBA Resources Revisited [CS]
      • Migrating Dimension Code To MicroStation V8
      • Migrating MDL Applications To Native Code
      • Mouse Wheel Events And The Visual Basic 6.0 IDE
      • Porting MDL Applications To MicroStation V8
      • Reading Elements From A Microsoft Access Database With VBA [CS]
      • Running MDL Applications
      • Scanning For MicroStation V8 Elements In VBA [CS]
      • Unleash A Workspace Wizard Automating Workspace Creation With MicroStation V8 And VBA [CS]
      • Using VBA To Detect The Current Or Last Used Command
      • Using VBA To Programmatically Export A VBA Project [CS]
      • Using VBA To Programmatically Import A VBA Projects Components And References [CS]
      • VBA -- Creating A Complex Application
      • VBA Interface Error: failed creating the comp manager - 0x80040583
      • VBA interface error: unable to get IDE
      • vba recording
      • Working With Levels In MicroStation VBA [CS]
      • Writing An MDL Application To Output Custom Placemarks To Google Earth
      • [V8i C++] PointCloud IPointCloudChannelDisplayHandler
    • +Visualization Wiki
    • Window List Dialog for Missing Tool Dialog Boxes

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

    Using VBA To Detect The Current Or Last Used Command

    VBA does not provide a simple way to determine the current or last used command.  The closest thing is to use the functions

    GetCExpressionValue("tcb->current_command")

    and/or 

    GetCExpressionValue("tcb->last_parsed_command")

    These two commands return a command ID (VBA Type Long).  Through experimentation, one can determine the command ID for a particular command.  However, these command IDs may change between different versions of MicroStation.  To accommodate this, one should dynamically associate the command ID with the desired command.

    Dim commandID As Long
    CadInputQueue.SendCommand "MEASURE DISTANCE ICON"commandID = GetCExpressionValue("tcb->current_command")CommandState.StartDefaultCommand

    If you need to keep track of multiple command IDs, a dictionary object can be used.  The following code will get the command IDs for all the measurement types:

    Dim measurementTypes(5) As String, i As Long, commandID As Long
    Dim commandBase As String, measurementCodes
        
    measurementTypes(0) = "MEASURE DISTANCE ICON"
    measurementTypes(1) = "MEASURE AREA ICON"
    measurementTypes(2) = "MEASURE LENGTH ICON"
    measurementTypes(3) = "MEASURE RADIUS ICON"
    measurementTypes(4) = "MEASURE ANGLE ICON"
    measurementTypes(5) = "MEASURE VOLUME ICON"     'only do this one if it is a 3D file
        
    Set measurementCodes = CreateObject("Scripting.Dictionary")
    For i = 0 To UBound(measurementTypes)
        If Not (measurementTypes(i) Like "*VOLUME*") Or ActiveModelReference.Is3D Then
            CadInputQueue.SendCommand measurementTypes(i)
            commandID = GetCExpressionValue("tcb->current_command")
            If Not IsNull(commandID) Then
                measurementCodes.Add commandID, getCommandBase(measurementTypes(i))
            End If
        End If
    Next
    CommandState.StartDefaultCommand

    Then you can later use the "Exists" method of the Dictionary object to determine if you have defined the command for a particular commandID.

    There is one problem with this whole approach though.  This will only work if you know the command(s) you are looking for (Such as all the measuring commands).  If you are just generally trying to determine the current/last command used, you would need to have a exhaustive list of all the key-ins necessary to run those commands, something that may be hard to come by.

    • current command
    • previous command
    • last command
    • Share
    • History
    • More
    • Cancel
    • Dan Koval Created by Dan Koval
    • When: Thu, Sep 5 2013 3:47 PM
    • Revisions: 1
    • 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