cclemon Posted August 10, 2009 Posted August 10, 2009 I have just used VBA in autocad for a while and got stuck with a problem. I try to write a do-loop-while of utility.getentity to collect lines in a drawing by interacting with a modeless userform. Besides, using "ESC" or not selecting at all, I want to stop the input by clicking a button on my userform, but I can't figure it out. How can I stop getentity by clicking a button on userform? Quote
SEANT Posted August 10, 2009 Posted August 10, 2009 I’ve never worked with VBA modeless forms, so I’m just surmising here, but what if the routine were set up to respond to an Application.AppDeactivate event? It may allow for a graceful exit out of the loop. As an aside: Is there a reason to use a looped utility.getentity instead of a SelectionSet.SelectOnScreen? Quote
rocheey Posted August 10, 2009 Posted August 10, 2009 I have just used VBA in autocad for a while and got stuck with a problem. I try to write a do-loop-while of utility.getentity to collect lines in a drawing by interacting with a modeless userform. Besides, using "ESC" or not selecting at all, I want to stop the input by clicking a button on my userform, but I can't figure it out. How can I stop getentity by clicking a button on userform? below is some generic code, when put on a userform, that will allow a button click to break out of a loop running in another subroutine. Clcking the 'cmdStartLoop' button starts the loop by running the subroutine called 'LoopMe'. The LoopMe sub checks to see if a module level variable called 'UserCancelled' is changed to true. if your looping code is in another module, then make your ''UserCancelled' ' varible Global ... '---------------- snip----------------- ' Module level code: Dim UserCancelled As Boolean Sub LoopMe() UserCancelled = False Do DoEvents If UserCancelled = True Then MsgBox "user cancelled" Exit Do End If Loop End Sub Private Sub cmdEndLoop_Click() UserCancelled = True End Sub Private Sub cmdStartLoop_Click() LoopMe End Sub '---------------- snip--------------------- Quote
cclemon Posted August 11, 2009 Author Posted August 11, 2009 Thank you, SEANT and rocheey. Actually, my code is something like: ------------------------------------- Do On Error Resume Next ThisDrawing.Utility.GetEntity ent, ptpick If Not (ent Is Nothing) Then ... Check the entity ... Retrieve info basing on its handle from a table ... Toggle its color ... etc ... End if Loop Until (ent Is Nothing) ------------------------------------- So the method given by rocheey may not work here, because it requires me to pick another entity to get out of the GenEntity first. I'm studying Application.AppDeactivate event now. Little progress. Quote
SEANT Posted August 11, 2009 Posted August 11, 2009 I'm studying Application.AppDeactivate event now. Little progress. In retrospect, my suggestion regarding Application.AppDeactivate may be more appropriate for an out of process (VB6 EXE Modeless Form) routine. Given that a VBA routine is still within the host process, a switch to the form may not generate an AutoCAD deactivate event. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.