Tutorials > 

To Create a Custom Command

 
 
 

The AutoCAD JavaScript tutorial demonstrates how you can create a custom command using the addCommand JavaScript API.

  1. Use the following JavaScript code to create a custom command, which will erase all objects shown on the canvas:
    Acad.Editor.addCommand("JSCOMMAND","MYERASE","MYERASE",Acad.CommandFlag.TRANSPARENT,callback);
    
    function callback()
    {
    	Acad.Editor.executeCommand("_erase","all","");
    }
    NoteSave the file as myerase.js
  2. Register the file path from where you want to load the JavaScript file using the TRUSTEDPATHS sysvar.
  3. Use the WEBLOAD command in AutoCAD to load the myerase.js file.
  4. Execute the MYERASE command from the command line to erase all objects shown on the active canvas.

    Before Executing MYERASE Command

    After Executing MYERASE Command