DoEvents and cursor - How to allow user to continue working during macro

DoEvents and cursor - How to allow user to continue working during macro

Anonymous
Not applicable
1,426 Views
2 Replies
Message 1 of 3

DoEvents and cursor - How to allow user to continue working during macro

Anonymous
Not applicable

Hi everyone,

 

I’m stuck with an issue on my macro.

I’m waiting for an user input (a particular shortcut). So I infinitely loop waiting for this and I add a DoEvents inside the loop.

 

Do Until (GetAsyncKeyState() And GetAsyncKeyState())
        DoEvents
        If GetAsyncKeyState() then
                # code here
End if Loop

When I do that, I can control and move the view, however I don’t have any cursor and can’t select or draw anything.

Is there a way to allowed the user to continue working during the macro ?

 

Thanks in advance,

 

Regards,

 

Paul

0 Likes
1,427 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor

When your VBA code does a lengthy looping execution, DoEvents would give AutoCAD chance to see if there is user interaction and/or graphics refresh needed. Usually, you only need to call GetAsyncKeyState([key/mouse button code]) when you only want to detect specific key/mouse button state.

 

However, in VBA code, after Doevents call, it is usually to do something for refresh UI (such as UserForm), or to see if a button on the UI is clicked (to stop the loop, or do something else/extra in the cycle of loop). So, that means, unless the loop is stoped after Doevents, your code execution in the loop continues. Since AutoCAD itself is a very resource-hungry desktop app, when it is busy in a lengthy process, it often takes up most, if not all CPU/momery available of the computer (depending on what the processing does, of course). At this moment the computer can often hardly be used for other tasks.

 

If by "user to continue working during the macro" means doing work with other applications than AutoCAD, then yes, user may be able to do something, if the computer is very good one (multi-core, a lot of memory), but my not be smooth. If you mean continuing working with the same AutoCAD session, practically, you cannot.

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks for your reply.

You confirmed what I understand of the function.

 

I mean continue working on Autocad. What I would like is having a small UserForm up during my work to have various informations inside, not necessarily always updating in realtime (I would like to froze the thread whenever I can to lessen the CPU burden). What bother me is that, without calling any other functions I'm able to move inside the autocad view but the other functions, as the selection seems, to be blocked.

 

I'm not a long time user but adding shortcuts to launch various macros seems too time consuming, inneficient and depends too much on the userconfiguration. That's why I wanted to have a small thread running in background . Is there another way to do that ?

 

Regards,

 

Paul

0 Likes