Xref Tools
Posted: Mon Feb 18, 2002 1:30 pm
I am trying to get this code to function under icad2k. Can someone help me in understanding this code and tell me why it will not function? or better yet see if you can get it to function. Thanks
; EDITXREF.LSP - Routine to edit an Xref or Block by pointing
; Run the routine, select an Xref or Block, and then confirm that you
; want to edit the Xref or Block (AutoCAD will save your current
; drawing). To return to the parent drawing, execute the script
; XRETURN.SCR
; copyright 1991, 1993 by Mark Middlebrook, Daedalus Consulting
; prepared for AutoCAD Power Tools, 12 Sept 93
;------------------------------------------------------------------------
(defun C:EDITXREF (/ olderr ent blkname xrefspec editname yorn scrfile)
;error handler
(setq olderr *error*)
(defun *error* (msg)
(if (= msg "quit / exit abort")
(princ)
(princ (strcat "error: " msg))
)
(setq *error* olderr)
(princ)
)
(cond ((and (= "UNNAMED" (getvar "DWGNAME")) ;unnamed drawing
(>= 12 (atoi (substr (getvar "ACADVER") 1 2)))) ;R.12 or later
(alert "Drawing is UNNAMED.\nPlease SAVE first before using EditXref.")
(exit)
));drawing unnamed - abort
(setq ent (entsel "\nSelect an Xref or Block to edit: ")) ;get entity
(cond (ent ;*if something was selected...
(cond ((and (setq blkname (cdr (assoc 2 (entget (car ent)))))
(tblsearch "BLOCK" blkname)) ;*if it's an xref or block...
(if (setq xrefspec (cdr (assoc 1 (tblsearch "BLOCK" blkname))))
(setq blkname xrefspec) ;*get full path if it's an xref
);if
(if (/= ".DWG" (strcase (substr blkname (- (strlen blkname) 3) 4)))
(setq blkname (strcat blkname ".DWG")); *add .DWG if it needs it
)
;*make sure file exists:
(cond ((setq editname (findfile blkname))
(initget "Yes No")
(setq yorn (getkword (strcat "\nEdit " editname "? <Y>: ")))
(cond ((/= yorn "No")
(command "SCRIPT" "#CLOSE#") (command) ;*close any open SCR
(setq scrfile (open "TEMP.SCR" "w")) ;*script to load xref
(write-line "end 2" scrfile)
(write-line editname scrfile)
(close scrfile)
(setq scrfile (open "XRETURN.SCR" "w")) ;*script to return
(write-line "end 2" scrfile)
(write-line (getvar "DWGNAME") scrfile)
(close scrfile)
(command "SCRIPT" "TEMP") ;*do it
));cond /=
);setq editname
(T (prompt (strcat "\nCan't find " blkname)))
);cond findfile
);and
(T (prompt "\nNot an Xref or Block."))
);cond and
);ent
(T (prompt "\nNo entity selected."))
);cond ent
(setq *error* olderr)
(princ)
);defun
(defun C:EDX () (C:EDITXREF))
(prompt "\nEDITXREF loaded. EDITXREF or EDX runs it.")
(princ)
; EDITXREF.LSP - Routine to edit an Xref or Block by pointing
; Run the routine, select an Xref or Block, and then confirm that you
; want to edit the Xref or Block (AutoCAD will save your current
; drawing). To return to the parent drawing, execute the script
; XRETURN.SCR
; copyright 1991, 1993 by Mark Middlebrook, Daedalus Consulting
; prepared for AutoCAD Power Tools, 12 Sept 93
;------------------------------------------------------------------------
(defun C:EDITXREF (/ olderr ent blkname xrefspec editname yorn scrfile)
;error handler
(setq olderr *error*)
(defun *error* (msg)
(if (= msg "quit / exit abort")
(princ)
(princ (strcat "error: " msg))
)
(setq *error* olderr)
(princ)
)
(cond ((and (= "UNNAMED" (getvar "DWGNAME")) ;unnamed drawing
(>= 12 (atoi (substr (getvar "ACADVER") 1 2)))) ;R.12 or later
(alert "Drawing is UNNAMED.\nPlease SAVE first before using EditXref.")
(exit)
));drawing unnamed - abort
(setq ent (entsel "\nSelect an Xref or Block to edit: ")) ;get entity
(cond (ent ;*if something was selected...
(cond ((and (setq blkname (cdr (assoc 2 (entget (car ent)))))
(tblsearch "BLOCK" blkname)) ;*if it's an xref or block...
(if (setq xrefspec (cdr (assoc 1 (tblsearch "BLOCK" blkname))))
(setq blkname xrefspec) ;*get full path if it's an xref
);if
(if (/= ".DWG" (strcase (substr blkname (- (strlen blkname) 3) 4)))
(setq blkname (strcat blkname ".DWG")); *add .DWG if it needs it
)
;*make sure file exists:
(cond ((setq editname (findfile blkname))
(initget "Yes No")
(setq yorn (getkword (strcat "\nEdit " editname "? <Y>: ")))
(cond ((/= yorn "No")
(command "SCRIPT" "#CLOSE#") (command) ;*close any open SCR
(setq scrfile (open "TEMP.SCR" "w")) ;*script to load xref
(write-line "end 2" scrfile)
(write-line editname scrfile)
(close scrfile)
(setq scrfile (open "XRETURN.SCR" "w")) ;*script to return
(write-line "end 2" scrfile)
(write-line (getvar "DWGNAME") scrfile)
(close scrfile)
(command "SCRIPT" "TEMP") ;*do it
));cond /=
);setq editname
(T (prompt (strcat "\nCan't find " blkname)))
);cond findfile
);and
(T (prompt "\nNot an Xref or Block."))
);cond and
);ent
(T (prompt "\nNo entity selected."))
);cond ent
(setq *error* olderr)
(princ)
);defun
(defun C:EDX () (C:EDITXREF))
(prompt "\nEDITXREF loaded. EDITXREF or EDX runs it.")
(princ)