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

Call rejected by Callee?

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
1622 Views, 5 Replies

Call rejected by Callee?


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.

 

Thanks for any help!
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous


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

 

 Err().Clear() 
 ACADVer =
acad.Version.ToString()
End Sub

 

 

 
Message 3 of 6
thenrich
in reply to: Anonymous

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
Message 4 of 6
Anonymous
in reply to: Anonymous

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
Message 5 of 6
jnelso99
in reply to: Anonymous

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!
Message 6 of 6
herrwolf1
in reply to: Anonymous

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

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