Nate Holt's Blog

August 24, 2009

Circuit Builder configure mode – adding a “pick from icon menu” selection

Filed under: Electrical — nateholt @ 5:01 pm

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″.

cbicon01

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.

cbicon02

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!

(defun c:cb_use_iconmenu ( / )
  ; Make sure that an icon menu resides in memory
  (if (not GBL_wd_wdmenu2use)(c:wd_menu_load_schem))
  ; Display icon menu and return user's selection
  (setq symnam (wd_wdmenu GBL_wd_wdmenu2use))
  (if symnam
    (progn ; User picked something. Go ahead and call
           ; the normal Circuit Builder insert component
           ; API call. Pass the symbol name picked from
           ; the icon menu in "symnam".
      (c:ace_cb_insym #xyz nil symnam #scl 8 nil)
  ) )
)
(c:cb_use_iconmenu) ; auto-start when this program loads

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))” ).

cbicon03

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.

cbicon04

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.

(defun c:cb_use_iconmenu2 ( / )
  ; Make sure that an icon menu resides in memory
  (if (not GBL_wd_wdmenu2use)(c:wd_menu_load_schem))
  ; Display icon menu and return user's selection
  (setq symnam (wd_wdmenu GBL_wd_wdmenu2use))
  (if symnam
    (progn ; User picked something. Go ahead and call
           ; the normal Circuit Builder insert component
           ; API call. Pass the symbol name picked from
           ; the icon menu in "symnam".
      (c:ace_cb_insym #xyz nil symnam #scl 8 nil)
  ) )
  (princ) ; quiet return
)

… and here is how it would look in the Excel file for the PB01 marker block section:

cbicon05

It’s a lot cleaner in the Excel entry but the downside is that the function has to be in memory before Circuit Builder is launched (in other words, it needs to be loaded or APPLOADed).

Going Deeper

If you feel a custom Circuit Builder-based app might make a significant difference at your company, please contact me at n8consultants.com.

About these ads

1 Comment »

  1. […] use the Multi-Connection Sequence Terminal symbol Multiple-Item Number Balloon positioning utility Circuit Builder configure mode – adding a “pick from icon menu” selection Circuit Builder – embedding custom calls in the spreadsheet using (c:ace_cb_eval…) Dual […]

    Pingback by Index of AutoCAD Electrical Utilities – April 2006 through September 2009 « AutoCAD Electrical Etcetera — November 19, 2009 @ 1:38 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Shocking Blue Green Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 33 other followers

%d bloggers like this: