Jump to content

Issue with calling a .NET LispFunction with a Reactor


ColinHolloway

Recommended Posts

Hi All,

 

I have just hit a wall with some code I am working on and wondered if anyone had seen a similar situation (and found a solution).

 

I have written a .NET routine that I use to control which Ribbon Menu Tabs and Panels are visible based on arguments passed to the routine. This runs correctly in AutoCAD 2016 when I call it from the command line or from inside a lisp function or command. However when I call the .NET routine from a reactor it fails:

 

Command: System.ArgumentNullException: Value cannot be null.
Parameter name: key
  at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
  at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
  at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
  at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.InvokeLisp(); error: ADS request error

 

EDIT: I have found that calling ANY command from a reactor fails e.g. (command "line" "0,0" "1000,1000") called by a reactor the error is:

Command: ; error: AutoCAD command rejected: "line"

 

Any and all thoughts greatly appreciated.

Colin

Edited by ColinHolloway
more information collected
Link to comment
Share on other sites

Yes, you cannot invoke a command from within a reactor callback function - a possible workaround is to invoke the command 'post-process' (using vla-sendcommand, for example).

Link to comment
Share on other sites

Hi Lee and Al,

 

Thank you for your replies.

 

I have added the vla-sendcommand call to my reactor and when I use it to do something "trivial" like zoom extents it works as expected, but when I call the .NET LispFunction it still fails:

 

(setq activedwg (vla-get-activedocument (vlax-get-acad-object)) )
(vla-SendCommand activedwg "(ribboncontrol \"Sedgman\" \"SedgCAD Legacy\" 0)\r")

 

 

Command: (ribboncontrol "Sedgman" "SedgCAD Legacy" 0)
System.ArgumentNullException: Value cannot be null.
Parameter name: key
  at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
  at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
  at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
  at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.InvokeLisp(); error: ADS request error
Command:

 

 

Note: If I paste (ribboncontrol "Sedgman" "SedgCAD Legacy" 0) directly to the command line it works as expected.

 

Is there an issue with calling a .NET LispFunction inside a reactor callback function even when using vla-sendcommand?

 

Maybe I need a completely fresh look at this problem...

What I am attempting to write is contextual ribbon menu control based on a variable set in the current drawing. The .NET Lisp Function I have written shows or hides a ribbon panel based on the arguments passed to it.

On drawing open I set a variable based on the folder the drawing was opened from and display the relevant panels in the ribbon menu. This works on startup, but I was hoping to be able to make the same change (if necessary) when switching drawing tabs (because each drawing can be opened from a different source). I have looked at contextual ribbon tabs in the CUI but that doesn't solve the issue of showing/hiding panels based on a local variable. Using a reactor to call my .NET routine seemed like the correct way to go, but I feel I am pushing the limits of what can be done. Thoughts?

 

Thanks again,

Colin

 

EDIT: I am developing this code in AutoCAD 2016 and on a hunch I fired up an AutoCAD 2014 machine and tried to run the code above... it worked perfectly. I was even able to remove the vla-SendCommand and call the .NET LispFunction (with required arguments) directly!!! What has changed in the calling of commands and .NET functions between 2014 and 2016?

Edited by ColinHolloway
New Information
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...