AutoCAD/xref lisp

Advertisement


Question
QUESTION: Bill, I apologize for writing so quickly again. I figured out how freeze, thaw, etc. xref layers--now i just need help getting the lisp to detect if the object selected is not an xref, an error handler, and perhaps notification if layers aren't present in xref. here is my updated routine.
thanks in advance for your help.

(defun C:XEQ ( / xrf)
 (setvar "cmdecho" 0 )
 (setq xrf (cdr(assoc 2 (entget(car(entsel "Select the Mechanical Xref: "))))))
   (command ".layer" "_off" (strcat xrf "|*" ) "_freeze" (strcat xrf "|*") "")
     (command ".layer" "_thaw" (strcat xrf "|M-EQ-21") "")
     (command ".layer" "_on" (strcat xrf "|M-EQ-PIPING") "_thaw" (strcat xrf "|M-EQ-PIPING") "")
     (command ".layer" "_on" (strcat xrf "|M-EQ-DESIGNATION") "_thaw" (strcat xrf "|M-EQ-DESIGNATION") "")
 (princ)
(setvar "cmdecho" 1 )
 )

ANSWER: Nathan:

That's OK.  

So, how about this one:

(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)
   (progn
;       (command "_.-layer" "_s" "0" "_off" "*" "_n" "_on" nentlay "")
      (if (tblsearch "layer" (strcat xrf "|M-EQ-21")) (command "_.-layer" "_thaw" (strcat xrf "|M-EQ-21") ""))
      (if (tblsearch "layer" (strcat xrf "|M-EQ-PIPING"))
        (command "_.-layer" "_on" (strcat xrf "|M-EQ-PIPING") "_thaw" (strcat xrf "|M-EQ-PIPING") "")
     )
      (if (tblsearch "layer" (strcat xrf "|M-EQ-DESIGNATION"))
         (command "_.-layer" "_on" (strcat xrf "|M-EQ-DESIGNATION") "_thaw" (strcat xrf "|M-EQ-DESIGNATION") "")
     )
   )
  (alert "This is not an Xref!")
 )
 (princ)
)

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


---------- FOLLOW-UP ----------

QUESTION: Thanks for the quick response. I tried the above lisp, and i get this error:
error: bad argument type: stringp nil

If i'm reading your code right, i think it is what i want. the tblsearch is checking for those layers in the xref right?
i'm not sure what the (command "_.-layer" "_s" "0" "_off" "*" "_n" "_on" nentlay "") line is for though--perhaps a carryover from the lisp i copied and was trying to tweak? also, i'm not trying to isolate a nested object in the xref, but rather just specific layers.
thanks for your help.

Answer
Nathan:
Please send me the drawing.  Go to my website (web address below) and click on the email icon and attach the drawings (the working drawing and the XREF).  Use ETRANSMIT to create a zip file you can send.  I don't have anything with those layers and it would be better to have those drawings available to me to check out the error.

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.