Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert Multiple Xrefs

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Mihai.Tanase
855 Views, 5 Replies

Insert Multiple Xrefs

Hi

 

I have a few .dwgs (test1 and test2) that i want to insert as xrefs. So far with the help of other autolisp on the site i have come to this :

 

(defun C:MultipleXr ( / myxref1 myxref2) ; define the function
  (setvar "ctab" "Model") ; move to modelspace
  (setvar "clayer" "0") ; set the current layer to 0
  (command "ucs" "w")
  (setq myxref1 (findfile "C:\\Dropbox\\Acad stuff\\Test\\Test1.dwg")
          myxref2 (findfile "C:\\Dropbox\\Acad stuff\\Test\\Test2.dwg")
  );; end steqs
  (foreach myxref (list myxref1 myxref2)
  (command "-xref" "Overlay" myxref "0,0,0" "1" "1" "0")
  );foreach
  (princ)
)

 

It does the job but if i run the command one more time i end up with the same xrefs on top of eachother.

I was thinking about creating some kind of search function to see if the xref is already in the my parent .dwg . Maybe using "ssget" to create a list and using "if" but ....... Smiley Sad

 

I realy have to warn you that i am pretty new to autolisp but i am weling to learn.

 

Thanks 

5 REPLIES 5
Message 2 of 6
hmsilva
in reply to: Mihai.Tanase

Something like this perhaps.

 

(defun C:MultipleXr (/ ENT HND I LST MYXREF MYXREFS OBJ SS XREFLST); define the function
  (setq	myxrefs	'("C:\\Dropbox\\Acad stuff\\Test\\Test1.dwg" "C:\\Dropbox\\Acad stuff\\Test\\Test2.dwg"))
  (foreach xref	myxrefs
    (if	(findfile xref)
      (setq xreflst (cons xref xreflst))
    );; if
  );; foreach
  (if xreflst
    (progn
      (if (setq ss (ssget "_X" '((0 . "INSERT"))))
	(progn
	(repeat	(setq i (sslength ss))
	  (setq	hnd (ssname ss (setq i (1- i)))
		ent (entget hnd)
		obj (vlax-ename->vla-object hnd)
	  );; setq
	  (if (vlax-property-available-p obj 'Path)
	    (if	(findfile (vla-get-path obj))
	      (setq lst (cons (cdr (assoc 2 ent)) lst))
	    );; if
	  );; if
	);; repeat
	(setvar "ctab" "Model"); move to modelspace
	(setvar "clayer" "0"); set the current layer to 0
	(command "ucs" "w")
	(if lst
	  (foreach xref	xreflst
	    (if	(not (member (vl-filename-base xref) lst))
	      (command "-xref" "Overlay" xref "0,0,0" "1" "1" "0")
	    );; if
	  );; foreach
	  (foreach xref	xreflst
	    (command "-xref" "Overlay" myxref "0,0,0" "1" "1" "0")
	  );; foreach
	);; if
	);; progn
      );; if
    );; progn
  );; if
  (princ)
);; MultipleXr

 

HTH

Henrique

EESignature

Message 3 of 6
Mihai.Tanase
in reply to: hmsilva

Tank you for the quick reply but i doesnt seem to work.

I load it up but when i run the command nothing hapens.

I wish i could say more but i have to say i understand maybe half of it. Smiley Tongue

 

 

Message 4 of 6
hmsilva
in reply to: Mihai.Tanase

Sorry Mihai,

the code had a typo!

 

I have commented the code to facilitate its comprehension.

The code is untested, I don't have AutoCAD in this laptop...

 

EDIT: after reread the code, I found an error, I think it is already fixed...

 

(defun C:MultipleXr (/ ENT HND I LST MYXREF MYXREFS OBJ SS XREFLST); define the function
  ;; sets a list with your xref names
  (setq	myxrefs	'("C:\\Dropbox\\Acad stuff\\Test\\Test1.dwg"
		  "C:\\Dropbox\\Acad stuff\\Test\\Test2.dwg"
		 )
  );; test if find each file
  (foreach xref	myxrefs
    (if	(findfile xref)
      ;; if find, create a list with the xrefs
      (setq xreflst (cons xref xreflst))
    );; if
  );; foreach
  ;; if found xref list exist
  (if xreflst
    (progn
      (setvar "ctab" "Model"); move to modelspace
      (setvar "clayer" "0"); set the current layer to 0
      (command "ucs" "w")
      ;; try to select all inserts
      (if (setq ss (ssget "_X" '((0 . "INSERT"))))
	(progn
	  ;; if exist inserts
	  (repeat (setq i (sslength ss))
	    ;; step thru the selection set
	    (setq hnd (ssname ss (setq i (1- i)))
		  ent (entget hnd)
		  obj (vlax-ename->vla-object hnd)
	    );; setq
	    ;; to test if the insert have the Path propertie (xref)
	    (if	(vlax-property-available-p obj 'Path)
	      ;; if is a xref create a xref exclusion list,
	      ;; with only the xref name, not path or extension
	      (setq lst (cons (cdr (assoc 2 ent)) lst))
	    );; if
	  );; repeat
	  ;; if the exclusion list exist
	  (if lst
	    ;; test the if the xref to overlay don't
	    ;; exist in the exclusion list
	    (foreach xref xreflst
	      (if (not (member (vl-filename-base xref) lst))
		;; if not member, do the xref command
		(command "-xref" "Overlay" xref "0,0,0" "1" "1" "0")
	      );; if
	    );; foreach
	  );; if
	);; progn
	;; if don't exist inserts
	;; do the xref command to all the list elements
	(foreach xref xreflst
	  (command "-xref" "Overlay" xref "0,0,0" "1" "1" "0")
	);; foreach
      );; if
    );; progn
  );; if
  (princ)
);; MultipleXr

 

HTH

Henrique

EESignature

Message 5 of 6
Mihai.Tanase
in reply to: hmsilva

Thank you very much for your help.

 

I have done some testing and works like a charm Smiley Very Happy

 

One thing i had to do put the list components from setq myxref on a row with blankspace between.

 

Amazing that's all that i can say.

Message 6 of 6
hmsilva
in reply to: Mihai.Tanase

You're welcome.
Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost