.NET

Reply
Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 11 of 18 (418 Views)

Re: Override default commands

04-05-2012 06:23 AM in reply to: annse
The reason is that, in fact, AutoCAD arx-application, that handles command _REFEDIT (ie AcRefEd.arx) is loaded when you first run the command and overrides your command REFEDIT. Therefore, need to load AcRefEd.arx before your's dll-file will be loaded:
Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.LoadModule ("AcRefEd.arx", false,true);

 Also you can modify registry to AcRefEd.arx will loaded with AutoCAD startup:

 

HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\RXX.X\ACAD-AYYY:ZZZ\Applications\AcadRefEdit
LOADCTRLS = 0x02 (instead of 0x0d)

 




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

Contributor
annse
Posts: 18
Registered: ‎04-04-2012
Message 12 of 18 (408 Views)

Re: Override default commands

04-05-2012 07:49 AM in reply to: Alexander.Rivilis

I've modified the registry. Even if I undefine _REFEDIT, my definition doesn't get called.

Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 13 of 18 (393 Views)

Re: Override default commands

04-06-2012 03:17 AM in reply to: annse

This code was tested with AutoCAD 2011-2013:

 

using System;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.EditorInput;

 

[assembly: ExtensionApplication(typeof(Rivilis.RefEditSubst))]

[assembly: CommandClass(typeof(Rivilis.RefEditSubst))]

 

namespace Rivilis

{

    public class RefEditSubst : IExtensionApplication

    {

        void IExtensionApplication.Initialize()

        {

            // Preloading AutoCAD RefEdit command arx-file

            SystemObjects.DynamicLinker.LoadModule("AcRefEd.arx", false, false);

        }

        void IExtensionApplication.Terminate()

        {

            // Do plug-in application clean up here

        }

        //------------------------------------------------

        //     Command group MUST be "ACAD_MAIN"

        //------------------------------------------------

        [CommandMethod("ACAD_MAIN", "RefEdit", CommandFlags.UsePickSet)]

        public void RefEdit() // This method can have any name

        {

            Document doc = Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            ed.WriteMessage("MyRefEdit..");

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

            {

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

            }

            else

            {

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

            }

        }

 

    }

}


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

Valued Mentor
KerryBrown
Posts: 276
Registered: ‎11-29-2008
Message 14 of 18 (387 Views)

Re: Override default commands

04-06-2012 04:37 AM in reply to: Alexander.Rivilis

 

Very nice solution Alexander !!

Regards

 

//-------------------------------------------------------

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 15 of 18 (385 Views)

Re: Override default commands

04-06-2012 04:41 AM in reply to: KerryBrown

Thanks! :smileyhappy:


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

Contributor
annse
Posts: 18
Registered: ‎04-04-2012
Message 16 of 18 (364 Views)

Re: Override default commands

04-10-2012 01:02 AM in reply to: Alexander.Rivilis

Thank you, Alexander! Setting the command group did it.

Moderator
Alexander.Rivilis
Posts: 1,449
Registered: ‎04-09-2008
Message 17 of 18 (362 Views)

Re: Override default commands

04-10-2012 01:07 AM in reply to: annse

annse wrote:

Thank you, Alexander! Setting the command group did it.


What about accept solution: http://forums.autodesk.com/t5/FAQ-How-To-Using-Autodesk/Accepted-Solutions/td-p/2701533 ?


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

Contributor
annse
Posts: 18
Registered: ‎04-04-2012
Message 18 of 18 (358 Views)

Re: Override default commands

04-10-2012 01:12 AM in reply to: Alexander.Rivilis

Accepted. :smileyhappy:

 

Thanks again!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!