Jump to content

looking for a lisp or script to attach a xref


pmxcad

Recommended Posts

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:

 



-LAYER
MAKE
XREF

LAYOUT
SET
MODEL
-XREF
ATTACH
.\XREF\*.DWG
0,0,0
1
1
0


 

Is there a way to get this working, script or lisp? Problem is the * as filename.

 

 

Thanks,

PmxCAD

Link to comment
Share on other sites

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 by VVA
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...