.NET

Reply
Moderator
Alexander.Rivilis
Posts: 1,451
Registered: ‎04-09-2008
Message 11 of 18 (425 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 (415 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,451
Registered: ‎04-09-2008
Message 13 of 18 (400 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: 278
Registered: ‎11-29-2008
Message 14 of 18 (394 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,451
Registered: ‎04-09-2008
Message 15 of 18 (392 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 (371 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,451
Registered: ‎04-09-2008
Message 17 of 18 (369 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 (365 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
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.