AutoCAD Electrical Tips from Nate Holt - AutoLISP Utility

  • Oh no! An error has occurred!
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • Posted February 25, 2009

    by Community Admin1

    When Nate Holt began blogging in April of 2006, he promised that "Controlling the Machine" Blog" would focus on automation, controls, and electrical engineering in general, and provide tips and tricks as well as some interesting "unknowns" about the AutoCAD Electrical product. This collection pulls together three of Nate's quick, helpful tips for using the AutoLISP utility to help you get the most from AutoCAD Electrical.

    I. Simple Drawing Parser Using AutoLISP

    While using AutoCAD Electrical, there may be instances where you'll need to list all of the layers defined in a drawing and write this information out to a spreadsheet. The following steps will demonstrate how to use the AutoLISP utility to handle the job.

    Before beginning, it's important to note that there are two main functions in the AutoLISP utility that can be used to make this happen. The first is a call-to function named "tblnext" that allows a program to cycle through the "LAYER" table for the active drawing and pull out all of the defined layer names. The second is a call-to function named "ssget" that gives a program the ability to cast a window around the whole drawing and capture all entities filtered by some criteria. Below is a picture of the utility:

    AutoLISP

    1. Beginning at the front end of the "LAYER" table for the active drawing, loop through this table and collect a list of all the layer names defined in the drawing. This is done by the "while" loop near the beginning of the program. Data for each layer record pulled from the table ends up in variable "x". The layer's name is extracted from this data and pushed on to the "laylst" layer name list.
    2. Next, select a text file name to write out this data. It will be written in comma-delimited "csv" format instead of native Excel format. The CSV format file is easy to construct and easily read by Excel.

     

    After taking the above steps, the program will hit the "foreach" loop. For each layer name in the sorted list, the program creates a selection set of all entities in the active drawing that appear on this specific layer. The size of the selection set is determined (i.e. number of entities on the target layer). The layer name and the entity count are formatted into a line of text and output to the target output file. The program will loop until all of the layer names have been processed and outputted to the CSV file. Finally, the program closes the CSV file and exits.

    II. Quick Switch Color Scheme
    If you prefer a white background while working with AutoCAD Electrical, but find yourself squinting to make out some of the layer color defaults, the following is a quick way to re-assign those default colors.

    1. Download this AutoLISP utility: files/20401_20500/20415/file_20415.lsp
    2. Open the AutoLISP file using either a standard ASCII text editor or with the built-in Visual Lisp editor (type vlide [Enter] at the "Command:" prompt). Near the top of the file, you'll see this block of code:

    (setq layer_mapping
    (list  ; format is (list layernam newcolor)(list "WIRENO" 72) ; light green (70) --> shade darker
    (list "WIREFIXED" 7) ; light blue (130) --> black/white
    (list "WIREREF" 52) ; light green (61) --> darker olive green
    (list "WIREREF_DEST" 52) ; light green (61) --> darker olive green
    (list "MISC" 7) ; yellow --> black/white
    (list "PMISC" 7) ; yellow --> black/white
    (list "PTAG" 150) ; light yellow (51) --> medium blue
    (list "TAGS" 150) ; light yellow (51) --> medium blue
    (list "TERMS" 123) ; cyan --> gray/blue
    ) )

    1. Adjust this list or add in additional standard AutoCAD Electrical layers that you want to map to a different color. The color number is the last entry in each sublist. For example, the first entry, (list "WIRENO" 72) will instruct this utility to look for layer "WIRENO" in the active drawing and force its default color to be color 72.

     

    III. Drawing List Report and 'User Post'  Example
    Reformatting AutoCAD Electrical reports can be accomplished with a custom "user post" and requires minimal setup. The following steps will help you customize AutoCAD Electrical's out-of-the-box features.

    1. First, locate the "User Post" function located in the lower right-hand corner of the display dialog.

     

    Change Report Format

     

    1. Once selected, an AutoLISP utility will appear that will match up with the report type being displayed. Hit the button, and the path to the AutoLISP utility will appear.

     

    AutoLISP Utility
    1. Next, you'll need to open up the dwglst.lsp file with an ASCII text editor or the built-in Visual Lisp editor (make a back-up copy first!). Right now, the file is just a blank template. It has three user options but none of them are set up to do anything. Here is the key part of the post-processing utility program. It is just a place-holder for where we will start to add our own custom code:

     

    Custom Code
    1. Since we're interested in tracking the value of the "Section" value from one drawing to the next, the focus falls on the index 5 position of each line of the report data. So, coding this up, we might end up with this new code inserted into the above place-holder:
    New Code
    1. The code grabs the "Sec" value from the first line of report data. Then it cycles through all lines of the report. Whenever the "Sec" value changes, it pushes in a "blank" line into the report.

     

    For more tips and tricks from Nate Holt, check out his blog, "Controlling the Machine."

     

    0 Comment | Add Comment

Comments



You must be logged in to post a comment.

Submit a Tip

Share your tips with the community.

Submit

Tags

You must be logged in to add a tag.

Send to a Peer

You must login to share pages.

Feedback

Tell us what you think of the site.

Send Feedback