Author Topic: Events.....  (Read 2306 times)

0 Members and 1 Guest are viewing this topic.

wannabe

  • Guest
Events.....
« on: March 09, 2009, 04:56:33 PM »
Does anyone have a link to some example code that shows the use of events in ACAD?

Specifically, I would like to see how we could have some of our code run when something in ACAD happens. Say I used the distance command on a 3D polyline. I would then like a messagebox to pop up and say "the distance is along a 3D polyline and may not be planar to the current view".

There are probably better examples. But I'm sure you understand my intentions.

Basically, 'how do I run code without netloading', is probably a simplified version or how do I set up callbacks from native commands; or can I subscribe to events and setup callbacks from native commands?

Cheers.
« Last Edit: March 09, 2009, 05:00:39 PM by wannabe »

Glenn R

  • Guest
Re: Events.....
« Reply #1 on: March 09, 2009, 07:08:08 PM »
As far as running code without NETLOAD'ing, look up 'Demand Loading' in the documentation.

Glenn R

  • Guest
Re: Events.....
« Reply #2 on: March 09, 2009, 07:12:21 PM »
...events, per se, are a whole different kettle of fish and in my opinion, require a fairly deep understanding of not only the object model you program against, but AutoCAD itself.

wannabe

  • Guest
Re: Events.....
« Reply #3 on: March 10, 2009, 08:52:50 AM »
Demand loading isn't something we can somehow appent to a native command, is it?

I saw Kean's blog about selecting too many entities and the some alternative options dialog that ensues. I'll dig it up and report back with modified questions.

Glenn R

  • Guest
Re: Events.....
« Reply #4 on: March 10, 2009, 09:05:25 AM »
'appent'???

In the 2008 ARX docs, search for the section 'Deman Loading for .NET Applications'. It has 2 topics:

1. Loading .NET Applications on AutoCAD Startup.
2. Loading .NET Modules on Command Invocation.

That should set you on the right path.

wannabe

  • Guest
Re: Events.....
« Reply #5 on: March 10, 2009, 01:45:53 PM »
I meant append, sorry. Cheers for the comments.

TonyT

  • Guest
Re: Events.....
« Reply #6 on: March 11, 2009, 05:22:38 PM »
Demand-loading is where you register an ARX extension
to be loaded automatically when one of the commands
it implements is first invoked.

For handling events, you can't use demand loading because
there's no way to tell AutoCAD that an extension should be
loaded when an event occurs.

So, you must load at startup for event-driven applications.

You don't have to explicitly NETLOAD your app, you can
also register it to load when AutoCAD starts as well. There
should be something on Kean's blog that shows how to do
that, but I don't have any specific links handy.
   
Typically, the pattern involves using IExtensionApplication
to have AutoCAD call your assembly when it loads, where
you can add handlers for application-level events.

For document-level events, you must add handlers for the
DocumentCollection's DocumentAdded/ToBeDestroyed events,
and in the handlers of those events, you add/remove handlers
for document-level events.

The specific example that you gave, would be fairly complicated,
because it would involve handling selection-based events, and
in those events, you would check to see what command is in-
progress, and act accordingly. The Editor class exposes events
that allow you to examine the objects selected by the user, and
even add/remove them.

The example case you describe might be more easily done by
simply implementing an alternative command that can be used
in lieu of the built-in command.

Demand loading isn't something we can somehow appent to a native command, is it?

I saw Kean's blog about selecting too many entities and the some alternative options dialog that ensues. I'll dig it up and report back with modified questions.

wannabe

  • Guest
Re: Events.....
« Reply #7 on: March 12, 2009, 01:52:06 PM »
I sent and received an email from Kean who responded with a similar comment to yours. Although he also asserted that the new overrule function could also be a useful stage of the methodology.

There are no plans to make any code that is contingent on such functions; it was all just hypothetical at this point.

Input appreciated.