;BGLAYER.LSP ; ;Background Layer version 1.01 ;Moves an xref to a layer with the same name as the xref. ;Will create the layer if is does not exist. ; ;Author J. Marsden DeLapp 12/17/96 ; ;v1.01 1/15/97 Cleaned up commented out code. ;v1.02 3/29/99 Added error handling function. ; ;***************************************************************** ;dxf function takes an integer dxf code and ent data list and ;returns the value for that dxf code (defun dxf (code elist) (cdr (assoc code elist)) ) ;***************************************************************** ;;; INTERNAL ERROR HANDLER ;;; Generic error handler (defun gen_er (s) ; If an error (such as CTRL-C) occurs ; while this command is active... (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) (princ "\n*Function cancelled*") ) (princ) ) ;***************************************************************** (defun c:bglayer (/ blknam ed en etype idata iflags isxref oldLAY Lay lstr ) (setq olderr *error* *error* gen_er ) (princ "Background Layer V1.01 Copyright 1997 by J. Marsden DeLapp.") (setq en (entsel "\nSelect an xref: ") ed (entget (car en)) ) (setq lstr (dxf 8 ed)) (setq etype (dxf 0 ed)) (if (= etype "INSERT") (progn (setq blknam (dxf 2 ed);get blockname idata (tblsearch "BLOCK" blknam);set insertdata to block def iflags (dxf 70 idata) ;get the flags );setq ;(boole 1 .....) does a bitwise AND on integer values (setq isxref (boole 1 4 iflags));if flag bit 4 is set it is an xref (if (= (boole 1 4 iflags) 4);if flag bit 4 is set it is an xref (progn (if (= lstr blknam);if layer name is already the block name (progn (princ "\nXREF: ")(princ blknam) (princ " is already on layer ")(princ lstr) );progn (progn ;stick in the new layer name in ed list (setq ed (subst (cons 8 blknam) (assoc 8 ed) ed)) ;Modify the entity en's layer, entmod will create the layer ;if it does not exist. (entmod ed) (princ "\nXREF: ")(princ blknam) (princ " moved from layer ")(princ lstr) (princ " to layer ")(princ blknam) );progn );if - layer str is block name );progn (princ "\nEntity was not an xref! Nothing to do.") );if );progn (princ "\nEntity was not an xref! (not an insert) Nothing to do. ") );if - entity is an insert (setq *error* olderr) (princ) ); end bglayer.lsp (princ "\nBackground Layer loaded. Start with \"BGLayer\".") (princ)