.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cancel command, CMDACITVE ??

8 REPLIES 8
Reply
Message 1 of 9
wesbird
631 Views, 8 Replies

Cancel command, CMDACITVE ??

Hi,
Now I have to problem to cancel current command, now the situation is, I create a palette with list box. when user click a item in the listbox, I will insert a block, draw line/pline, etc according the item user picked. My problem is, when user pick the 1st item, my function in the palette will ask to pick a point, at this time, if user pick another item, I need to cancel 1st function.
I tried, acedPostCommand(Chr(3)) which will cancel previous one which is fine, but it also cancel current one.

I use the listbox SelectedIndexChanged event (code attached0.
I am thinking to check CMDACTIVE system variable and found it is not in the .net. so how I can check when should I send ^C to cancel the command?
both
acedPostCommand(Chr(3) + Chr(3) + Chr(3))
acedPostCommand(Chr(3))
not working

I really appreciate your help. thank you very much

[code]
Private Sub lstItems_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstItems.SelectedIndexChanged

'' debug
'DDebug.WriteLog("IRRAPalette.lstItems_SelectedIndexChanged: " & _drvData.Row("item_name"))

If _IsInit Then Exit Sub

If lstItems.SelectedIndex > -1 Then

_drvData = lstItems.SelectedItem

'' ^C^C^C
'acedPostCommand(Chr(3) + Chr(3) + Chr(3))
acedPostCommand(Chr(3))

Dim myPart As New MyPart
' Insert
myPart.Insert(_drvData)

End If
End Sub
[/code]

Wes
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
8 REPLIES 8
Message 2 of 9
cgay
in reply to: wesbird

weslleywang,

You could prevent the user from selecting another item until they either cancel or place the first item.

I.E.
1. user selects an item
2. you disable the list box
3. you prompt them for the place point
4. they realize they want a different object
5. they press escape
6. your code flow moves to the end of the event procedure and you unlock the list box
7. the choose a different item

This eliminates the need for your code to cancel the active command since it is your command that was active, so when your event ends, it is safe for them to pick a different item.

C
Message 3 of 9
wesbird
in reply to: wesbird

good idea, I will try it.


Thank you,

Wes
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
Message 4 of 9
wesbird
in reply to: wesbird

thank you, C. It works.

But how I can disable other tab of the same palette?

Thank you,


Wes
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
Message 5 of 9
cgay
in reply to: wesbird

Not too sure what you mean.

Are you just trying to disable the other controls on a palette you created?

Any chance of some code or a screenshot?

C
Message 6 of 9
wesbird
in reply to: wesbird

There are multiple tab in my palette, like, pipe, valve and misc. if I start at pipe, click a item in pipe list, pipe list box get disabled. There is still a chance user could click valve tab, click item in valve listbox. That is why I like to disable all tab.
Is this clear?
Thanks for your help



Wes
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
Message 7 of 9
cgay
in reply to: wesbird

Wes,

I think I see what you are after. Instead of disabling the listbox, try to disable the form.

Assuming your palette is named Pallet1

Try
Pallet1.Enabled = False
'Other code here
Finally
Palet1.Enabled = True
End Try

You need to wrap this in a Try-Finally block in case there is an error, you want to be able to select something else.

C
Message 8 of 9
wsteed
in reply to: wesbird

I realize it's way after the fact, but this may help others with this same problem. A couple years ago I was able to use the "PostMessage" user32 function to cancel the current autocad command before I began processing my code.
Just call CancelAcadCommand before you begin interaction with AutoCAD.
The code would look something like this:

'***Declarations***

'************* THESE ARE USED BY THE AutoCAD CancelCommand() ***************
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumWindowsDelegate, ByVal lParam As Integer) As Integer
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Integer, ByVal lpEnumFunc As EnumChildWindowsDelegate, ByVal lParam As Integer) As Boolean
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Const WM_KEYDOWN As Integer = &H100
Public Const WM_KEYUP As Integer = &H101
Public gAutoCADHwnd As Integer
Public Delegate Function EnumWindowsDelegate(ByVal hWnd As Integer, ByVal lParam As Integer) As Boolean
Public Delegate Function EnumChildWindowsDelegate(ByVal hWnd As Integer, ByVal lParam As Integer) As Boolean
'***************************************************************************

Public Sub CancelAcadCommand()
Try
EnumWindows(AddressOf fEnumWinProc, 0)

If gAutoCADHwnd <> 0 Then
PostMessage(gAutoCADHwnd, WM_KEYUP, 27, 0)
PostMessage(gAutoCADHwnd, WM_KEYUP, 27, 0)
End If

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Function fEnumWinProc(ByVal hWnd As Integer, ByVal lParam As Integer) As Boolean
Dim pRetval As Integer
Dim pBuf As New String(" "c, 256)

pRetval = GetWindowText(hWnd, pBuf, pBuf.Length)

'the buffer will 255 chars which will contain the useful strings plus rest of them will be '0's
Dim psStr As String
psStr = Split(pBuf, Chr(0))(0)

'check for AutoCAD
If psStr = vbNullString Then
fEnumWinProc = True
Exit Function
End If

If psStr.ToLower.IndexOf("autocad") >= 0 Then
EnumChildWindows(hWnd, AddressOf fEnumChildProc, 0)
fEnumWinProc = False
Else
fEnumWinProc = True
End If
End Function

Function fEnumChildProc(ByVal hWnd As Integer, ByVal lParam As Integer) As Boolean
Dim pRetval As Integer
Dim pBuf As New String(" "c, 256)

pRetval = GetWindowText(hWnd, pBuf, pBuf.Length)

Dim psStr As String
psStr = Split(pBuf, Chr(0))(0)

'check for Command Window "HeadLands"
If psStr = vbNullString Then
fEnumChildProc = True
Exit Function
End If

If psStr.ToLower.IndexOf("headlands") >= 0 Then
gAutoCADHwnd = hWnd
fEnumChildProc = False
Else
fEnumChildProc = True
End If
End Function
Message 9 of 9
SRSDS
in reply to: wsteed

I have the same problem. Disabling the each tab container in the pallete would work but the alternative posted by wsteed would be much cleaner. Problem is I can't follow it and don't know why it's not working.

 

I've read every cancel command thread but can't seem to find anything. Sending ^c cancels the previous command as well as the current. Is anyone using something similar or is able suggest an alternative?  

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost