mousebutton

We have discussed how to add new command to AutoCAD. We added our new command to Now let’s discuss how to add it to context menu. We want this command appear when we select particular type of object. This is what a contextual menu all about, right?

This time we will create a command to automatically convert line(s) to polyline. This is not something new. I’ve seen a lot of people have discuss it in forum or blogs. One of them is in Autodesk evangelist, Lynn Allen blog. But we are going to do it slightly different: put it to our context menu.

Open your CUI browser. You might want to read the previous post about creating a new command before you continue.

Right click on command list area, select new command from context menu. Rename it. Let’s call it Line to Pline. Or if it’s sound ridiculous to you, you can use another name that suit you.

Now in properties area, macro field, type this value:

^C^C_pedit;;;^C

A little explanation:

  • ^C is similar to pressing [esc], pressing [esc] twice will cancel a running command (if any).
  • PEDIT is activating polyline edit command
  • ;;; means you press [enter] three times. ; will execute [enter]

In Lynn’s blog she use ^C^CPEDIT;y;; It would work fine too. What’s the difference? Let’s compare to what we do.

  • ^C^C is just the same to what we do.
  • she use PEDIT instead of _PEDIT. Mostly using either one of it works fine. Adding underscore is an AutoCAD convention so this command can be used by AutoCAD in any other language. If you use English, then there’s no difference with or without underscore.
  • She use Y after the first ; If you activate PEDIT and select a line or arc, then AutoCAD will ask you: Object selected is not a polyline Do you want to turn it into one? <Y>
    By default the answer is yes. So pressing [enter] without typing Y will return the value of Yes. She decided to make sure AutoCAD will accept yes as the answer, so add Y then [enter] to do this.

Not different at all, aren’t they?

Now we have done with creating command. Now we have to define a new shortcut menu. Look at customize section. Find shortcut menus group. Right click on it, and click new shortcut menu. Rename it to Line Object Menu.

shortcutmenu

What are we doing? We define a condition, when this menu should appear. We want this menu appear when we select line. But it won’t appear when we select other type of objects. We have created the menu, but haven’t define the condition. Now we add this condition on properties section, aliases field.

Click ‘…’ button on this field. Use it, don’t type directly on the text field. Type on each line as follow:

  • OBJECT_LINE    –> this will enable your menu appear when you select a single line
  • OBJECTS_LINE   –> this will enable your menu appear when you select multiple lines

Adding both of them will enable your menu to appear on both conditions.

object name

Click OK. You will see your aliases as below. You might have different ID than mine (mine POP520), but that’s not a problem.

properties

Now, drag and drop our new command to this shortcut menu.

cuifinish

Click OK to close your CUI browser. Now try to draw some lines. Select it, then right click. See if your command show up in your context menu.

menuresult

Kinda fun, isn’t it?



Source: CAD Notes – Adding Command to Your Right Click
Go to Source: CAD Notes