Monday, April 30, 2012

Creating a command for a new Contextual Tab

Creating a command for a new Contextual Tab:



This tutorial serves two purposes. One is to create a new tool to convert Line or Arc entities to Polylines, and the other purpose is showing how to integrating this tool into a contextual tab.
We're using AutoCAD 2013, and by default there are no contextual tabs for Line or Arc entities. Let's create a tool to convert these object types to polylines and put it on a contextual tab.
Start by opening the CUI editor by running the CUI command. In the upper left pane, under the ACAD menu, expand Ribbon, and then expand Contextual Tab States.

Scroll down until you see "Line Selected" and click it. Notice that there is nothing under here and nothing shows up in the right pane. If you check "Arc Selected", you will see the same thing.
In order to add something here, we need to do five (5) steps.


  1. Create a new command.


  2. Create a new Panel


  3. Create a new Tab


  4. Add the command to the new Panel and add the Panel to the new Tab


  5. Add the new Tab to the Contextual Tab States for Arc and Line entities


Step 1 - In the lower left portion of the CUI, click the New Command icon to create a new command. Over on the right side, enter the name "Convert Line or Arc to Polyline", and in the Macro field, copy this macro exactly as printed here.
._pedit $M=$(if,$(=,$(getvar"PEDITACCEPT"),0),y,)^C^C

In the Images area, choose an existing image or browse to find one.

Step 2 - In the upper left pane, right click on Panels and choose New Panel. It will scroll down automatically and the name of the Panel will be highlighted - Enter a name, like "My Tools"

Step 3 - In the upper left pane again, scroll up above Panels, right click on Tabs and choose New Tab and give it the name "Line/Arc Tools".

Step 4 - Now it's time to put the puzzle together. Left-click drag the new command you made in Step 1, into Row 1 of the "My Tools" Panel you created in Step 2. Now left-click drag the "My Tools" panel into the new "Line/Arc Tools" tab.
Step 5 - Finally add the "Line/Arc Tools" tab to the Contextual Tab State named "Line Selected". Then drag and drop it one more time into the Contextual Tab State named "Arc Selected". Click OK to save the CUI and close the CUI editor.

Now when you get back into your drawing, draw a line and arc. Select ONE of them, and the proper contextual tab should appear that contains one panel, containing one command - the "Convert Line or Arc to Polyline" command that we added in Step 1. Pick this command and the entity will be converted to a polyline.
Now this is just a simple example and only supports a single object selected. You could tweak the macro to support multiple entities, create a lisp routine to do even more and use this in place of the macro we entered above - not to mention create other commands for lines and or arc and add them to the contextual tab. From there, you could do this for other entity types.
What will you do?






No comments:

Post a Comment

Thank's!