.NET

Reply
Contributor
annse
Posts: 15
Registered: ‎04-04-2012
Message 1 of 18 (491 Views)
Accepted Solution

Override default commands

491 Views, 17 Replies
04-04-2012 03:01 AM

Hi!

 

I'm trying to do something like this:

 

[Autodesk.AutoCAD.Runtime.CommandMethod("REFEDIT", Autodesk.AutoCAD.Runtime.CommandFlags.UsePickSet)]
public void RefEdit()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;

 

if (doc is a document I care about))
{
do my stuff...
}
else
{

run the default command...
}
}

 

I haven't undefined the default command, my definition of REFEDIT executes anyway.

I wanna be able to run the default command from my definition.

 

doc.SendStringToExecute(".REFEDIT ", true, false, false); will loop forever.

 

ADN Support Specialist
Balaji_Ram
Posts: 666
Registered: ‎03-21-2011
Message 2 of 18 (483 Views)

Re: Override default commands

04-04-2012 05:40 AM in reply to: annse

Hi,

 

I tried this which is very similar to what you are trying and it worked ok.

With this code, the line command is redefined only for drawings that have "Test" in their name.

 

Can you try this and see if it works for you ?

Maybe it will then help you identify the reason for your code to loop indefinitely.

 

// Add reference to Autodesk.AutoCAD.Interop 
// Add reference to Autodesk.AutoCAD.Interop.Common
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;

[CommandMethod("LINE")]
static public void LineMethod()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    if (doc.Name.Contains("Test"))
        ed.WriteMessage("My implementation of line");
    else
    {
        AcadApplication app = (AcadApplication)Application.AcadApplication;
        app.ActiveDocument.SendCommand("_.LINE ");
        ed.WriteMessage("My implementation of line");
    }
}
    
void IExtensionApplication.Initialize()
{
    AcadApplication app = (AcadApplication)Application.AcadApplication;
    app.ActiveDocument.SendCommand("_.UNDEFINE _LINE ");
}

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Contributor
annse
Posts: 15
Registered: ‎04-04-2012
Message 3 of 18 (473 Views)

Re: Override default commands

04-04-2012 06:58 AM in reply to: Balaji_Ram

Thank you for your quick response!

 

I've added required references and I now use SendCommand instead of SendStringToExecute.

This will still loop indefinitely. (If doc.Name doesn't contain "Test")

 

public void Initialize()
{

AcadApplication app = (AcadApplication)Application.AcadApplication;
app.ActiveDocument.SendCommand("_.UNDEFINE _REFEDIT ");
}

 

[Autodesk.AutoCAD.Runtime.CommandMethod("REFEDIT", Autodesk.AutoCAD.Runtime.CommandFlags.UsePickSet)]
static public void RefEdit()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;

 

if (doc.Name.Contains("Test"))
{
ed.WriteMessage("New refedit...");
}
else
{
AcadApplication app = (AcadApplication)Application.AcadApplication;
app.ActiveDocument.SendCommand("_.REFEDIT ");
}
}

 

Thanks again!

ADN Support Specialist
Balaji_Ram
Posts: 666
Registered: ‎03-21-2011
Message 4 of 18 (467 Views)

Re: Override default commands

04-04-2012 08:36 AM in reply to: annse

Hi,

 

With the Line command the code does work.

 

But there seems to be some problem with using it for "Refedit".

Can you check if the command is actually undefined after sending the "undefine" command ?

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Moderator
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 5 of 18 (455 Views)

Re: Override default commands

04-04-2012 11:42 AM in reply to: Balaji_Ram

What about:

app.ActiveDocument.SendCommand("_ACAD_REFEDIT.REFEDIT ");

 ?

Command _REFEDIT defined in file AcRefEd.arx

If your's dll-file loaded after AcRefEd.arx - than no need to _UNDEFINE _REFEDIT, because your command REFEDIT override standard command REFEDIT. And standard command REFEDIT can be invoked using _ACAD_REFEDIT.REFEDIT


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
annse
Posts: 15
Registered: ‎04-04-2012
Message 6 of 18 (437 Views)

Re: Override default commands

04-04-2012 11:32 PM in reply to: Balaji_Ram

Hi!

 

When I do the same thing with LINE instead of REFEDIT, my new definition of LINE won't run.

I get this error with both LINE and REFEDIT.

 

_.UNDEFINE
; error: no function definition: ACET-STR-REPLACE
_LINE

 

Thanks!

Contributor
annse
Posts: 15
Registered: ‎04-04-2012
Message 7 of 18 (434 Views)

Re: Override default commands

04-04-2012 11:46 PM in reply to: Alexander.Rivilis

Thanks, Alexander! That works!

 

My dll is loaded in a .bundle installation.

So, because I can't override _LINE the same way, _LINE is loaded after my dll and _REFEDIT before?

 

Thanks again!

Contributor
annse
Posts: 15
Registered: ‎04-04-2012
Message 8 of 18 (428 Views)

Re: Override default commands

04-05-2012 12:29 AM in reply to: Alexander.Rivilis

If the timing issue is irrelevant due to that the _REFEDIT command is already defined when my dll is loading,

I can use SendStringToExecute instead of SendCommand?

This way I won't have to echo the command.

 

Thanks again!

Moderator
Alexander.Rivilis
Posts: 1,398
Registered: ‎04-09-2008
Message 9 of 18 (424 Views)

Re: Override default commands

04-05-2012 12:39 AM in reply to: annse

annse wrote:

I can use SendStringToExecute instead of SendCommand?

This way I won't have to echo the command.


I think you can do it. Try!  :-)


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
annse
Posts: 15
Registered: ‎04-04-2012
Message 10 of 18 (416 Views)

Re: Override default commands

04-05-2012 03:32 AM in reply to: Alexander.Rivilis

Hello again...

 

Sending "_ACAD_REFEDIT.REFEDIT " seems to redefine the command.

If the string is executed, the next time you run REFEDIT, it'll run the default definition. 

 

[Autodesk.AutoCAD.Runtime.CommandMethod("REFEDIT", Autodesk.AutoCAD.Runtime.CommandFlags.Session & Autodesk.AutoCAD.Runtime.CommandFlags.UsePickSet)]
static public void RefEditDef()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;

 

if (doc.Name.Contains("Test"))
{

ed.WriteMessage("selected ref..");

}
else
{
doc.SendStringToExecute("_ACAD_REFEDIT.REFEDIT ", true, false, false);
}
}

 

Any ideas?

 

Thanks!

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community