AutoCAD/XREf LSP

Advertisement


Question
good day, im trying to learn how to create lsp files and i have found your website quite helpful. i do have a small problem. been trying to create an lsp "defun c:xn" that would move an xref to "la-xref" layer and identify the x-ref name in the command line. and a separate command "defun c:xx" to load and reload the selected xref.

Answer
mi:

XN.lsp will be very simple:

defun c:xn () (command "_.chprop" pause "" "_la" "LA-XREF" "") (princ))

XX.lsp will have more, including a little error checker:


(defun xxerr (msg)
  (if c:r (c:r) redraw)
  (setq ent nil elist nil xrefname nil)
  (setq *error* olderr)
  (princ msg)
  (prompt ".  Please try again.")
  (princ)
)

(defun c:xx (/ ent elist xrefname fname)
  (setq olderr *error*)
  (setq *error* xxerr)
  (setq ent (entsel "\nSelect the Xref to reload:  "))
  (setq elist (entget (car ent)))
  (setq xrefname (cdr (assoc 2 elist)))
  (command "_.xref" "_r" xrefname)
  (if (not (null xrefname ))
     (prompt (strcat "\nXREF name:  " xrefname))
     (prompt "\nObject is neither a block nor an XREF.  ")
  )
  (setq *error* olderr)
  (princ)  
)




They  should work - even on Chinese AutoCAD.  Let me know if it does not.

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.