Controlling the Machine

  • Coinciding with the acquisition of VIA Development, Nate joined Autodesk in March of 2003 after a decade stint as an entrepreneur following a two-decade stint as a controls engineer and software applications developer at Owens-Corning. Nate is now the lead product architect for AutoCAD Electrical. He loves this stuff.

    About Nate

Latest Post

  • Reformat Wire From/To report into a tallied Wire Count report - AutoCAD Electrical
    October 31, 2008 09:03 AMby Nate Holt

    Here is another example of AutoCAD Electrical's report "User Post" capability can step in and service a user's custom reporting needs.  

    In this example, the user wants a tallied list of wires used in his AutoCAD Electrical project drawing set, tallied by wire number and by wire type (i.e. the wire "layer" name).

    The closest standard report would be the "Wire From/To" report that lists a line item for every from/to wire connection in the project. This includes wire number, wire type (i.e. wire layer), component and pin number connection at each end, etc. BUT, the report is not "tallied". For example, wire number "309B" with a wire type of "WHT_16_AWG" might be carried on a wire network that interconnects 27 devices yielding potentially 26 line item entries in the normal from/to report.

    But, the user wants to condense these entries down so that each wire number / wire type combination is one line entry with a "quantity" column, sort of like a "wire number BOM" report.

    Here is how

    Step 1 - figure out the name of the existing "user post" utility associated with the Wire From/To report. Run the report and then hit the "User Post" button on the report dialog. Look down in the command window. The path/name of the user post utility is shown here. This is the file we will alter along with the "dialog control" file - same name but ".dcl" extension.

    Step 2 - Get into the folder shown above. Make backup copies of wirefrm2.lsp and wirefrm2.dcl (just in case!)

    Step 3 - Open wirefrm2.dcl with an ASCII text editor or the AutoCAD Visual Lisp editor. Make and save changes shown in bold below. This will add a new "Wire Count" option to the little dialog that pops up when we select "User Post" for the Wire From/To report.

    main_select : dialog
     {
     label=/*wirefrm2_dcl_001*/"Report Data Post-processing Options";
     :paragraph
       {
       :text_part{
                 label=/*wirefrm2_dcl_002*/"Select options(s) to apply to the report's data";
                 }
       :text_part{
                 label=/*wirefrm2_dcl_003*/"before passing it back to the report display dialog.";
                 }
       :text_part{label="";}
       :text_part{
                 label=/*wirefrm2_dcl_004*/"(To modify these user options, edit the Post-process";
                 }
       :text_part{
                 label=/*wirefrm2_dcl_005*/" utility file listed in the AutoCAD command line window)";
                 }
       :text_part{label="";}
       }
     :toggle{key="user1";
            label=/*wirefrm2_dcl_007*/"Substitute wire color/gauge label text for LAYER names";
            }
     :toggle{key="user2";
            label=/*wirefrm2_dcl_012*/"Report only selected INST values";
            }
     :toggle{key="user3";
            label=/*wirefrm2_dcl_009*/"Report only non-cable connections";
            }
     :toggle{key="user4";
            label=/*wirefrm2_dcl_013*/"Report only selected wire types";
            }
     :toggle{key="user5";
            label=/*wirefrm2_dcl_xxx*/"Format into wire count report - (WIRENO,LOC1=count, and WLAY1)";
            }
     ok_cancel;
     }

    Step 4 - Open wirefrm2.lsp file. Add three lines shown in bold below to support the new toggle on the above dialog:

      ; -- main routine --
      (setq rtrn nil)
      ; AutoCAD Electrical passes the report displayed data as a list of lists of lists in variable
      ; called wd_rdata. The first element of this list is the list of lists
      ; report data. The 2nd element is future (at this time).
      (if (AND wd_rdata (car wd_rdata) (listp (car wd_rdata)))
        (setq wd_rdata (car wd_rdata))) ; just go with first list of lists (report data)
       
      ; Create and reference a ".dcl" file, on-the-fly
     
    ;  (setq user_1 "1") ; default to 1st user entry toggled on 
      (setq user_1 "0") ; default toggle OFF
      (setq user_2 "0")
      (setq user_3 "0")
      (setq user_4 "0") ; ** 25-Mar-06 NEHolt
      (setq user_5 "0")
      ; Look for dcl file of same name, open if found.
      (setq cancel nil)
      ; see if running as pre-process or auto report. won't work for those below that require selection from dialog
      (if GBL_wd_postprocess
        (progn
          (if (listp GBL_wd_postprocess)
            (progn
              (if (> (length GBL_wd_postprocess) 1)
                (setq param_lst (cadr GBL_wd_postprocess)) ; optional for any selections within this function
                (setq param_lst nil)
              )
              (setq GBL_wd_postprocess (car GBL_wd_postprocess)) ; should be which one to run 
          ) )   
          (if (= (type GBL_wd_postprocess) 'INT) (setq GBL_wd_postprocess (itoa GBL_wd_postprocess)))
          (cond
            ((= GBL_wd_postprocess "1") (setq user_1 "1"))
            ((= GBL_wd_postprocess "2") (setq user_2 "1"))
            ((= GBL_wd_postprocess "3") (setq user_3 "1"))
            ((= GBL_wd_postprocess "4") (setq user_4 "1"))
            ((= GBL_wd_postprocess "5") (setq user_5 "1"))
            (T (setq cancel 1)) ; not a valid value
          )
      ) )     
      ; Look for dcl file of same name, open if found.
      (if (AND (not GBL_wd_postprocess)  ; otherwise bypass dialog
               (setq dclnam (c:ace_find_file "wirefrm2.dcl" 16))) ; 16=display error dialog if file not found
        (progn
          (setq dcl_id (load_dialog dclnam))               
          (if (new_dialog "main_select" dcl_id)
            (progn
              (set_tile "user1" user_1) ; set toggles per defaults above
              (set_tile "user2" user_2)
              (set_tile "user3" user_3)
              (set_tile "user4" user_4) ; ** 25-Mar-06 NEHolt
              (set_tile "user5" user_5)
              (action_tile "user1" "(setq user_1 $value)")
              (action_tile "user2" "(setq user_2 $value)")
              (action_tile "user3" "(setq user_3 $value)")
              (action_tile "user4" "(setq user_4 $value)") ; ** 25-Mar-06 NEHolt
              (action_tile "user5" "(setq user_5 $value)")
              (action_tile "cancel" "(setq cancel 1)")
              (start_dialog)
              (unload_dialog dcl_id)
      ) ) ) )

    ... and add this new section which is triggered by selecting the new report option. This section accumulates the wire number / wire layer combinations, counts them up, and reformats the report into a tallied wire count list ( ! )

                  ) )   
              ) )
          ) )      
          (if (= user_5 "1") ; reformat the whole report as a "wire number/count" report
            (progn
              (setq rtrn nil)
              (setq wnum_lst nil)
              (setq cnt_lst nil)
              (foreach xx wd_rdata
                ; (nth 0 xx) = WIRENO
                ; (nth 7 xx) = WIRELAY (tied to the "From" component)
                (cond
                  ((setq x (member (list (nth 0 xx)(nth 7 xx)) wnum_lst))
                    ; Repeated wire number / wire layer combo. Increment count in cnt_lst
                    (setq cnt (nth (- (length wnum_lst)(length x)) cnt_lst))
                    (setq cnt (1+ cnt))
                    ; Push incremented value back into the list
                    (setq cnt_lst (wd_nth_subst (- (length wnum_lst)(length x)) cnt cnt_lst))
                  )
                  (T ; New wire number / Wire layer combo
                    (setq wnum_lst (cons (list (nth 0 xx) (nth 7 xx)) wnum_lst))
                    (setq cnt_lst (cons 1 cnt_lst)) ; start with a count of 1
                  )
                )
              )
              ; Push the wire number and count value out to the report
              (setq ix 0)
              (foreach xx wnum_lst
                (setq lst (list (nth 0 xx) ; wire number - index 0 item in list
                                (itoa (nth ix cnt_lst)) ; count - index 1 item in list
                                "" "" "" "" "" ; blank field placeholders for items 2-6
                                (nth 1 xx) ; wire layer into 7th item of list
                          )
                )               
                (setq rtrn (cons lst rtrn))
                (setq ix (1+ ix))
              )
              (setq rtrn (reverse rtrn)) ; put back into original order
              (setq wd_rdata rtrn) ; fresh copy for possible further processing
          ) )
        )                  
      ) 
      (c:wd_rtrn_2wd rtrn) ; return post-processed list back to AutoCAD Electrical's report dialog
    )

    If this is too daunting, download the modified files here and push into the above folder:

    files/22301_22400/22303/file_22303.dcl and rename to wirefrm2.dcl

    files/22301_22400/22304/file_22304.lsp and rename to wirefrm2.lsp

    Step 5 - TEST! - run the Wire From/To report and let it display in the dialog. Hit the "User Post" button. You should see your new, modified dialog pop up with a fifth option:

    ... toggle this and hit OK. In main report dialog select "Change Report Format" and show only the WIRENO, LOC1, and WLAY1 fields. Hit OK. Sort by LOC1 (quantity) and by WIRENO. Hit OK. There it is!

    1 Comment | Add CommentIn Controlling the Machine >

