Showing posts with label AutoLISP. Show all posts
Showing posts with label AutoLISP. Show all posts

Sunday, January 25, 2009

Assigning Multiple Double Click Actions to Single Entity Type in AutoCAD

In the Unleash the Double Click Power post, you saw how to customize the double click action of an entity type to implement custom double click actions. Now we are going to see how we can implement different double click actions simultaneously on single entity type. Normally, we accomplish this by using Reactors or Events in the respective languages. But, we are not going to use any of these in our method. Rather, we will follow a tricky way to achieve the same result.

As an example, I will show you how to change the double click action of an 'Attribute Block'. Normally double clicking an attribute block shows the Enhanced Attribute Editor Dialog. We are going to change this to show either Enhanced Attribute Editor(_eattedit) or Edit Attributes dialog (_attedit) depending on certain condition. Let's say, when we double click on a title block named TITLE_BLOCK, it should display the Enhanced Attribute Editor dialog and for all other blocks in the drawing, it should display Edit Attributes dialog. The step by step configuration is given below.



  1. Open CUI and create a custom command with the following code inside the macro section of the command. If you don't know how to create a custom command, then refer to the 'Unleash the Double Click Power' post mentioned above. Replace the 'TITLE_BLOCK' inside the following code with your actual title block name.
    ^C^C(if (= (cdr (assoc 2 (entget (ssname (ssget "P") 0)))) "TITLE_BLOCK") (command "_eattedit")(command "_ddatte" ))

  2. Drag and drop the custom command under the 'Attribute Block' section inside the Double Click Actions.

  3. Click on 'Apply' and close the CUI dialog.





That's it. Now if you double click on the title block, it will open the Enhanced Attribute Editor dialog and for all other attributed blocks, it will open Edit Attributes dialog. By the way, don't forget to take a backup of the default CUI files before you start experimenting with them.

Tuesday, October 9, 2007

Using Additional Options Inside Standard AutoCAD Commands

Are we going to edit the standard AutoCAD commands? No way. Rather we will look how to achieve a similar functionality in a tricky way. We are going to make use of AutoLISP's special ability to work transparently in between commands. Let us see how to utilise this to draw a circle with circumference option.

Add the following lisp routine to your acadDoc.lsp file. If the acaddoc.lsp file does not exist, create a new one.

(defun c:C#() (/ (getreal "\nEnter circumference : ") (* 2 pi)))

Now we can use this circumference option inside the circle command in the following way.

Command: Circle
Specify center point for circle or [3P/2P/Ttr (tan tan radius)]:
Pick center point
Specify radius of circle or [Diameter] <5.5>: 'C#
Enter circumference : 100
15.9155


Don't forget to provide the option as transparent using apostrophe ('). It will draw a circle with given circumference. Note that you can use any convenient option name in place of C#. I used the special character '#' in order to distinguish it from the standard command shortcuts. Here goes another sample for creating a circle with 'Area' option. Follow the same procedure you did for the previous option.

(defun c:A#() (sqrt (/ (getreal "\nEnter circle area : ") pi)))

And use it in this way

Command: Circle
Specify center point for circle or [3P/2P/Ttr (tan tan radius)]:
Pick center point
Specify radius of circle or [Diameter] <6.8>: 'A#
Enter area : 500
12.6157


If you come up with any other options, feel free to share it here.