.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to overrule any command?

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
iPranavKulkarni
364 Views, 8 Replies

How to overrule any command?

Hello is that possible to overrule any command?

I need to overrule BEDIT command in autocad.

Can anyone help? 

8 REPLIES 8
Message 2 of 9
BlackBox_
in reply to: iPranavKulkarni

Consider DocumentLockModeChangedEventArgs.Veto()

 

https://www.keanw.com/2006/10/blocking_autoca.html

 

https://adndevblog.typepad.com/autocad/2012/05/veto-a-particular-command-in-autocad.html

 

 

[Edit] - You can also just use good ole' UNDEFINE & REDEFINE Commands, FWIW.



"How we think determines what we do, and what we do determines what we get."

Message 3 of 9
gphanauer
in reply to: iPranavKulkarni

I think you want to use "BEDIT" to disallow the editing of certain blocks or implement your own command to edit such blocks. Because it doesn't make sense to intercept "BEdit" for any block. The problem I see here is how
to get the block name.
If you already have the block selected and type "BEdit" it's easy to get the name of the block.
If I type "BEdit" with no block selected, AutoCAD will launch the window to select the block to edit.
My question is how are you going to get the name of the block?

Perhaps these contents will help:

https://www.theswamp.org/index.php?topic=49985.0 

https://adndevblog.typepad.com/autocad/2015/01/tracking-entity-handles-through-bedit.html 

Message 4 of 9
BlackBox_
in reply to: gphanauer


@gphanauer wrote:

I think you want to use "BEDIT" to disallow the editing of certain blocks or implement your own command to edit such blocks. Because it doesn't make sense to intercept "BEdit" for any block. The problem I see here is how
to get the block name.
If you already have the block selected and type "BEdit" it's easy to get the name of the block.
If I type "BEdit" with no block selected, AutoCAD will launch the window to select the block to edit.
My question is how are you going to get the name of the block?

Perhaps these contents will help:

https://www.theswamp.org/index.php?topic=49985.0 

https://adndevblog.typepad.com/autocad/2015/01/tracking-entity-handles-through-bedit.html 


I don't think anyone would disallow BEDIT for all Blocks.

 

If user makes it to BEDIT, simply filter the Block name retrieved by calling Autodesk.AutoCAD.Internal.AcAeUtilities.GetBlockName() (thanks, Alexander Rivilis!), then conditionally invoke BCLOSE and report that to command line, no? 



"How we think determines what we do, and what we do determines what we get."

Message 5 of 9
kdub_nz
in reply to: BlackBox_

@BlackBox_ ,

Autodesk.AutoCAD.Internal.AcAeUtilities.GetBlockName()

could be one for the list !

 


// Called Kerry in my other life.

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

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

Message 6 of 9
gphanauer
in reply to: BlackBox_

Thank you very much for the answer and for the code you provided at https://www.theswamp.org/index.php?topic=49985.0 
I've been trying to block "BEdit" before the dialog is shown on the display and so far I haven't been able to.
What event should be used to intercept the "BEdit" command so that the dialog box has not yet been launched?
Could you provide a small snippet of code showing this?

Message 7 of 9
BlackBox_
in reply to: kdub_nz


@kdub_nz wrote:

@BlackBox_ ,

 

Autodesk.AutoCAD.Internal.AcAeUtilities.GetBlockName()

 

 

could be one for the list !


Added to list.



"How we think determines what we do, and what we do determines what we get."

Message 8 of 9
BlackBox_
in reply to: gphanauer


@gphanauer wrote:

Thank you very much for the answer and for the code you provided at https://www.theswamp.org/index.php?topic=49985.0 
I've been trying to block "BEdit" before the dialog is shown on the display and so far I haven't been able to.
What event should be used to intercept the "BEdit" command so that the dialog box has not yet been launched?
Could you provide a small snippet of code showing this?


Here's a working sample just as a silly demonstration - I don't actually think this is a good thing to do in a work environment. 

 

Rather than create a mechanism for filtering which Blocks are allowed, etc I simply implemented a custom BEDITMODE sysvar, so that when BEDITMODE==0 the BEDIT Command is disabled (with a Block selected via context menu, or with nothing selected and simply enter BEDIT at Command line). When BEDITMODE==1 the BEDIT Command works as expected OOTB.

 

