.NET
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
*pkirill
Call rejected by Callee?
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
687 Views, 5 Replies
07-20-2005 05:15 AM
I've got a batch processing program that was
created in .NET. So far, so good - but the main issue I have left to resolve is
that if AutoCAD is open and the user has left a command active in one of the
document windows (2005 and/or 2006), the processor throws an exception "Call was
rejected by callee". Can anyone help me with a way to get the processor look for
an active command and if found, cancel it? I'm assuming a try/catch will
do it, I just don't know how to format it.
created in .NET. So far, so good - but the main issue I have left to resolve is
that if AutoCAD is open and the user has left a command active in one of the
document windows (2005 and/or 2006), the processor throws an exception "Call was
rejected by callee". Can anyone help me with a way to get the processor look for
an active command and if found, cancel it? I'm assuming a try/catch will
do it, I just don't know how to format it.
Thanks for any help!
*pkirill
Re: Call rejected by Callee?
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-20-2005 05:19 AM in reply to:
*pkirill
This is my "Detect AutoCAD" sub if it's any
help...
Sub DetectAcadSession()
blnAcadExist =
False
On Error Resume Next
acad = GetObject(,
"autocad.application")
If Err().Number <> 0
Then
blnAcadExist =
False
acad = New
AcadApplication
While blnAcState =
False
AcState =
acad.GetAcadState
If AcState.IsQuiescent
Then
blnAcState =
True
End
If
End While
Else
blnAcadExist =
True
End If
help...
Sub DetectAcadSession()
blnAcadExist =
False
On Error Resume Next
acad = GetObject(,
"autocad.application")
If Err().Number <> 0
Then
blnAcadExist =
False
acad = New
AcadApplication
While blnAcState =
False
AcState =
acad.GetAcadState
If AcState.IsQuiescent
Then
blnAcState =
True
End
If
End While
Else
blnAcadExist =
True
End If
Err().Clear()
ACADVer =
acad.Version.ToString()
End Sub
ACADVer =
acad.Version.ToString()
End Sub
Re: Call rejected by Callee?
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-25-2005 06:21 AM in reply to:
*pkirill
Kill the active command
Public Function KillAutoCADCommand(ByVal AcadDoc As AutoCAD.AcadDocument) As Boolean
''' 10.19.04 TMH Made argument optional so you can just grab the current AutoCAD instance.
Dim AutoCADPending As Boolean = True
Dim strTemp As String
Dim i As Integer
Try
EnumWindows(AddressOf EnumWinProc, 0)
PostMessage(gAutoCADHwnd, WM_KEYUP, 27, 0)
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
' The following loop needs to be performed in order to make sure the
' PostMessage API has performed the cancel in AutoCAD before proceeding
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
Do Until AutoCADPending = False
Try
strTemp = AcadDoc.Name
AutoCADPending = False
Catch ex As Exception
AutoCADPending = True
End Try
Loop
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Public Function KillAutoCADCommand(ByVal AcadDoc As AutoCAD.AcadDocument) As Boolean
''' 10.19.04 TMH Made argument optional so you can just grab the current AutoCAD instance.
Dim AutoCADPending As Boolean = True
Dim strTemp As String
Dim i As Integer
Try
EnumWindows(AddressOf EnumWinProc, 0)
PostMessage(gAutoCADHwnd, WM_KEYUP, 27, 0)
''''''''''''''''''''''''''''''''''''''''''''''''''
' The following loop needs to be performed in order to make sure the
' PostMessage API has performed the cancel in AutoCAD before proceeding
''''''''''''''''''''''''''''''''''''''''''''''''''
Do Until AutoCADPending = False
Try
strTemp = AcadDoc.Name
AutoCADPending = False
Catch ex As Exception
AutoCADPending = True
End Try
Loop
''''''''''''''''''''''''''''''''''''''''''''''''''
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
*pkirill
Re: Call rejected by Callee?
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-27-2005 08:51 AM in reply to:
*pkirill
That's great - Much Thanks!
Paul
wrote in message news:4909926@discussion.autodesk.com...
Kill the active command
Public Function KillAutoCADCommand(ByVal AcadDoc As AutoCAD.AcadDocument) As
Boolean
''' 10.19.04 TMH Made argument optional so you can just grab the
current AutoCAD instance.
Dim AutoCADPending As Boolean = True
Dim strTemp As String
Dim i As Integer
Try
EnumWindows(AddressOf EnumWinProc, 0)
PostMessage(gAutoCADHwnd, WM_KEYUP, 27, 0)
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
' The following loop needs to be performed in order to make sure
the
' PostMessage API has performed the cancel in AutoCAD before
proceeding
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
Do Until AutoCADPending = False
Try
strTemp = AcadDoc.Name
AutoCADPending = False
Catch ex As Exception
AutoCADPending = True
End Try
Loop
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Paul
Kill the active command
Public Function KillAutoCADCommand(ByVal AcadDoc As AutoCAD.AcadDocument) As
Boolean
''' 10.19.04 TMH Made argument optional so you can just grab the
current AutoCAD instance.
Dim AutoCADPending As Boolean = True
Dim strTemp As String
Dim i As Integer
Try
EnumWindows(AddressOf EnumWinProc, 0)
PostMessage(gAutoCADHwnd, WM_KEYUP, 27, 0)
''''''''''''''''''''''''''''''''''''''''''''''''''
' The following loop needs to be performed in order to make sure
the
' PostMessage API has performed the cancel in AutoCAD before
proceeding
''''''''''''''''''''''''''''''''''''''''''''''''''
Do Until AutoCADPending = False
Try
strTemp = AcadDoc.Name
AutoCADPending = False
Catch ex As Exception
AutoCADPending = True
End Try
Loop
''''''''''''''''''''''''''''''''''''''''''''''''''
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Re: Call rejected by Callee?
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-01-2005 02:23 PM in reply to:
*pkirill
Hi -
I think I am experiencing the same kind of problem that the OP has. What I am trying to do is open up a file, go through all of the block references and explode with the "-explode" command. I'm doing this through VB.NET via a "SendCommand" call. I know the handle to the block ref, so I do this:
acadDoc.SendCommand("(command ""-explode"" (handent """ & strHandle & """))" & vbCrLf)
The problem is that works once, and subsequent calls blow up with the "call rejected by callee" exception. I'm suspecting it's the same deal as the OP. One other wierdness is when I call that, AutoCAD's help file pops up. AutoCAD's main window also tends to want to show itself as well, no matter what I set it's visibility to.
With that said, I'm trying to get this EnumWindows thing working, and I was wondering if you could post the rest of the code. I'm having problems declaring the Win32 API functions, and nothing I've found on the web is working. I'm assuming that something like this should work:
Public Delegate Function CallBack(ByVal handle As Integer, ByVal param As Integer) As Boolean
Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As CallBack, _
ByVal lParam As Integer) As Integer
Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, _
ByVal lpString As String, ByVal cch As Long) As Long
Private Const WM_KEYUP As Long = &H101
Public Function WndEnumProc(ByVal handle As Integer, _
ByVal param As Integer) As Boolean
Dim lResult As Long
Dim sWndName As String
WndEnumProc = 1
lResult = GetWindowText(handle, sWndName, 255)
' And I assume that if sWndName has "AutoCAD" in it
' or something like that, we set gAutoCADHwnd to it
End Function
I have to do the "Callback" thing apprarently because the AddressOf thing needs it based on the MSDN docs.
The problem I see is that GetWindowText is not giving me anything at all. lResult is garbage. If I set a breakpoint and go through, I get LOTS AND LOTS of handles, seemingly more than I expect, and nothing with which GetWindowText works.
One other question tho - Instead of using EnumWindows, why not use AcadApplication.HWND? I still don't have any success doing a PostMessage to that, but I'm still curious. I know this is a hairy question, but any help is appreciated.
Thanks!
I think I am experiencing the same kind of problem that the OP has. What I am trying to do is open up a file, go through all of the block references and explode with the "-explode" command. I'm doing this through VB.NET via a "SendCommand" call. I know the handle to the block ref, so I do this:
acadDoc.SendCommand("(command ""-explode"" (handent """ & strHandle & """))" & vbCrLf)
The problem is that works once, and subsequent calls blow up with the "call rejected by callee" exception. I'm suspecting it's the same deal as the OP. One other wierdness is when I call that, AutoCAD's help file pops up. AutoCAD's main window also tends to want to show itself as well, no matter what I set it's visibility to.
With that said, I'm trying to get this EnumWindows thing working, and I was wondering if you could post the rest of the code. I'm having problems declaring the Win32 API functions, and nothing I've found on the web is working. I'm assuming that something like this should work:
Public Delegate Function CallBack(ByVal handle As Integer, ByVal param As Integer) As Boolean
Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As CallBack, _
ByVal lParam As Integer) As Integer
Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, _
ByVal lpString As String, ByVal cch As Long) As Long
Private Const WM_KEYUP As Long = &H101
Public Function WndEnumProc(ByVal handle As Integer, _
ByVal param As Integer) As Boolean
Dim lResult As Long
Dim sWndName As String
WndEnumProc = 1
lResult = GetWindowText(handle, sWndName, 255)
' And I assume that if sWndName has "AutoCAD" in it
' or something like that, we set gAutoCADHwnd to it
End Function
I have to do the "Callback" thing apprarently because the AddressOf thing needs it based on the MSDN docs.
The problem I see is that GetWindowText is not giving me anything at all. lResult is garbage. If I set a breakpoint and go through, I get LOTS AND LOTS of handles, seemingly more than I expect, and nothing with which GetWindowText works.
One other question tho - Instead of using EnumWindows, why not use AcadApplication.HWND? I still don't have any success doing a PostMessage to that, but I'm still curious. I know this is a hairy question, but any help is appreciated.
Thanks!
Re: Call rejected by Callee?
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-27-2010 10:44 AM in reply to:
*pkirill
Hello,
I'm using VB.Net 2008 and the following lines of code from your post do not work for me.
EnumWindows(AddressOf EnumWinProc, 0)
PostMessage(gAutoCADHwnd, WM_KEYUP, 27, 0)
What do I need to do to make these work?
Thank you,
Eric
I'm using VB.Net 2008 and the following lines of code from your post do not work for me.
EnumWindows(AddressOf EnumWinProc, 0)
PostMessage(gAutoCADHwnd, WM_KEYUP, 27, 0)
What do I need to do to make these work?
Thank you,
Eric
