VBA Record failed

Asked this question a number of years ago, failed to ask it correctly

I tried the VBA record in an attempt to record or duplicate in VBA the Alt+F4 command used in Micro Station and Windows also to close certain windows.

Sub Macro3()
Dim startPoint As Point3d
Dim point As Point3d, point2 As Point3d
Dim lngTemp As Long

' Start a command
CadInputQueue.SendCommand "FILEDESIGN"

CommandState.StartDefaultCommand
End Sub

All I got. I have learned certain features like using the 4-5 sequence will zoom out the drawing window but hitting Esc will not close it nor pressing the 1 key which opens the Power Select. The only two options are click the red x to close or actually press the Alt+F4 key manually. Know you can run a VBA by direct key-in I was going to attempt to use a quick select button to duplicate the [X]

manually click the x or press Alt+F4. A picture of my quick select tool box to give you the Idea 

 I was hoping to setup another quick time saving button which all the gray spots are spares for future use I can set and do about everything I have to much faster than looking and I only have one basic F key left F2 I am using the rest and did not want to resort to the Alt+ or Ctrl+

Hope this is a better worded question ?

Parents
  • Hi Richard,

    Hope this is a better worded question ?

    Unofortuately not too much. I lseems to me you have tried to write a novel illustrated with nice pictures, where more different types of information are mixed and not clear technical spec formulated in simple points.

    Let's do some analysis...

    I tried the VBA record in an attempt to record or duplicate in VBA

    To record or to duplicate? They are two different things.

    the Alt+F4 command used in Micro Station and Windows

    VBA macro recorded is limited in terms of its features and what can be recorded. And I am quite sure Windows shortcuts often cannot be recorded at all or only consequences (internal events) are recorded.

    to close certain windows.

    Sorry, but such information is completely useless :-( What is "dialog"? Please be specific and provide exact information.

    Is it about MicroStation dialog (Tool Settings dialog, References dialog etc.) or your VBA UserForm? Technically they are very different situations.

    Why not to formulate you question / request as: I have VBA Form in my MicroStation VBA macro and I want to close it when defined keyboard shortcut is used?

    All I got.

    This is not the record of Alt+F4 shortcut. I guess it cannot be recorded, because Alt+F4 closes active dialog, so it can close the whole MicroStation (recording will be stopped at this case) or it closes active dialog (e.g References or Level Manager), but I think VBA recorded does not record these events, because they are "GUI only" changes without any change in design file content or active setting. And there is no singl euniversal key-in to close a particular dialog.

    I have learned certain features like using the 4-5 sequence will zoom out the drawing window but hitting Esc will not close it nor pressing the 1 key which opens the Power Select. The only two options are click the red x to close or actually press the Alt+F4 key manually. Know you can run a VBA by direct key-in I was going to attempt to use a quick select button to duplicate the [X]

    I do not understand these sentences. What are they about?

    I was hoping to setup another quick time saving button which all the gray spots are spares for future use I can set and do about everything I have to much faster than looking and I only have one basic F key left F2 I am using the rest and did not want to resort to the Alt+ or Ctrl+

    What is your object? Is it VBA form? It's not possible to track key shortcuts from VBA code, it's not the tool to implement such functionality. VBA Forms have very limited functionality to track pressed keys when the dialog is active and sometimes even a simple request leads quickly to dirty code hacks.

    I assume I do not understand the issue well enough, but it seems to me like the try to implement simple feature in very complicated way. What is a main purpose of this (strange) form that tries to simulate MicroStation toolbar? VBA is not tightly integrated into MicroStation GUI (cannot be from technical reasons), so it's not the right tool.

    In my opinion better approach is to follow how MicroStation GUI is designed and to use standard MicroStation customization tools like own toolboxes and tasks, where position mapping will work automatically and every icon can call defined VBA macro. To implement completely own solution, you have to use nati C/C++ code and MicroStation resources (or WinForms in C# alternatively), but I am in doubt whether the result will be "MicroStation compatible".

    With regards,

      Jan

  • Well took me to the cleaners more that once )c; Sorry for trying hard to explain. I have been working on a workaround for the Alt+F4 command I wanted to put into a macro or key in. This is where I am at so far. I was attempting to close any command box like this one

    it can be closed via Alt+F4 the Esc key will not work as it does in so many other choices.

    the single key entry works good for me as the 1234.... commands and the A, W, Q, ... 

    The follow will do almost everything, sadly the CadInputQueue.SendKeyin "dialog viewsettings off"

    actually works as a toggle if the viewsettings are off it turns them on (not so good for me)

    the rest seem to test great now all I do is press the F8 key (mdl silentload USTNVBA MACROS)

    and then Enter which seems to close most everything. the Alt+F4 seems to do anything but unable to find out how to put the command into a Key-in to make myself a button or into a VBA  which I can run run with key-in button. Hope this is more focuse or maybe more confusing. I always appreciate your help. Sorry I messed up worse then 8 years ago.

    Sub a00Macro3()
    ' 082518 - Addeed "levelmanager dialog close", Added "leveldisplay dialog, Works "Place Circle",
    ' [1] close" Added "dialog viewsettings off" FAILS if not open it opens it with the close command ??
    ' 072518 - Reset Command will close "Fit View", with the "CommandState.StartDefault Command "Smart Line"
    ' 072518 continued:Closed "Extend",

    ' Start a command
    ' CadInputQueue.SendCommand "FILEDESIGN"
    CadInputQueue.SendKeyin "Reset"
    CadInputQueue.SendKeyin "levelmanager dialog close"
    CadInputQueue.SendKeyin "leveldisplay dialog close"
    ' [1]
    ' CadInputQueue.SendKeyin "dialog viewsettings off"
    'CadInputQueue.SendKeyin ""
    'CadInputQueue.SendKeyin ""
    CommandState.StartDefaultCommand
    End Sub

    The unusual name of macro is for testing and it stays at the top of the pop-up list.

    Ok, God bless and thank you again for the pointers. Was I not 73 I would try at the C++

    having been told many years ago when learning Basic ((^8 

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

  • Hi Richard,

    I have been working on a workaround for the Alt+F4 command I wanted to put into a macro or key in.

    Because you have not described / shared any complete workflow what VBA code should do, I have to ask "Why?". The request "to close any dialog" sounds very strange to me, because VBA code should not interact with dialogs, but to access / control MicroStation through VBA API and when it's necessary, through key-ins.

    Can you explain please describe specific (not general ideas) workflow step by step (in points, not in plain text), where at the end you need to close a dialog? Or your request is to find all opened dialogs and to close them all? I assume this is not your question, because it's not the functionality of Alt+F4.

    I was attempting to close any command box like this one

    Please use correct terminology. This is not command box, but Tool Settings dialog. There is only one such dialog, so exact naming is crucial. Why you want to close it? It's the core and central point of any MicroStation workflow, because it dynamically shows parameters of active tool, so to close it looks like a bad idea. And it will be opened automatically when another tool is started anyway.

    sadly the CadInputQueue.SendKeyin "dialog viewsettings off" actually works as a toggle if the viewsettings are off it turns them on

    It looks like bug in MicroStation and should be reported via Service Ticket. But because V8i development is closed and all is about CE today, an importance of such ticket will be probably quite low. But it seems the problem persists also in CE...

    the rest seem to test great now all I do is press the F8 key (mdl silentload USTNVBA MACROS)and then Enter which seems to close most everything.

    What you want to achieve? What should be the result of your workflow? Please don't describe what you do (it looks like my brain is not good enough to understand it), but what is required result.

    In this case, you opened Macros dialog and select a macro that should be started. If it's repeated often, it looks to me like too complicated, because my personal opinion is that any interaction with GUI (usually dialogs) breaks automation. Maybe to start specific macro using key-in directly and to assign such key-in to e.g. F key or to icon in custom toolbox would be better?

    and then Enter which seems to close most everything.

    So you want to close all opened dialogs?

    but unable to find out how to put the command into a Key-in to make myself a button or into a VBA  which I can run run with key-in button.

    Sorry, do not understand :-( What do you mean by "put command into a key-in..."?

    You can create own toolobox with tools (represented by icons). Every tool can be configured (how it looks like and behave, assign show/hide tests etc.) and it also have assigned key-in that is run when the icon is pressed. Is it what you want to use?

    Sub a00Macro3()

    What this macro should do? It closes two (or three) dialogs. Why?

    I am sad I cannot help you, but still don't understand what are your requirements and what macro(s) should do. Usually it can be formulatted in one or two sentences (or several steps, not continuous text). When long text is necessary to desribe functionality, the design is probably wrong, because it's expected the code will do too many things, which is always harder to implement.

    With regards,

      Jan

  • Usually it can be formulatted in one or two sentences

    To explain it better, well-formulated specifications can be for example:

    • When I press a particular F-key, specific macro should be started.
    • When I press an icon in my custom toolbox, this key-in should be started.

    ... or when more steps are involved in the workflow:

    1. After click on my custom icon in toolbox, VBA macro should be started.
    2. A user using data point will identify a view.
    3. This view will be ...
    4. The command ends

    To use lengthy formulations rarely leads to simple and efficient discussion, because it's easy to put more working tiny simple tasks togeether, but complex and hard to try to solve ten different things together in one discussion and code.

    Regards,

      Jan

  • to close any command box like this one

    To close Tool Settings dialog this key-in can be used:

    dmsg closedialog -79

    But as I wrote above, it does not makes any sense to me, because the dialog will be opened again when a tool is started.

    Regards,

      Jan

  • Wow, this is it, Most of the dialog boxes will go back to the default command when Esc is pressed but every time I hit 4-5 (Fit View) the dialog tool would not reset when the Esc was pressed, nor the right mouse. the dmsg closedialog - 79 did the trick

    I had to wait a while to come back,  I was so ashamed to read the reply and all the errors I made. 8 yrs ago I was told to put in ref pictures and that was my poor attempt you have given me the tool to fix the problem and I had searched but again if you do not know how to express a question hard to find answers.

    Thank you again and God bless you. Your one very sharp/Smart individual

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

  • Jan, I understand more now. I am used to Esc closing most dialog s and going back to my default command the Power Selector. After reading your last reply I did the key commands 4-5 (Fit View) then pressed Esc and the 1 key and there I was back to the active command of Power Select. I was so used to just Esc and it failed on the Fit View 4-5 sequence to go back to default, but then I pressed the 1 which opens the power select. So it just takes an extra key and I was using the Alt+F4 to close it 

    sorry for the confusion and thanks for feedback . 

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

Reply
  • Jan, I understand more now. I am used to Esc closing most dialog s and going back to my default command the Power Selector. After reading your last reply I did the key commands 4-5 (Fit View) then pressed Esc and the 1 key and there I was back to the active command of Power Select. I was so used to just Esc and it failed on the Fit View 4-5 sequence to go back to default, but then I pressed the 1 which opens the power select. So it just takes an extra key and I was using the Alt+F4 to close it 

    sorry for the confusion and thanks for feedback . 

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

Children
No Data