Previous Post

  • Nate's Simple AutoLisp - Lesson 004
    October 28, 2008 07:35 AMby Nate Holt

    Geeze, it's been over two years since lesson "003". Busy times. Anyway, we're back. If you have 10 minutes to kill and want to take a chance with an exciting, hands-on experience, then read on.

    Warning/Disclaimer: I'm neither a professional teacher nor am I well versed in the theory behind AutoLisp programming. But even beginners can come up with something useful and... best of all, have fun at the same time!

    Here's what we'll do in the next 10 minutes. We will build up, step-by-step, a useful program consisting of just one line of code. Then we'll add it as a button on the AutoCAD menu. Note: We're using AutoCAD Electrical as our example application but this applies to AutoCAD in general.

    Step-by-Step... A Really Simple "Wire Layer" Lister

    We just want to have a lead-pipe simple tool to quickly list the layer name of the picked object, let’s say a series of AutoCAD Electrical wire segments, one at a time, boom…boom…boom. We don’t want a screen-full of data about the object, we don’t want some kind of property dialog to display, we just want this one piece of info and we want it fast.
    Just for fun, let’s start develop this little tool with nothing more than the “Command:” window. With your AutoCAD schematic drawing active on screen, let’s start here:
    Command: (entsel) [Enter]
    Select object: [pick on wire segment, return=] (<Entity name: 7ef05f60> (19.5858 16.9905 0.0))
     
    The (entsel) function returns a two-element list: the first element is the entity name of the picked line segment and the second element is the XY coordinate of the mouse pick point. We just want the entity name, the first element of this returned list. Use the AutoLISP "car" function to extract the first element. So let’s next try this:
     
    Command: (car (entsel)) [Enter]
    Select object: [pick on wire segment, return=] <Entity name: 7ef05f60>
     
    Remember, gotta keep those "(" and ")" balanced out. For each "(" you add, you need to balance it with a ")". Okay, good so far. Now let’s modify our “program” to open up the selected line segment with a call to “entget”
     
    Command: (entget (car (entsel))) [Enter]
    Select object: [pick on wire segment, return=] ((-1 . <Entity name: 7ef05f60>) (0 . "LINE") (330 . <Entity name: 7ef05c10>) (5 . "6C") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "RED_18AWG") (100 . "AcDbLine") (10 20.0 17.0 0.0) (11 18.5625 17.0 0.0) (210 0.0 0.0 1.0))
     
    Wow, got a lot more information than we really need. The part we want to focus in on is the “8” subrecord which is used to carry the entity’s layer assignment. We'll use the "assoc" call to filter out all but the first instance of the target subrecord... 
    Command: (assoc 8 (entget (car (entsel)))) [Enter]
    Select object: [pick on wire segment, return=] (8 . "RED_18AWG")
     
    Really close. The layer name is in the second part of this return. We can use the “cdr” function to strip off the first part of this list of data…
     
    Command: (cdr (assoc 8 (entget (car (entsel))))) [Enter]
    Select object: [pick on wire segment, return=] "RED_18AWG"
     
    Okay, we did it. Pick entity, get layer name instantly. But it only does one at a time. Let’s add a “while” loop around our little program like this:
     
    Command: (while (princ (cdr (assoc 8 (entget (car (entsel))))))) [Enter]
    Select object: RED_18AWG
    Select object: RED_18AWG
    Select object: BLK_14AWG
    Select object: BLK_14AWG
    Select object:
    ; error: bad argument type: lentityp nil
    Command: *Cancel*
     
    Nice. We could stop now. We’re can pick,pick,pick and get instant gratification with each pick. It doesn’t look too pretty when we decide to kick out with [ESC] or pick in empty space. Let’s do just a tiny clean-up so that it exits nicely when we just pick in empty space to finish. We will store the return from (entsel) in variable “x”. If valid, then we go ahead and dig out the layer name of “x” and “princ” it out to the command window. The extra “(princ)” at the very end also helps give a clean return.
     
    Command: (while (setq x (entsel))(princ (cdr (assoc 8 (entget (car x))))))(princ) [Enter]
    Select object: BLK_14AWG
    Select object: RED_18AWG
    Select object: RED_18AWG
    Select object: BLK_14AWG
    Select object:

    Nifty.

    Now let’s add our cool tool to the pull-down menu so we don’t have to type it in each time. Type CUI to bring up the standard “Customize User Interface” dialog. Select “ELECTRICAL” and “Menus” for the pull-down menu customization. Let’s put our new tool under the “Wires” pull-down. So expand “Wires” as shown here.

     
     Highlight an existing command, let’s say “Insert Wire” and right-click. Pick “Duplicate”. Now you’ll end up with two “Insert Wire” entries, one above the other. Click on the new, lower one and begin to edit it.
     

    Change the Display name, description. Carefully enter in your new program in the “Macro” line as shown here. The “^C^C^P” prefix is not absolutely necessary but does serve a useful purpose. If you are in some existing command and then pick on this new menu item, the ^C^C part will cancel out of the previous command before starting your new command. Be careful about NOT adding in extra spaces. These can sometimes be interpreted as an [Enter] keystroke when the “Macro” string is executed.

    Save the CUI changes. Now, go to your “Wires” pull-down menu.

    WOW! There it is! Give it a try!

     

    BUT… this cool utility is encoded right into my current version of the menu. Could be easy to lose and a hassle to remember it and to type it back in 100% correctly. Let’s make it a bit safer – put the one-line program into an ASCII text file, call the file “cool.lsp”, and just reference this file from our new menu entry instead of having to encode the program itself into the menu entry.

    The key here is to create the cool.lsp ASCII text file and save to some folder that is one of the support paths defined for AutoCAD (or a new support path you add for your cool utilities). This way, a simple call to the AutoLISP function “findfile” will find it.
    After you create the one-line ASCII text file called “cool.lsp”, do this: test at command line to make sure it works. Type this string:
    Command: (if (setq x (findfile "cool.lsp"))(load x)) [Enter]
    Select object: BLK_10AWG
    Select object: BLK_10AWG
    Select object:
     

    Okay, the above test worked. It found, loaded, and executed the one line of code. It worked! Now edit the menu button and encode this “findfile” command string into it. To do this, type CUI and find your “Cool layer lister” entry. Change the macro string to match below. OK out of CUI command and test the menu button.

    Time's up! Was that fun or what... ? ! ! !

    0 Comment | Add CommentIn Controlling the Machine >

  • Parametric Connectors in AutoCAD Electrical - presetting defaults
    October 23, 2008 08:51 AMby Nate Holt

    These things are pretty cool. For one, they can auto-adjust to underlying wire spacing. Here's the opening dialog. Set various parameters for the desired "smart" connector and then...

    ... position on the first wire connection...

    ... and mouse click. The connector pin connections align with the underlying wiring. Any extra pins go in at the "pin spacing" value set on the initial dialog.

    But on start-up, the initial design parameters come up as either of two sets of hard-coded presets - one set if the drawing appears to be in metric units and a different set if inch/imperial units. You then make your adjustments in the opening dialog - and these are "remembered" for the remainder of your AutoCAD Electrical session... but reset when you restart AutoCAD Electrical.

    How can I quickly preset these start-up defaults?

    Here's how

    These defaults are pushed into a Lisp global called GBL_wd_connector_config_dlg_data. If you preset this global with your desired set of default values, then the dialog will pop up with these pre-populated settings!

    Let's try it. Here is the opening dialog on a drawing in metric units. It is pre-populated with the program's hard-coded defaults for a drawing that appears to be in metric units:

    Cancel out and then type this at the command line to view the value of the target global:

    Command: !gbl_wd_connector_config_dlg_data [Enter]
    (1 4 2 2 1 0 0 1 1 40.0 6.0 6.0 6.0 6.0 3.0 4 ("1") 0 0)
    Command:

    So, the above gives the program's hard-coded defaults.

    Now let's say you want to have this dialog initially pop up with 50.0 pin spacing and 5.0 for the four "size" values and 2.5 for the "Radius:" value.

    How do we figure out what this cryptic global should look like to give this result? Restart the command, display the dialog, and manually enter in these desired values. Insert a connector and then cancel out. Now redisplay the value held in the global:

    Command: !gbl_wd_connector_config_dlg_data [Enter]
    (1 4 2 2 1 0 0 1 1 50.0 5.0 5.0 5.0 5.0 2.5 4 ("1") 0 0)
    Command:

    So, there it is. If we can somehow preset Lisp global with a value of  '(1 4 2 2 1 0 0 1 1 50.0 5.0 5.0 5.0 5.0 2.5 4 ("1") 0 0), then the first time the Insert Connector dialog appears, it will carry all of our desired defaults ( ! ).

    Presetting the Lisp global

    Basically we just need to figure out a way to execute this lisp expression (when we're working on a metric drawing):

    (setq GBL_wd_connector_config_dlg_data '(1 4 2 2 1 0 0 1 1 50.0 5.0 5.0 5.0 5.0 2.5 4 ("1") 0 0))


    You would have an similar one for inch/imperial unit drawings.

    So, how to execute the appropriate metric or inch Lisp expression? There are multiple ways to execute an expression:  1) a one-line script file, 2) add button to the toolbar or pull-down menu, 3) create a tiny AutoLisp program, 4) ??

    If you are ALWAYS going to work in metric, you could even set this up in the acaddoc.lsp file or the ".mnl" file or even in AutoCAD Electrical's wd.env file. The wd.env file implementation would look like this (new line at the very end of the file):

    *SETQ:GBL_wd_wnum_noduplicate_chk,'("GND" "24VDC" "COM")
    *SETQ:GBL_wd_colga_leaderlay,"SYMS"
    *SETQ:GBL_wd_colga_textlay,"MISC"
    SETQ: GBL_wd_connector_config_dlg_data,'(1 4 2 2 1 0 0 1 1 50.0 5.0 5.0 5.0 5.0 2.5 4 ("1") 0 0)

     

    Reference information - here's the breakdown of the global

    Example using metric default:

      
                  1 ; connector type 1=plug/jack one block, 2=double, 4=plug only, 8=jackonly
                  4 ; showpins 0=hide single, 1=show single, 2=both, 4=plug, 8=jack, 16=hide both
                  orientation ;  orientation 1=vert, 2=horiz
                  2 ; 1=plug right or top, 2=plug left or bottom
                  1 ; divider line 1=yes, 0=no
                  0 ; (5) wire change, 1 block
                  0 ; (6) wire change, 2 blocks
                  1 ; (7) pin spacing mode 1=fixed, 2=wire crossings
                  1 ; (8) insert all pins  1=all, 2=allow spacers/breaks
                  rungdist ; (9) pin spacing             
                  6.0 ; (10) jack side offset
                  6.0 ; (11) plug side offset
                  6.0 ; (12) top offset
                  6.0 ; (13) bottom offset
                  3.0 ; (14) plug rounded corner fillet radius
                  4 ; (15) pin count
                  (list "1") ; (16) pin list (list of strings)
                  0 ; (17) start as child
                  0 ; (18) start with break 1=Y, 0=N
     

     

    0 Comment | Add CommentIn Controlling the Machine >

  • User-post to import component descriptions into Wire From/To reports - AutoCAD Electrical
    October 21, 2008 12:05 PMby Nate Holt

    This request popped up this morning. User wants to include the connected component descriptions in the Wire From/To report. Currently this is not an option. But we can fill in the gap with a "User Post" !

     Here is the main addition to the user-post utility wirefrm2.lsp:

          (if (= user_5 "1") ; pull in component DESC1-3 values
            (progn
              ; "nil"=get current proj mdb file name
              (if (setq scratch_fnam (c:wd_mdb_get_proj_scratch_dbnam nil))
                (progn ; have active project's scratch database filename.
                  ; Now do a query on the COMP table to get a list of all
                  ; component desc data
                  (setq complst (wd_oledb_select scratch_fnam (strcat
                          "SELECT HDL,DWGIX,DESC1,DESC2,DESC3 FROM [COMP]"
                          " WHERE DWGIX <> ''")))
                  (setq rtrn nil)
                  (foreach xx wd_rdata
                    ; process CMP1. Get its handle and DWGIX value
                    (setq hdl (nth 39 xx))
                    (setq dwgix (nth 41 xx))
                    ; Now search for this component in the query data
                    ; from the scratch database
                    (setq hit nil)
                    (foreach x complst
                      (if (AND (= hdl (car x))(= dwgix (cadr x)))
                        (setq hit x)
                    ) )
                    (if hit
                      (progn ; found match. Push three desc values into
                             ; fields normally reserved for "from"
                             ; component's panel XYZ coordinates
                             ; PNLX1, PNLY1, and PNLZ1
                        (setq xx (wd_nth_subst 52 (nth 2 hit) xx)) ; DESC1
                        (setq xx (wd_nth_subst 53 (nth 3 hit) xx)) ; DESC2
                        (setq xx (wd_nth_subst 54 (nth 4 hit) xx)) ; DESC3
                        (princ hit)
                    ) )
                    ; process CMP2. Get its handle and DWGIX value
                    (setq hdl (nth 40 xx))
                    (setq dwgix (nth 42 xx))
                    ; Now search for this component in the query data
                    ; from the scratch database
                    (setq hit nil)
                    (foreach x complst
                      (if (AND (= hdl (car x))(= dwgix (cadr x)))
                        (setq hit x)
                    ) )
                    (if hit
                      (progn ; found match. Push three desc values into
                             ; fields normally reserved for "to"
                             ; component's panel XYZ coordinates
                             ; PNLX2, PNLY2, and PNLZ2
                        (setq xx (wd_nth_subst 56 (nth 2 hit) xx)) ; DESC1
                        (setq xx (wd_nth_subst 57 (nth 3 hit) xx)) ; DESC2
                        (setq xx (wd_nth_subst 58 (nth 4 hit) xx)) ; DESC3
                    ) )
                   
                    (setq rtrn (cons xx rtrn))
                  )         
                  (setq rtrn (reverse rtrn))
                  (setq wd_rdata rtrn)
            ) ) )                     
          )     

    The key thing above is the query of the COMP table (about eight lines down) to read in all component handles and drawing index numbers along with DESC1-3 values. These handle/drawing index numbers are then used to find the matching connected component in each line of the report. The corresponding DESC1-3 values are then substituted into rarely used fields in the report.

     

     ... and here is the addition to the dialog defintion support file wirefrm2.dcl shown in bold text below:

     :toggle{key="user1";
            label=/*wirefrm2_dcl_007*/"Substitute wire color/gauge label text for LAYER names";
            }
     :toggle{key="user2";
            label=/*wirefrm2_dcl_012*/"Report only selected INST values";
            }
     :toggle{key="user3";
            label=/*wirefrm2_dcl_009*/"Report only non-cable connections";
            }
     :toggle{key="user4";
            label=/*wirefrm2_dcl_013*/"Report only selected wire types";
            }
     :toggle{key="user5";
            label="Include component DESC1-3 desc (into PNLX1-2,PNLY1-2,PNLZ1-2 fields)";
            }

    If you want to get this a try, download these two files:

    files/22201_22300/22273/file_22273.lsp - rename to wirefrm2.lsp

    files/22201_22300/22274/file_22274.dcl - rename to wirefrm2.dcl

    ... and overwrite existing versions on your system (probably in folder "c:\documents and settings\all users\documents\autodesk\acade 2009\support\")

    Then run your Wire From/To report. Select "User Post" and you should see a new option #5. Select it. Then hit "Change Report Format" and add in fields PNLX1-PNLZ1 and PNLX2-PNLZ2 to see the component descriptions from the "From" and "To" connected components respectively.

    0 Comment | Add CommentIn Controlling the Machine >

  • Index to 86 utilities for AutoCAD Electrical
    October 10, 2008 03:27 PMby Nate Holt

    This blog's 2.5 years went quickly. It's been fun. I really appreciate the privilege to (try to) respond to your questions and suggestions.

    About a year ago I posted a simple index to the 64 or so utilities that had been published on this blog in its first year. Now, we're up to about 86, so here's an updated list (starting with most recent).

    Pushing Wiretype user settings to signal arrow attributes
    X-Y Grid-based Wire Numbering - based on pick points
    Undoing 'Do not show me this again'
    Circuit Generation by Layer Combos On/Off
    Concatenations in Title Block update
    Match Wire Number text to Wire Color
    User-post to alter sort of 'By Tag' BOM report
    Extra wire number display - on component connections
    TIP: Terminal Strip Editor - speed-up
    Voltage drop calculations
    Backwards tagging from child to parent
    Troubleshooting missing icon menu images
    Calculate motor FLA and Starter Size - AU2007
    Block list to a spreadsheet
    Simple drawing parser using AutoLISP - layer list to a spreadsheet
    Unconventional use of Wire Gaps
    Auto-adjust Drawing Index report
    Drawing List report and 'user post' example
    Conduit fill calculation / reports
    Color assignment per layer - switch utility
    Control of pin text size in graphical cross-reference
    Presetting your Surfer 'Zoom' factor
    Constructing an AutoCAD Electrical project 'ZIP' utility
    Updating drawing set parameters from the Project's scratch database
    SS->PLC I/O utility - adding auto title block update
    European-style Terminal/Cable connection charts
    Matching cable tag-IDs to connected components
    Auto wire number tag removal on cabled wire networks
    Flipping attribute justification on a mass scale
    Customizing the Drawing Index Sheet
    Vectoring existing projects to reference ACE 2008 libraries
    Flipping to In-line wire number tags
    Wire angle connections to dots - simple swap utility
    Titleblock Update - Previous/Next Sheet Numbers
    Tracing Polyline-connected Components
    Recovering Corrupted Wiring in AutoCAD Electrical
    Making the Part Number fit the Relay Contacts used - AutoCAD Electrical
    Smart Title Block Swapping with AutoCAD Electrical
    Component tagging by "Pick Order" in AutoCAD Electrical
    Terminal Plan report - controlling the "field" wiring side in AutoCAD Electrical
    Auto-mapping "Power" and "Control" contact pin assignments in AutoCAD Electrical
    Updating AutoCAD Electrical "Web links" - Pat Murnen's neat solution
    Enhancing AutoCAD Electrical's Tabular Terminal Strip Layout
    Bypassing AutoCAD Electrical's Automatic Wire tag-ID assignments
    1-line Diagrams and linked MCC layouts: AutoCAD Electrical
    Creating Special Wire From/To Annotation - AutoCAD Electrical
    Repeating In-line Wire Number Tags with Auto-update
    Discrete Cross-referencing on Large Schematic Symbols
    Writing to Block Attributes in un-opened Drawings - Example App
    AutoCAD Electrical's Modify Symbol Lib util - Pushing it beyond its limits
    Linking AutoCAD Custom Drawing Props back to AcadE Proj Mgr
    When one Tag-ID isn't enough
    Comparing project defaults to all drawings at once
    Incrementing Line References - customizing the "user" symbol
    How to pull the 10 "user" attributes on a wire number into the From/To report
    Terminal assignments based upon Cable core indices
    Wire From/To - limiting to certain component type
    Catalog Lookup - Browsing on Internal vs. Manufacturers part numbers
    Altering the twist in Twisted-pair symbols
    How to Alias AutoCAD Electrical commands using the ACAD.PGP file
    Multi-wire Bus Command - controlling the default count and spacing
    Wildcard Filtering in Reports
    BOM Report + Component DESC1-3 Text
    Multi-Language Electrical Component Tagging
    PLC I/O Wire Numbering based upon "Slot" + I/O Pin Number
    Catalog Lookup - table name confusion
    Edit Wire Number Dialog - Tip: holding in new position
    Example of mass update of SHEET assigments
    Automatic Display of Internal Part Numbers on Electrical Components
    Angles to Dots (IEC angled tee symbols to dot conversion)
    Special PLC Address-based Wire Numbers
    A couple SS->PLC I/O Tricks - Pin number assignments
    Migrating PLC point descriptions back to overall module representation
    Dual Catalog Lookup: Preferred and Everything else
    Mirror Tears - flipping orientation of inserted components
    Customized INSERT PLC Module Command
    User Struggle with Reversing Starter - WDTAGALT approach
    Adding unused core/conductors to Cable From/To report
    Flipping between "Shop floor" and "Customer" tags
    Instant "Tags used" listing
    Attribute Edit > 255 characters ( ? )
    Rolling your own brand of Signal cross-reference annotation
    Writing relay contact references grouped by catalog number out to Excel
    ACE2006/2007 project file compatibility with ACE2004/2005
    Hiding subsets of rarely used catalog lookup entries
    Multiple ASSYCODE trick
    Trick with Type 0 Pin list

    0 Comment | Add CommentIn Controlling the Machine >

  • Pushing Wiretype settings to signal arrows - AutoCAD Electrical
    October 9, 2008 11:26 PMby Nate Holt

    This posting is triggered by a recent user request. The Create Wiretype command allows a number of wire parameters to be associated to a given wire layer. But how can these be accessed with a user-created utility?

    The need is to look at each source/destination arrow symbol, find the attached wire, and determine the wire type (i.e. the wire "layer" name). Then access the defined data for the given wire type. Pull two of this wire type's parameters from its definition and push them on to two new attributes the user has added to his source/destination arrow symbols.

    This solution is in two parts: 1) modify the library symbols to include the new target attributes, and 2) create a little AutoLISP utility to find the wiretype data related to the wire tied to each source/destination arrow symbols and push two elements of this data back into the symbol as visible values on the two new target attributes.

    Add two new attributes to the Source/Destination arrow symbols

    This is the first step. User adds attributes COLOR and SIZE to each of the arrow symbols. In this example the attribute definitions are located just below the XREF attribute that carries the "From xxx" or "To xxx" cross-reference annotation.

    All done. That's the simple, boring part. Now the fun part begins... creating the software application to make it all work.

    How this think will work

    Let's design it so that the utility prompts the user to pick on each signal source or destination arrow symbol. The utility reads the symbol and confirms that it is a source or destination symbol. Then it finds the wire tied to the symbol and extracts the wire's layer name (i.e. the wire's "wire type").

    Next it makes an API call to query the scratch database to find all wiretypes tied to the active drawing. On the record that matches the passed layer name, it returns the list of color, size, and USERn values assigned to this wire type.

    It pulls out the color and size values and pushes them out to the two new attributes found on the source/destination arrow symbols.

    That's it!

    Here is the application:

    ; ** 09-Oct-2008 NEHolt created
    ; --------   W I R E T Y P E _ A N N O . L S P  -------
    (defun c:wiretype_anno ( / rtrn dwgix laynam ben blknam
                      color size x ed wtlst lst wen xitflg)
      ; PURPOSE: push WIRETYPE's "color" and "size" settings
      ;    out to target attributes on picked Source or
      ;    Destination arrow symbol.
     
      ; -- internal functions --

      (defun get_wiretype_data ( laynam / rtrn dwgix)
        ; Find and return all data tied to target "laynam"
        ; on active drawing in active project.
        ; "laynam" = wiretype layer name
        (setq rtrn nil)
        (setq dwgix nil)
        ; Set global GBL_wd_cip which carries the position
        ; that active drawing is in relative to all drawings
        ; listed in the project's ".wdp" file.
        (if (OR (= GBL_wd_cip 0)(not GBL_wd_cip))
          (wd_wdp_is_active_in_proj)) ; set the global
        ; Now figure out the drawing's DWGIX value that
        ; is used in the project's scratch database to
        ; identify this active drawing. 
        (if (/= GBL_wd_cip 0)
          (setq dwgix (wd_mdb_wdp2ix_ix GBL_wd_cip)))
        ; Now call an API function that queries the
        ; active project's scratch database file tables
        ; WIRETYPE and WIRETYPE_USR to find all
        ; info about wiretype "laynam" as defined on
        ; the active drawing (i.e. the active drawing's
        ; "DWGIX" value. 
        (if (AND laynam (/= laynam "") dwgix)
          (setq rtrn (ace_query_wiretype dwgix laynam))
        ) 
        rtrn ; nil=not found, otherwise a list of wire
             ; type COLOR, SIZE, and USER1-USER20
      )
     
      ; -- main program starts here --
      (setq xitflg nil)
      (while (not xitflg)
        (setq xitflg T) ; default to exit loop
        ; Prompt user to pick on Source/Destination
        ; arrow that needs to be annotated.
        (setq x (entsel "\nSelect source/destination arrow:"))
        (if x
          (progn
            (setq ben (car x)) ; entity name of pick
            (setq ed (entget ben)) ; open it
            (if (= (cdr (assoc 0 ed)) "INSERT")
              (progn ; so far, so good
                (setq blknam (cdr (assoc 2 ed)))
                ; Make sure it is an arrow symbol
                (if (wcmatch blknam "?A#S*,?A#D*")
                  (progn ; yes, keep going
                    ; Look for attached wire
                    (setq lst (c:wd_get_sym_pntlst ben 1 nil))
                    (if lst
                      (progn ; go for first or only connection
                        (setq wen (car (nth 3 (car lst))))
                        ; Get layer name of connected wire
                        (setq laynam (cdr (assoc 8 (entget wen))))
                        ; Now get COLOR and SIZE info for this
                        ; wire type
                        (setq wtlst (get_wiretype_data laynam))
                        (if wtlst
                          (progn ; have some data
                            (setq color (car wtlst))
                            (setq size (cadr wtlst))
                            ; Push these on to the Source/Dest
                            ; arrow symbol.
                           
                            ; ** SET TARGET ATTRIBUTE HERE **
                            (c:wd_modattrval ben "COLOR" color nil)
                            (c:wd_modattrval ben "SIZE" size nil)
                           
                            (setq xitflg nil) ; stay in loop
      ) ) ) ) ) ) ) ) ) ) )
      (princ) ; quiet return
    )

    You can download this file here: files/22201_22300/22257/file_22257.lsp

    ... then

    1. rename the downloaded file to "WIRETYPE_ANNO.LSP"

    2. to run, open target drawing and APPLOAD your renamed file "WIRETYPE_ANNO.LSP".

    3. Type WIRETYPE_ANNO [Enter] and the command line and start selecting the source/destination symbols to adjust.

     

     

     

    0 Comment | Add CommentIn Controlling the Machine >

  • X-Y Grid-based Wire Numbering - Based on wire number pick points - AutoCAD Electrical
    October 1, 2008 08:51 AMby Nate Holt

    AutoCAD Electrical normally makes wire number assignments based on the “beginning” XY point of a wire network.  Here’s a nifty utility to let you override this behavior. You can have wire number assignments be based on the XY point of a manual pick on each wire network.

    This originated from a user request. Here’s the default AutoCAD Electrical behavior for wire numbering in an X-Y grid-based tagging mode.

    Three wire networks are tagged “1-A”, “1-B”, and “1-C” because each wire network “begins” in those X-Y zones.

    But the user really wants to reposition the wire numbers as shown below. No problem. Just use the MOVE WNUM command and pick as shown.

    But here is the kicker. The user really wants the wire number assignment to match up with the X-Y position of where the wire number has been positioned on the wire network. So, in the screenshot above, he wants wire number “1-B” to really be “2-A” since the wire number text is now in the 2-A X-Y grid location. And he wants “1-C” to really be “2-B”.

    Well, can do this by using the EDIT WIRE NUMBER command on each of these two re-positioned wire numbers and manually forcing them to be the new values.
    Painful.
     
    AutoCAD Electrical’s API to the rescue.

    How about creating a little AutoLISP utility to make this easier. You would launch the utility. It would prompt you to pick locations on each wire network. For each pick, it would read the X-Y grid location, figure out the appropriate wire number, and pop it in as a “fixed” wire number with that value. So, in operation, it would look like this:

    Here’s the utility! Download here: files/22201_22300/22240/file_22240.lsp 

    Rename the file wire2pick.lsp. Then APPLOAD it. Type WIRE2PICK [Enter] at the “Command:” prompt to launch the utility.

     How does this thing work?

    It makes use of a number of API calls built into AutoCAD Electrical. To get to the API documentation, select "Electrical Help Topics" from the HELP pull-down menu. Then pick on the "API Help" item along the right-hand list you should see in the help dialog.

    Here is the main part of the utility with some running commentary in italics.

      ; Get list of existing wire nums on the active drawing
      (if (not dwg_wirenum_lst)
        (setq dwg_wirenum_lst (wd_wnum_get_dwg_wnum_list))
      ) 
      (setq xitflg nil)
      (while (not xitflg)
        (setq xitflg T) ; default to exit loop
    ; this next line prompts user to pick where the wire number is to be inserted        
        (setq x (entsel "\nNext wire number insertion point (pick on wire):"))
           
        (if x
          (progn ; something picked, keep going!
            (setq xy (cadr x)) ; pick point
            (setq wen (car x)) ; entity name of wire
            (setq reftxt (car (wd_1_get_xr xy)))
            (setq str reftxt)
            (setq new_w reftxt)
            (setq same_lr_cnt 0)
            ; Calculate the wire number
            (setq new_w (wd_1a_fmt_into_fmt (list fmt reftxt ""
                             pc_h pc_v pc_s pc_d pp p_i pl
                             (wd_wnum_get_next_suffix same_lr_cnt suffix_lst)
                             curdwg_sec curdwg_subsec
                             w_layer
                             ) 1 ))
            ; Make sure wire number not used before. If so, increment suffix until unique.            
            (while (member new_w dwg_wirenum_lst)
              (setq new_w (wd_1a_fmt_into_fmt (list fmt reftxt ""
                        pc_h pc_v pc_s pc_d pp p_i pl
                        (wd_wnum_get_next_suffix same_lr_cnt suffix_lst)
                        curdwg_sec curdwg_subsec
                        w_layer
                        ) 1 ))
              (setq same_lr_cnt (1+ same_lr_cnt))
            )     

            (setq ed (entget wen)) ; open up the entity, see if it is a LINE entity
            (if (= (cdr (assoc 0 ed)) "LINE")
              (progn ; looks good so far      
                ; Make sure that this line is on a valid wire layer - AcadE API call
                (if (not (wd_lay_verify_wire_lay (cdr (assoc 8 ed))))
                  (progn ; Not on a wire layer. Display error msg.
                    (princ "Line is not on a wire layer")
                    (setq xitflg nil) ; stay in loop but do not increment wire number
                  )
                ; ELSE
                  (progn
                    ; Some error checking here - Make sure that this network does not
                    ; carry a "Destination" arrow. This means that
                    ; we cannot predefine the wire number on this
                    ; network (it must be defined on the "source"
                    ; part of the network)
                    (setq netlst (c:wd_get_wire_netlst wen 1)) ; AcadE API call
                    (if Z_prev (command "_.ZOOM" "_PREV"))
                    (setq Z_prev nil)
                    (if (nth 5 netlst)
                      (progn
                        (princ (strcat "\n Destination arrow on this"
                          " network. Fixed wire number not allowed."))
                        (setq xitflg nil) ; stay in loop but do not
                                          ; increment wire number
                      )
                   ; ELSE
                      (progn 
                        (setq skip nil)
                        (setq existing (c:ace_get_wnum wen)) ; this is an AcadE API call
                        (if (/= overwrite "A")
                          (progn ; Check if this wire network already
                                 ; has a wire number assignment
                            (if existing
                              (progn ; returns x=(list wnum wnum_blk_en)                               
                                (princ " existing= ")
                                (princ (car existing))
                                (setq x (getstring " Overwrite? (Y/<N>/yes to All)":))
                                (if (= (strcase (substr x 1 1)) "A")
                                  (progn ; overwrite all, do not prompt
                                    (setq overwrite "A")
                                    (setq xitflg nil) ; stay in loop
                                  )
                                ; ELSE
                                  (if (OR (= (strcase (substr x 1 1)) "N") (= x ""))
                                    (progn ; do not overwrite existing wnum
                                      (setq xitflg nil) ; stay in loop but don't increment
                                      (setq skip T)
                        ) ) ) ) ) ) )
       
                        (if (not skip)
                          (progn ; okay to insert the fixed wire number now!
                             
                                 ; Delete any old wire number at its position
                                 ; to make way for new wire number inserted
                                 ; at new pick point.
                            (if existing (c:ace_del_wnum wen)) ; another AcadE API call
                            (setq x (c:wd_putwnxyf xy new_w)) ; another AcadE API call
                            (if x
                              (progn
                                ; Save wire number in active dwg's list of existing
                                ; wire numbers
                                (setq dwg_wirenum_lst (cons new_w dwg_wirenum_lst))
                                (setq xitflg nil) ; stay in loop
                        ) ) ) )
                        (if Z_prev (command "_.ZOOM" "_PREV"))
                        (setq Z_prev nil)
     
                ) ) ) )
              )
            ; ELSE
              (progn ; not a LINE
                (princ " ??")
                (setq xitflg  nil) ; stay in loop but don't increment wire number text
            ) )   
      ) ) )     

    0 Comment | Add CommentIn Controlling the Machine >

Subscribe to Blog

Want to keep up with the latest? Subscribe to the RSS feed today.

RSS

Categories

All

Blog Roll

AUTODESK MANUFACTURING COMMUNITY

Ellipsis
The official Autodesk Manufacturing Tech Evangelist blog
Under The Hood
Brian Schanen on Vault, Productstream, and more
In the Machine
Garin Gardiner hosts the official blog of the Inventor Product Team
Controlling the Machine
Archive of Nate Holt's AutoCAD Electrical posts

RECOMMENDED

Being Inventive
The official support blog for the Autodesk Inventor product line
Between the Lines
Shaan Hurley's AutoCAD Blog
It's Alive in the Lab
Scott Shepherd's Lab's Blog
Beyond the Paper
Volker Joseph's DWF Blog
Lynn Allen's Blog
Staying current with AutoCAD and Autodesk

PEER

AutoCAD Electrical Etcetera
Nate Holt shares AutoCAD Electrical tips and tricks.
Autodesk Manufacturing Northern European
The official blog for the Autodesk Northern Europe Manufacturing Technical Team.
Sean Dotson's Site
Sean Dotson's mCAD Tutorials, Forums, Admins & more
The Autodesk Informer
Helpful sites, tutorials, and industry news
CAD Professor
Inventor, Inventor LT, and AutoCAD news and updates.

Send to a Peer

You must login to share pages.

Feedback

Tell us what you think of the site.

Send Feedback