Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Woes while calling AcadDocument.SendCommand from a Form

37 views
Skip to first unread message

Mark Webb (Autodesk - ADT Software Engineer)

unread,
Jun 17, 1999, 3:00:00 AM6/17/99
to
I've noticed some peculiarity which I cannot seem to work around..
 
The problem is that I have a form which, for example, switches to AutoCAD to request a pickPoint from the user. Attempting the following code is expected to work, as this is how it is documented
 
  Public Sub btnGetPoint_Click()
    Dim pt As Variant
    Me.Hide
    pt = ThisDrawing.Utility.GetPoint()
    Me.Show
 
    ' do some work with the point
    MsgBox "Picked point(x,y): " & Str$(pt(0)) & ", " & Str$(pt(1))
 
  End Sub
 
The form hides okay, the command runs okay, and the form shows again afterwards. The problem is that the code after Me.Show never gets executed until the form is ultimately closed down. *Very strange* behaviour indeed. Especially in this instance when the message box appears a long time after it was expected :-)
 
The obvious workaround is to do the following
 
  Public Sub btnGetPoint_Click()
    Dim pt As Variant
    Me.Hide
    pt = ThisDrawing.Utility.GetPoint()
    ' do some work with the point
    MsgBox "Picked point(x,y): " & Str$(pt(0)) & ", " & Str$(pt(1))
 
    Me.Show
    'make sure no other code is written after the Me.Show call
  End Sub
 
Anybody have any insights into this one?
--
Mark Webb
Software Engineer, AutoCAD Architectural Desktop
Autodesk, UK
 mark...@eur.autodesk.com
 http://www.autodesk.com/archdesktop

Richard D. Howard [Autodesk GIS]

unread,
Jun 17, 1999, 3:00:00 AM6/17/99
to

Mark Webb (Autodesk - ADT Software Engineer) wrote in message
<7kavrd$9p...@adesknews2.autodesk.com>...

>
>I've noticed some peculiarity which I cannot seem to work around..
>

Hi Mark,

I can confirm what you're seeing - it's been that way since
at lease 14.01, so it's not something specific to A2K.

rdh.


John Pierson

unread,
Jun 22, 1999, 3:00:00 AM6/22/99
to
Answer is quite simple really, weird, but simple. Let's look at what
happens. Form gets loaded. Then you click your button. The button hides
the form, the user picks a pont (which how do you do that, I can't get that
code to work). Then it shows the form, BUT it does not resume the code.
It's a NEW instance of the form. Almost as if you created a new form, but
it doesn't call the initialize event. How do I know this? Well, I did this:

Public Sub btnGetPoint_Click()
Dim pt As Variant
Me.Hide

MsgBox "test1"

Me.Show
MsgBox "text2"


'make sure no other code is written after the Me.Show call
End Sub


What happens? Well, like you expect, the code hides the form, does a
message box containing "test1" then the Form is redisplayed. If you close
this form, you get the display "test2". Now here's the interesting part.
If instead of closing the form, I hit the button a few times, something
changes. I get "test1" in each instance, but upon closing the form, for
ever time that I click the button, I now have that many message boxes
containing "test2" in them that I must dismiss. So, like I said, it's
almost like it's starting a new instance of the form, without triggering the
initialize events. It doesn't pick up where it left off.

John


Richard D. Howard [Autodesk GIS] wrote in message
<7kbr0g$cq...@adesknews2.autodesk.com>...


>
>Mark Webb (Autodesk - ADT Software Engineer) wrote in message
><7kavrd$9p...@adesknews2.autodesk.com>...
>>

>>I've noticed some peculiarity which I cannot seem to work around..
>>
>

Denis Gagné

unread,
Jun 22, 1999, 3:00:00 AM6/22/99
to
John-Richard and Mark,

Aren't you complicating something intended to be simple?

When you show a Modal Dialog / UserForm, "no subsequent code is executed
until the Dialog / UserForm is hidden or unloaded". This is by design.

And it also happens when you show the SAME INSTANCE of your hidden UserForm
which is still a Modal Form.

" MsgBox "text2" " is subsequent code. It is not executed unless you unload
the form or ... you use my modeless control.

Cheers

Denis

Mark Webb (Autodesk - ADT Software Engineer)

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to
This is going further than I expected :-)

Personally I cannot see how this was *As Design*, as it is pretty
unintuitive behaviour. I've never known Win32 preventing subsequent calls to
be delayed after a ShowWindow(SW_SHOW)

Once you know the problem and how to get around it, this doesn't really
become an issue, so putting Me.Show as the last call in the routine is
fine...

--
Mark Webb
Software Engineer, AutoCAD Architectural Desktop
Autodesk, UK
mark...@eur.autodesk.com
http://www.autodesk.com/archdesktop

Denis Gagné <de...@videotron.ca> wrote in message
news:7kpfio$7t...@adesknews2.autodesk.com...

Denis Gagné

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to
Hi Mark,

>This is going further than I expected :-)

This is an interesting subject for discussion that could go further.

I just may not have found the right words to express a different point of
view and I'm very sorry


>
>Personally I cannot see how this was *As Design*, as it is pretty
>unintuitive behaviour. I've never known Win32 preventing subsequent calls
to
>be delayed after a ShowWindow(SW_SHOW)
>

This may be limitative but isn't modality an intended limitation?

>Once you know the problem and how to get around it, this doesn't really
>become an issue, so putting Me.Show as the last call in the routine is
>fine...


Yes, except for an event procedure.

The only workaround I know is to use the Activate Event to maintain the
activity after a UserForm becomes active. Unfortunately this event is
triggered only once and you will have to Unload the Userform instead of
hiding it.

Code for UserForm1:

Private Sub CommandButton1_Click()
testContinue
End Sub

Private Sub UserForm_Activate()
Select Case Caption
Case "Continue"
testContinue
'Case...
End Select
End Sub


Code for Module1.bas:

Public Sub testContinue()
Static Continue As Boolean

If Not Continue Then

Unload UserForm1
'Here you can interact with AutoCAD
' using ThisDrawing.Utility.GetPoint()
MsgBox "Before"
Continue = True

'Set the Caption for an appropriate action
UserForm1.Caption = "Continue"

'Show a new instance of the UserForm
UserForm1.Show

Else

'Action that will take place after
'the new instance of UserForm1
'is activated
Continue = False
UserForm1.Caption = "UserForm1"
MsgBox "After"

End If

End Sub


Salutations

Denis


Jorge Lopez

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to
Et all,

Unintuitive yes, but this is expected and makes sense. VBA forms must be
MODAL. This means that Me.Show starts a modal state while Me.Hide ends the
modal state.

Eg.

Sub Confusion()
UserForm1.Show ' Begins modal state
MsgBox "Hi" ' does not display until modal state ends;
' since a new modal state was created
' this does not execute until the
modal
' state created in
CommandButton1_Click()
' ends
End Sub


Private Sub CommandButton1_Click()
Me.Hide ' Ends modal state from Sub Confusion
MsgBox "Test" ' Displays immediately
Me.Show ' Begins new modal state
MsgBox "Test2" ' does not display until modal state ends
End Sub

In C++, Me.Show is equivalent to calling DoModal() and not ShowWindow().

Cheers,


Jorge


Denis Gagné wrote in message <7kqp9s$9s...@adesknews2.autodesk.com>...

0 new messages