Here's the C#: 

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Internal;
using Autodesk.AutoCAD.Runtime;

using acApp = Autodesk.AutoCAD.ApplicationServices.Application;

using System;

[assembly: ExtensionApplication(typeof(BlackBox.AutoCAD.BlockEditorTools.Events))]

namespace BlackBox.AutoCAD.BlockEditorTools
{
    public class Events : IExtensionApplication
    {
        private static DocumentCollection acDocs = acApp.DocumentManager;
        private static string varName = "BEDITMODE";

        void IExtensionApplication.Initialize()
        {
            acDocs = acApp.DocumentManager;

            acApp.Idle += onIdle;
        }
        void IExtensionApplication.Terminate()
        {
        }

        public static void onIdle(object sender, EventArgs e)
        {
            acApp.Idle -= onIdle;

            acDocs.DocumentLockModeChanged += onDocumentLockModeChanged;

            Document doc = acDocs.MdiActiveDocument;

            if (doc != null)
            {
                doc.Editor.WriteMessage("\n️ BlackBox Block Editor Tools loaded. \n");
            }
        }
        public static void onDocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e)
        {
            try
            {
                if (CoreUtils.WcMatch(e.GlobalCommandName.ToUpper(), "*BEDIT"))
                {
                    if (0 == Convert.ToInt16(acApp.GetSystemVariable(varName)))
                    {
                        e.Veto();

                        ///<-- this is where you do something useful, like prompt user for a Block selection
                        /// when implicit selection is empty (to prevent dialog) then, when done doing 
                        /// whatever you need to qualify if the selected Block is allowed, simply invoke 
                        /// SendStringToExecute() for BEDIT Command

                        e.Document.Editor.WriteMessage("\n** BEDIT Command has been disabled ** \n");

                    }
                }
            }
            catch (System.Exception ex)
            {
                if (acDocs.MdiActiveDocument != null)
                    acDocs.MdiActiveDocument.Editor.WriteMessage("\n; error: System.Exception: " + ex.Message + "\n");
            }
        }
    }
}

 

 

... and here's the Autoloader app .bundle's PackageContents.xml file:

 

<?xml version="1.0" encoding="utf-8"?>
<ApplicationPackage AppVersion="2.4.3" Author="BlackBox" Description="BlackBox Block Editor Tools for AutoCAD®" HelpFile="" Icon="" Name="BlackBox Block Editor Tools for AutoCAD®" ProductCode="{D2F18D8E-50A1-4A40-A8F8-9A80259BF779}" ProductType="Application" SchemaVersion="1.0" UpgradeCode="{EE422D69-A51A-4549-8D7C-F667405DB00B}" FriendlyVersion="2.4.3" SupportedLocales="Enu" AppNameSpace="appstore.exchange.autodesk.com" OnlineDocumentation="">
  <Components Description="2024" >
    <RuntimeRequirements OS="Win32|Win64" Platform="AutoCAD*" SeriesMin="R24.3" SeriesMax="R24.3" SupportPath="./Contents/Help;./Contents/Support" />
	<SystemVariables>
		<!-- BEDITMODE
			0 - Disabled
            1 - Enabled (OOTB) -->
		<SystemVariable Flags="Create|OpenOnce|Chatty" Name="BEDITMODE" Owner="" PrimaryType="Int16" StorageType="Profile" Value="0" ></SystemVariable>
	</SystemVariables>
	<RegistryEntries>
      <RegistryEntry Key="Variables\BEDITMODE" Name="LowerBound" Value="0" Type="REG_DWORD" Flags="Create|Open" ></RegistryEntry>
		<RegistryEntry Key="Variables\BEDITMODE" Name="UpperBound" Value="1" Type="REG_DWORD" Flags="Create|Open" ></RegistryEntry>
    </RegistryEntries>
    <ComponentEntry AppDescription="BlackBox Block Editor Tools for AutoCAD®." AppName="BlackBox\Block Editor Tools" LoadOnAutoCADStartup="true" ModuleName="./Contents/Support/bbox_BlockEditorTools24.dll" Version="2.4.3" />	
  </Components>
</ApplicationPackage>

 

 



"How we think determines what we do, and what we do determines what we get."

Message 9 of 9
gphanauer
in reply to: BlackBox_

I appreciated the code.
To date I have not used a custom system variable.
Thanks a lot.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost