AutoCAD/xref lisp
Expert: Bill DeShawn - 5/20/2009
QuestionQUESTION: 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.
AnswerNathan:
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