Nate Holt's Blog

November 6, 2009

PLC I/O Drawing Generator – Pre-defining wire numbers – AutoCAD Electrical

Filed under: Electrical — nateholt @ 11:02 am

Adding a new option to the “Spreadsheet to PLC I/O” drawing generator tool – pre-defining wire numbers right in the spreadsheet.

This AutoCAD Electrical tool is pretty flexible. Using Excel, you lay out your control system’s I/O module requirements and out pops a set of 75-80% complete PLC I/O drawings.

For example, the first three lines of this example spreadsheet drives the AutoCAD Electrical Spreadsheet to PLC I/O utility to generate the circuitry shown below. But wouldn’t it be nice if we could pre-define the existing wire number assignments that tie into the two customer-supplied interlocks?



How to add this new feature

This is not too difficult. One thing that makes it possible is that this Spreadsheet to PLC I/O generator tool runs is an AutoLISP function that runs totally bare. It is supplied and runs in full-source mode, file name “wdio.lsp”. This means you are free to modify your copy of this tool.

The second thing that makes adding this new option easy-to-do is that the tool is already set up to support “piggy-backed” attribute assignments.  For example, in the row of your spreadsheet for I/O point “I:003/10” you’ve entered the block name for a N.O. temperature switch, block name “HTS11”. In the D3DESC column you’ve entered a description for this switch, “SLURRY HEAT READY”. But you’d also like to define the “RATING1” value for this switch. But your spreadsheet has no column for RATING1 for the 3rd connected component. No problem. Just piggy-back the RATING1 assignment to the D3DESC value:



We’ll use this same idea to flag pre-defined wire number insertion on each side of a component. Instead of a name of an attribute, we’ll use these names:  $WNL and $WNR for “wire number left side” and “wire number right side”.

So, let’s say that we want to pre-define wire number assignments “TS-100” and “TS-101” for this temperature switch in our spreadsheet. We’d enter this:


So, that’s how we’ll set up our Excel spreadsheet to define wire number assignments. Now, the key piece is to modify the “wdio.lsp” file to be ready to recognize that a piggy-backed attribute name that is $WNL or $WNR is really a flag for a wire number insert.

Step 1 – find the wdio.lsp utility. A good way to do this is to type this at your AutoCAD Electrical “Command:” prompt

(c:ace_find_file “wdio.lsp” 3) [Enter]

If it can be found, the full path will display. Ignore the doubled-up back-slashes. It’s a Lisp thing.

Step 2 – MAKE BACK-UP COPY OF wdio.lsp. Important! Safety first.

Step 3 – Open wdio.lsp with any ASCII text editor or use AutoCAD’s Visual Lisp editor (type vlide [enter] at Command: prompt)

Step 4 – find this function within wdio.lsp file


Step 5 – Carefully cut and paste the code below to replace everything shown in the screenshot above.

  ; --
  (defun wdio_write_out_accum_extra_attr_data ( en lst2 / atnam atval x xx hit_wen lstx)
    ; "lst2" = (list (list attrnam attrval) (list attrnam attrval) ...)
    (foreach x lst2
; ** 06-Nov-09 NEHolt.begin, N8 Consultants LLC     
        ((wcmatch (strcase (car x)) "$WNL,$WNT,$WNR,$WNB") ; Look for special wire number flag
          ; masquerading as an attribute tag name. When found, the "attribute value" associated
          ; with it will be the desired fixed wire number value.
          ; The name of the flag indicates which "side" of the inserted component "en" that
          ; the wire number goes with.
          ; Get component's wire connection data
          (setq lstx (c:wd_get_sym_pntlst en 1 nil))
          (setq hit_wen nil)
          (foreach xx lstx
            ; Going through each wire connection returned from the component that was
            ; just inserted (entity name "en"). Each sublist has the X?TERMxx wire connection
            ; direction (the "?" part) held in (nth 4...) element. If any wires tied to
            ; this connection, they are held in a list of entity names in (nth 3...) element.
              ((/= hit_wen nil)) ; already processed this wire number, skip
              ((= (nth 3 xx) nil)) ; no wire connected to this component connection, keep looking
              ((AND (= (strcase (car x)) "$WNL")
                    (= (nth 4 xx) 4)) ; connection direction is from the left
                ; Found wire connection on left side (wire connection direction "4")
                ; Push fixed wire number out to this wire connection's attached wire                
                (setq hit_wen (car (nth 3 xx))) ; save wire entity name & exit loop
              ((AND (= (strcase (car x)) "$WNR")
                    (= (nth 4 xx) 1)) ; connection direction is from the right
                ; Found wire connection on right side (wire connection direction "1")
                ; Push fixed wire number out to this wire connection's attached wire                 
                (setq hit_wen (car (nth 3 xx))) ; save wire entity name & exit loop
              ((AND (= (strcase (car x)) "$WNT")
                    (= (nth 4 xx) 2)) ; connection direction is from above
                ; Found wire connection on top side (wire connection direction "2")
                ; Push fixed wire number out to this wire connection's attached wire                 
                (setq hit_wen (car (nth 3 xx))) ; save wire entity name & exit loop
              ((AND (= (strcase (car x)) "$WNB")
                    (= (nth 4 xx) 8)) ; connection direction is from below
                ; Found wire connection on bottom (wire connection direction "8")
                ; Push fixed wire number out to this wire connection's attached wire                 
                (setq hit_wen (car (nth 3 xx))) ; save wire entity name & exit loop               
          ) ) )    
          (if hit_wen
            (progn ; push the defined wire number out to wire entity "hit_wen".
                   ; Insert it as a "fixed" wire number value.
              (c:wd_putwnf hit_wen (cadr x))             
        ) ) )    
; ** 06-Nov-09 NEHolt.end

          (if (AND (not (c:wd_modattrval en (car x) (cadr x) 1)) (/= (car x) ""))
            (progn ; target attribute name not found
              ; If it is the format of CATxx, MFGxx, CNTxx, ASSYCODExx, or WDBLKNAMxx then write out as XData
              (if (wcmatch (car x) "CAT??,MFG??,CNT??,ASSYCODE??,UM??,WDBLKNAM??")
                (progn ; write as XData
                  (c:wd_upd_pnlval en (car x) (cadr x))             
        ) ) ) ) )
  ) )

Step 6 – save your modified version of wdio.lsp.

Now, let’s test.

Here we’ve opened up the demo PLC spreadsheet demoplc.xls and added some references. We changed the terminal block names from HT0001 to HT1001 so that wire numbers change through them. We’ve added a couple customer symbol references. Finally, we added in our wire number flags to insert wire numbers “W1”, “W2” on the customer limit switch and “W5” and “W9” for the N.C. relay contact.


Save spreadsheet. Exit out of Excel. Cross fingers and fire up the AutoCAD Electrical Spreadsheet –> PLC I/O utility. Reference the modified spreadhseet, and watch what happens…


A few things to keep in mind with this modification:

1. Remember that terminals come in two flavors… those that maintain a wire number assignment through the terminal on those that trigger a wire number change through them. You might need to use the latter.

2. If you put the “$WNL=<wire number>” or “$WNR=<wire number>” flag in an empty cell in your spreadsheet, precede it with a semi-colon (ex: empty cell contents becomes “;$WNL=12345”). This triggers the utility to treat this as a piggy-backed attribute.

3. For wires attaching from above or below, use flags $WNT and $WNB.

4. If these flag names don’t make sense or the “$” character is not one that shows up on your keyboard, adjust to suit your needs by editing the appropriate places in the pasted in Lisp code of step #5 above.

Advertisement – if your company is in need of AutoCAD Electrical customization, please visit



  1. I’m very new in autocad electrical. I need to know how to download from plc ladder diagram (PC) to PLC (hardware). can you help me. please email to me.


    Comment by safit — November 18, 2009 @ 3:53 am

    • Hi,
      There is currently no provision within AutoCAD Electrical to download and create drawings of the internal ladder logic you program up within your PLC. But if you lay out your PLC’s I/O listing in a spreadsheet or can download that part of your PLC’s program (dealing only with the I/O) and get it into a spreadsheet, then the AutoCAD Electrical “Spreadsheet to PLC I/O” drawing generator may be useful to you. Sorry I do not have the answer you were hoping for. – Nate.

      Comment by nateholt — November 18, 2009 @ 9:06 am

  2. Hi Nate,
    Is there a way to format the wire layer in the Excel Spreadsheet. I’m reading all of your post and the helps but nothing talked about that. For example, the first component is a fused terminal and and want to have the wire on the left is Black_#14AWG, the wire on the right is Red_#14AWG_Field and so on for the next component. If possible, when i format my wire to Cable layer, i want to insert a twisted pair symbols. Right now, i’m going around by using a circuit and use the ” * ” in order to insert in for the analog.
    Please help
    Thank you very much
    Trung Tran

    Comment by Trung Tran — January 11, 2010 @ 1:59 pm

    • Are you talking about the “Spreadsheet to PLC I/O Generator Tool”?

      Comment by nateholt — January 11, 2010 @ 4:37 pm

  3. Yes,
    I’m talking about the Spreadsheet to PLC I/O Generator Tool. I don’t know how to set up wire layers for devices with I/O Spreadsheet.
    Thank you
    Trung Tran

    Comment by Trung Tran — January 12, 2010 @ 11:53 am

  4. Hi Nate,
    I’m having problem with the default wire set for the PLC I/O Generator. Looking at my wdio settting, there is no option in order to setting up for the default wire. When i do the template for the WDIO setting, the current layer was Grn_14AWG_Field and then later on that layer became the default layer for all the wire even when i change current layer in the template into Blk_14AWG. Is there a setting that i can set my default wiring?
    Thank you
    Trung Tran

    Comment by Trung Tran — January 12, 2010 @ 12:06 pm

  5. Hello Nate,

    I’m trying to use the PLC I/O Utility to auto generate loop wiring diagrams. I’ve been fooling around with some custom symbols I created with the Symbol Builder on a loop diagram template. The problem is, of course, that for this type of drawing I neither need the PLC module itself nor some of the bus wiring generated with this tool. Is there perhaps a way of coupling this PLC I/O Generator with some autolisp code to delete these blocks+wires automatically so that I am left with only the one or two rungs + components for a Loop drawing? Are there any alternatives within AutoCad Electrical 2010 that would allow me to autogenerate/populate instrumentation loop diagrams from a spreadsheet?


    Comment by Mark — January 20, 2010 @ 4:36 pm

  6. […] PLC I/O Drawing Generator – Pre-defining wire numbers […]

    Pingback by Automation of PLC I/O Drawings – AutoCAD Electrical « AutoCAD Electrical Etcetera — February 11, 2010 @ 10:20 am

  7. Nate,

    I am trying to use the Spreadsheet to PLC functionality and everything works well, minus the ladder numbering. I have it set up in my drawings and project to use %S%N, however when I setup the ladder in the utility, the only options I have are “Numbers Only”, “Numbers Ruling”, “User Blocks”, “X-Y Grid” and “X Zones”. the only option that displayed the sheet number was “User blocks”, but that also inserted a hexagon that I don’t want.

    Is there a way to have the ladders follow my default project settings when it comes to reference numbering?

    Thank you!

    Comment by Cristian — April 14, 2010 @ 11:07 am

  8. Hi Shane,

    No, the PLC I/O Generator utility makes a number of “calls” into the AutoCAD Electrical executable. This means that you need AutoCAD Electrical installed and running on your machine in order to launch the PLC I/O generator tool.

    Get the free 30-day trial and give it a try. Maybe you’ll decide you can’t live without it ( ! ).


    Comment by nateholt — May 25, 2010 @ 11:10 pm

  9. Nate,
    I am trying to do some similar editing to the plc i/o program. There are some other small programs I am trying to generate. I can not seem to isolate the code for actually inserting the components into the Autocad drawing. Could you please help me with this. A simple code structure inserting a component, like a switch, into a drawing would be great. From there I think I can get pretty close…I just can’t seem to get that to work. :(

    Comment by Anthony — February 4, 2011 @ 5:35 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

Create a free website or blog at

%d bloggers like this: