PDA

View Full Version : Help with xref lisp



cadd4la
2015-10-21, 05:53 AM
I found this lisp on the net and need it changed to my needs.

Looking for it to insert the file using the dimscale of the xref file. Also is it possible to let me choose the folder, have it not xref all the .dwg files at once but allows me to choose a point with the osnap node on, xref then move to the next one?


(defun C:XATTC (/ path lst sett)
;;;Attach Xref from a subfolder named XREF of the main drawing
(vl-load-com)
(setq sett (mapcar '(lambda (x)(getvar x))
'("INSUNITSDEFSOURCE" "INSUNITSDEFTARGET" "INSUNITS" "EXPERT")))
(vl-cmdf "_Layer" "_Make" "Xref" "") ;_make Layer named Xref
(setq path (vl-string-right-trim "\\" (getvar "DWGPREFIX")) ;_get path of the main drawing
path (strcat path "\\" "Xref" "\\" "Const") ;_get path to subfolder named Xref
)
(mapcar '(lambda (x)
(vl-catch-all-apply
'(lambda ()
(vla-attachexternalreference
(vla-get-modelspace
(vla-get-activedocument (vlax-get-acad-object))
)
x
(vl-string-translate
",.$#=@^\`"
"-_dpeaut"
(vl-filename-base x)
)
(vlax-3d-point '(0 0 0))
1
1
1
0
:vlax-true
)
)
)
)
(setq lst (z-files-in-directory path "*.dwg" nil))
)
(mapcar '(lambda (x y)(setvar x y))
'("INSUNITSDEFSOURCE" "INSUNITSDEFTARGET" "INSUNITS" "EXPERT")
sett )
(if lst
(alert
(strcat (itoa (length lst)) " xref attached from\n" path)
)
(alert (strcat "Nothing xref found in\n" path))
)
(princ)
)
;;;* Function z-files-in-directory returns a list of files located in a given
;;;* directory
;;;* Author: Vitaly Zuenko (ZZZ)
;;;* Parameters:
;;;* Directory - path eg "D:\\my documents\\ZEF\\Lisp"
;;;* Pattern - template such as "*. lsp", or a list'("*. dwg "" *. dxf ")
;;;* Nested - search in subfolders: t (yes) or nil (no)
;;;* Example call:
;;;(Z-files-in-directory "D:\\my documents\\ZEF\\Lisp" "*. dwg" t)
;;;(Z-files-in-directory "D:\\my documents\\ZEF\\Lisp"'("*. dwg "" *. dwt ") t)
;;;=============================================================================
(defun z-files-in-directory (directory pattern nested /)
(if (not (listp pattern))
(setq pattern (list pattern))
)
(if nested
(apply
'append
(append
(mapcar '(lambda (_pattern)
(mapcar '(lambda (f) (strcat directory "\\" f))
(vl-directory-files directory _pattern 1)
)
)
pattern
) ;_ mapcar
(mapcar '(lambda (d)
(z-files-in-directory
(strcat directory "\\" d)
pattern
nested
)
)
(vl-remove
"."
(vl-remove ".." (vl-directory-files directory nil -1))
)
)
)
)
(apply 'append
(mapcar '(lambda (_pattern)
(mapcar '(lambda (f) (strcat directory "\\" f))
(vl-directory-files directory _pattern 1)
)
)
pattern
)
)
)
)
(princ "\nType XATTC in command line")
(vl-load-com)