CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz]
CZ | EN | DE
Login or
registration
  Visitors: 2448

CAD tip CAD tip # 13529:

   
Question CAD 
 %  platform  category 
Q - question

How to redefine the behavior of a standard AutoCAD command?

A - answer If you want to change or extend the behavior of a standard AutoCAD command, you can use several methods. Let's take an example of UNISOLATEOBJECTS (unisolate objects). We want AutoCAD to regenerate the active viewport after the isolation is lifted. We can use one of the following methods:

  1. Menu editing.
    If you usually invoke the command from menu or from a ribbon or via a keyboard shortcut, just modify its definition in the menu (the CUI command) - e.g., instead of calling ^C^C_unisolateobjects here, use and save the user menu macro ^C^C_unisolateobjects;_regen

  2. Redefinition.
    Using the _UNDEFINE command, you can "unlearn" an internal AutoCAD command and replace its behavior with a custom command definition of the same name. You can provide the redefinition using, for example, a LISP macro. Add a command redefinition function to an automatically loaded .LSP file (e.g. ACADDOC.LSP):
    (command "_UNDEFINE" "_UNISOLATEOBJECTS")
    (defun C:UNISOLATEOBJECTS()
     (command "._UNISOLATEOBJECTS")
     (princ " and regen")
     (command "_REGEN")
     (princ)
    )

  3. Reactor.
    A reactor is a way to add automatic responses to an event in AutoCAD. This can be, for example, a command completion event (commandEnded). Again, add the following reactor definition to any .LSP file you load automatically:
    (vl-load-com)
    (defun MY_Unisolate (reac com)
      (if (wcmatch (strcase (car com)) "UNISOLATE*")
        (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acActiveViewport)
      )
    )
    (setq *UNISOReactor
     (vlr-command-reactor
         "Unisolate reactor"
         '((:vlr-commandEnded . MY_Unisolate)))
     )
    )

You can also use the first option in AutoCAD LT. The second one can be used also in AutoCAD Web.

ACADACLTADTACADMPlantMapCivil3D
100% *  CAD 
8.11.2022    1137×  

See also:
Tip 10763:How to block specific AutoCAD commands?
Tip 8802:How to turn off the Exchange Apps in AutoCAD 2013?
Tip 7897:How to control BLIPMODE and SCREENMENU in AutoCAD 2012?
Tip 4452:Compare AutoCAD and AutoCAD LT - what are the key differences?
Tip 4241:How to lock given AutoCAD variables from editing?


Back   All CAD Tips



Have we helped you? If you want to support the CAD Forum web service, consider buying one of our CAD applications, or our custom software development offerings, or donating via PayPal (see above). You may also add a link to your web - like this "fan" link: CAD Forum - tips, utilities, blocks for Autodesk products
CAD:    OS:    Categ: 
Text:  FAQ glossary   



Featuring:
DwgTextTranslator translates a series of drawings from one language to another using MS Access.
Download a fully functional trial version.


Please use these tips at your own risk.
Arkance Systems is not responsible for possible problems that may occur as a result of using any of these tips.
TOPlist