August 24, 2009

How to encode a “pick from icon menu” option into Circuit Builder’s Excel spreadsheet

This posting builds upon the previous one. In fact, we’ll start with the same 3-phase motor control circuit template and “stop” component marker block “PB01″.

As we insert this circuit using Circuit Builder’s “Configure” mode, it processes the various marker blocks that come in with the circuit’s skeleton template drawing. The various options for each marker block are hard-coded in the ace_circuit_builder.xls spreadsheet.

For example, when Circuit Builder processes the “PB01″ marker block shown here, it finds five options and “none” defined in the Excel spreadsheet. These options then show up in the user interface. The user can select from this list of six options to insert at the “PB01″ position as the circuit inserts.

But what if none of these hard-coded options is really what is needed for this particular circuit? Maybe a N.C. pressure switch contact is the appropriate “stop” contact to interrupt power to the motor circuit. Wouldn’t it be nice to have a 7th option, one that calls up the normal “Insert Component” icon menu and let’s the user browse to the pressure switch page and then pick an appropriate component for the circuit?

This is do-able. Not super easy, but do-able. Here’s how…

How to enable Icon Menu picks from within Circuit Builder

The key is to create a small AutoLISP utility that can substitute for the normal Insert Component API call. We then add a new row to the spreadsheet for our “PB01″ options and reference this new AutoLISP function. That should do it.

Step 1

Here is the AutoLISP utility. It wraps a call to “wd_wdmenu” around the normal circuit builder API call “(c:ace_cb_insym…)”. What this does is call the icon menu function, user picks, and function returns the block name of the picked component. This block name is saved in variable “symnam” and then this variable is passed to the normal Circuit Builder insert component command. The very last line “auto-starts” this function as soon as it’s loaded. Should work!

Save this AutoLISP program in an ASCII text file named “cb_user_iconmenu.lsp”. Save it to a folder that is somewhere in the AutoCAD Electrical or AutoCAD support file search path list.

Step 2

Reference the above (c:cb_use_iconmenu) function in a new line for marker block PB01 in the Excel spreadsheet ace_circuit_builder.xls. If you have a hard time finding where this support file is located, type this at your “Command:” prompt:

(c:ace_find_file "ace_circuit_builder.xls" 3) [Enter]

Here is the edited “PB01″ marker block section of the 3PH_H sheet of the spreadsheet. Note that it has to use the “c:ace_cb_eval” function that was introduced in the last posting. Carefully enter the call as shown, (c:ace_cb_eval “(load (c:ace_find_file ‘cb_use_iconmenu.lsp’ 3))” ).

Testing

Save the edited Excel spreadsheet and exit. Now run Circuit Builder in “Configure” mode. When you get to the “Stop” selection in the control circuit, you now see a new option ( ! ). Pick it.

The standard “Insert Component” dialog appears. Now browse to the “pressure switch” page and make your selection. The picked block name is passed back to Circuit Builder and it inserts at the appropriate spot in the circuit.

Alternate solution

The first solution uses an auto-starting AutoLISP function that is searched for and “apploaded” with each use. The advantage of this first approach is that no AutoLISP function has to be pre-loaded and in memory. The disadvantage is that encoding it in the Excel spreadsheet is a bit mysterious… the use of the (c:ace_cb_eval…) function and the goofy syntax. Another disadvantage for ACE2009 users is that this (c:ace_cb_eval…) function needs to be pre-APPLOADED (in ACE2010 it is pre-defined).

Here is an alternate solution. The AutoLISP file is laid out just a bit differently… it has no auto-run line at the end of the code.