AutoCAD/LISP routine

Advertisement


Question
I have been experimenting a little with AutoLISP. I work for an MEP company, using AutoCAD 2009. Our standard procedure is for the electrical dept. to xref in the HVAC equipment in order to provide power to the equipment. Currently users need to manipulate the xref layers through the layer manager. That works fine, but it can be tedious to do on many drawings, and only increases chance for user error, especially when some of the designers are the most experience CAD users. I'm trying to create a LISP routine that will prompt the user to select the xref, then it will freeze/thaw and turn on/off certain layers in that xref, ultimately displaying only the HVAC equipment needed and its designation. These layers do not change, they are company standard. I can't figure out how to pass the xref name in to the "-layer" command to include the "xref|layername" syntax, much less error handling if, for some reason, a layer doesn't exist in the xref. any help would be much appreciated. the following is the LISP i have currently, which I can't take all the credit for.

(defun C:XEQ ( / entlay)
 (setvar cl (getvar "clayer")
(setq entlay(cdr(assoc 8 (entget(car(nentsel "Select the Mechanical Xref: "))))))
   (if (vl-string-search "|" entlay)
       (command "._-layer" "_s" "0" "_off" "*" "_n" "_on" "entlay|m-eq-elec-20" "")
    (alert "This is not an Xref!")
   )
(princ)
)

Answer
Hi, Nathan.

Is this what you're trying to do?

(defun C:XEQ2 (/ ent elist nestent nestlist nentlay)
 (prompt "\nSelect nested object in the Mechanical XREF:  ")
 (setq ent (entsel))
 (setq elist (entget (car ent)))
 (if (= (cdr (assoc 0 elist)) "INSERT")
   (setq insertnam (cdr (assoc 2 elist)))
 )
 (setq nestent (nentselp (cadr ent)))
 (setq nestlist (entget (car nestent)))
 (setq nentlay (cdr (assoc 8 nestlist)))
 (if (vl-string-search "|" nentlay)
   (command "_.-layer" "_s" "0" "_off" "*" "_n" "_on" nentlay "")
   (alert "This is not an Xref!")
 )
 (princ)
)

Keep in touch
Bill DeShawn
http://my.sterling.net/~bdeshawn

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill DeShawn

Expertise

I can address all 2-D questions and some 3-D questions. I do programming in AutoLISP if it doesn`t involve solid modeling. I can also address menu customization issues and can help you find answers to questions I can`t answer by taking your question directly to Autodesk via their newsgroups.

Experience

I used to do electronic and mechanical design for a flat panel monitor manufacturer, and now I do architectural drafting for an architect. I did and do AutoLISP and menu customization and take pride in making my lisp routines to do the work exactly the way the client likes them done.

Publications
I had a routine published in CADENCE magazine (no longer in publication and taken over by CADALYST). Some of my routines are published on my website at http://my.sterling.net/~bdeshawn

©2012 About.com, a part of The New York Times Company. All rights reserved.