We have discussed how to add a new command to AutoCAD. We added it to the toolbar. Now let’s discuss how to add it to the context menu. We want this command to appear when we select a 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 a polyline. This is not something new. I’ve seen a lot of people have discussed it in forums or blogs. One of them is in Autodesk Evangelist, Lynn Allen blog. But we are going to do it slightly differently: 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.
Create a new command in the command list category. Rename this new command. Let’s call it Line to Pline. Or you can use another name that suits you.
Now in properties area, macro field, type this value:
A little explanation:
- ^C is similar to pressing [esc], pressing [esc] twice will cancel a running command (if any).
- PEDIT is activating the polyline edit tool.
- ;;; 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 as what we do.
- she uses PEDIT instead of _PEDIT. Mostly using either one of them works fine. Adding underscore is an AutoCAD convention so this macro can be used by AutoCAD in any other language. If you use English, then there’s no difference with or without underscore.
- She uses 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 the customize section. Find the shortcut menus group. Right-click on it, and click the new shortcut menu. Rename it to Line Object Menu.
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.
Click OK. You will see your aliases as below. You might have different ID than mine (mine POP520), but that’s not a problem.
Now, drag and drop our new command to this shortcut menu.
Click OK to close your CUI browser. Now try to draw some lines. Select it, then right click. See if it shows up in your context menu.
Kinda fun, isn’t it?