Jump to content

Recommended Posts

Posted

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?

Posted

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?

Posted
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---------------------

Posted

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. :reallymad:

Posted

I'm studying Application.AppDeactivate event now. Little progress. :reallymad:

 

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. :unsure:

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...