AutoCAD/LISP routine
Expert: Bill DeShawn - 5/19/2009
QuestionI 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)
)
AnswerHi, 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