Modeless,AcFocusCtrl1 and GetEntity

Modeless,AcFocusCtrl1 and GetEntity

Anonymous
Not applicable
462 Views
3 Replies
Message 1 of 4

Modeless,AcFocusCtrl1 and GetEntity

Anonymous
Not applicable
Roughly I have a dialog box with the following
1. the main module sets my dialog to Modeless
2. One button to select an object “cmdGetObj”
3. one button to exit “cmdExit”

When I select the getobj button I am prompter to select an object.
(and possible I will have a loop to select objects)
The problem is that because the form is modless, I can also select the exit button……
But the exit only unloads the form and the user is still prompted to select a point.
How can I set it up so that the cmdExit will not only unload the form but will also exit the “getEntity” or any other command ?


'main program
UserForm1.Show modeless
UserForm1.AcFocusCtrl1.KeepFocus = True


Private Sub cmdGetObj_Click()
ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select object to revise"
Endsub


Private Sub cmdExit_Click()
Unload Me
End Sub
0 Likes
463 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
You could handle it in two ways (may be more) to not allow user to close the
form until picking is done.

1. Set a UserForm level flag to indicate now is picking or not. If is, you
will not allow form to be closed. The code looks like:

Private picking as Boolean

Private Sub CommandButton1_Click()

On Error Resume Next

'Set picking flag
picking = True

Dim basePnt As Variant
Dim returnObj As AcadEntity

ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select object to
revise"

'Clear picking flag
picking = False

If returnObj Is Nothing Then
MsgBox "No entity is picked."
Else
MsgBox "Entity is picked."
End If

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

If picking Then
Cancel = 1
Exit Sub
End If

'Other cleaning up code when UserForm is closing

End Sub


2. You can disable UserForm during picking, so it cannot be closed until
picking is done. The code lopks like:

Private Sub CommandButton1_Click()

On Error Resume Next

'Disable the form
Me.Enabled = False

Dim basePnt As Variant
Dim returnObj As AcadEntity

ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select object to
revise"

'Enable the form back
Me.Enabled = True

If returnObj Is Nothing Then
MsgBox "No entity is picked."
Else
MsgBox "Entity is picked."
End If

End Sub


wrote in message news:5452343@discussion.autodesk.com...
Roughly I have a dialog box with the following
1. the main module sets my dialog to Modeless
2. One button to select an object "cmdGetObj"
3. one button to exit "cmdExit"

When I select the getobj button I am prompter to select an object.
(and possible I will have a loop to select objects)
The problem is that because the form is modless, I can also select the exit
button..
But the exit only unloads the form and the user is still prompted to select
a point.
How can I set it up so that the cmdExit will not only unload the form but
will also exit the "getEntity" or any other command ?


'main program
UserForm1.Show modeless
UserForm1.AcFocusCtrl1.KeepFocus = True


Private Sub cmdGetObj_Click()
ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select object to revise"
Endsub


Private Sub cmdExit_Click()
Unload Me
End Sub
0 Likes
Message 3 of 4

Anonymous
Not applicable
thanks Norman

But I was hoping that there was a way that in the cmdExit not only could I undload the form but also terminate the command. ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select object"
I guess that is how I should have worded my query in the first place, in this discussion group.

All the same I appreciate your effort in replying....Thanks
0 Likes
Message 4 of 4

Anonymous
Not applicable
Can someone please comment if this is good programming practice, normally I am against using the sendcommand in VBA.

to exit out of the getEntity I have revised my cmdExit to the following, the chr(3) sends an ESC key to the command prompt.

Private Sub cmdExit_Click()
ThisDrawing.SendCommand Chr(3)
Unload Me

End Sub
0 Likes