pmxcad Posted March 28, 2015 Share Posted March 28, 2015 Hello all, i`ve made a script that makes a layer "XREF" and make it current. And set the layout to modelspace. Aftert that i want to attach a XREF. This xref drawingfile is in a subfolder of the main drawing. Because the file name of the xref is always different so i used a * (asterik) as filename. So this is not working. There is always just one Xref file in the subfolder. See script: -LAYERMAKEXREFLAYOUTSETMODEL-XREFATTACH.\XREF\*.DWG0,0,0110 Is there a way to get this working, script or lisp? Problem is the * as filename. Thanks, PmxCAD Quote Link to comment Share on other sites More sharing options...
VVA Posted March 29, 2015 Share Posted March 29, 2015 (edited) Try it (defun C:XATT (/ path lst sett) ;;;Attach Xref from a subfolder named XREF of the main drawing ;;;Posted http://www.cadtutor.net/forum/showthread.php?91669-looking-for-a-lisp-or-script-to-attach-a-xref ;;;http://forum.dwg.ru/showthread.php?p=1387542 (vl-load-com) (setvar "TILEMODE" 1) ;_switch to Model (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") ;_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 XATT in command line") (vl-load-com) Edited March 31, 2015 by VVA Quote Link to comment Share on other sites More sharing options...
pmxcad Posted March 29, 2015 Author Share Posted March 29, 2015 Wow, super. It works perfect VVA. Thanks, PmxCAD Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.