Execute code

Execute code

Anonymous
Not applicable
467 Views
3 Replies
Message 1 of 4

Execute code

Anonymous
Not applicable
Hi...

I wish that when I load a DLL into AutoCAD running a code, but if I load in another document also it run.

I've tried with Initialize and Terminate but it does not work:

Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

Public Sub Initialize() Implements IExtensionApplication.Initialize
...
End Sub

Public Sub Terminate() Implements IExtensionApplication.Terminate
...
End Sub

how I can do it?

Thanks you
0 Likes
468 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

You may want to look into events raised by
DocumentCollection, such as DocumentBecameCurrent/DocumentActivated... You would
place code into appropriate event handler to get it run when a document becomes
active or current (make sure you correctly understand the difference between
DocumentBecameCurrent and DocumentActivated...lots of try-and-see would help you
to decide whatevent you want to handle).

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hi...
I wish that when I load a DLL into AutoCAD running a code, but if I load in
another document also it run. I've tried with Initialize and Terminate but it
does not work: Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize ... End
Sub Public Sub Terminate() Implements IExtensionApplication.Terminate ... End
Sub how I can do it? Thanks you
0 Likes
Message 3 of 4

Anonymous
Not applicable
Ok... But, Do you have an example?, please...

Thanks you
0 Likes
Message 4 of 4

Anonymous
Not applicable

Off my head, here is some quick code (not tested,
not written in VS, so could be wrong):

 

namespce MySpance

{

    public class MyClass:
IExtensionApplication

    {

        static
DocumentColelction mDwgManager=null;

       
...

       
...

 

        public void
Initialize()

       
{

       
    //I alway put try...catch block, just in casesomething
unexpected occurs

       
    try

       
    {

       
       
mDwgManager=Application.DocumentManager;

       
       

       
        //Handle DocumentBecameCurrent event,
which might be the most suitable to your requirement

       
        //But you may also want to try different
events based on your need

       
        mDwgManager,DocumentBecameCurrent+=new
DocumentCollectionEventHandler(MyDoucment_BecameCurrent)

       
    }

       
    catch

       
    {

       
        //Do something if necessary

       
    }

       
}

 

        //Handle
event

        private
static void MyDocument_BecameCurrent(object sender, DocumentCollectionEventArgs
e)

       
{

       
    //Get the current document

       
    Document dwg=e.Document

 

       
    //You can also simply do this:

       
    //Document dwg=mDwgManager.MdiActiveDocument

 

       
    //Now that you have obtained the current drawing, which is
active, you can run code against it

       
    DoProcess(dwg);

       
}

    }

}

 

HTH.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Ok...
But, Do you have an example?, please... Thanks you
0 Likes