Re arrange xrefs in a drawing

Re arrange xrefs in a drawing

aries.1482
Enthusiast Enthusiast
413 Views
6 Replies
Message 1 of 7

Re arrange xrefs in a drawing

aries.1482
Enthusiast
Enthusiast

Hi, I have a lisp to attach mutiple xrefs in one drawing (see attach file). But the problem is: all xrefs insert at (0,0,0) point, and I want re arrange them in row (see attach picture). Drawing name like: Drawing-01, Drawing-02, ...

 

Screenshot 2022-08-28 145524.png

 

Plz help me. Thank you in advance!

0 Likes
Accepted solutions (1)
414 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant

If the drawings would all be the same size as each other, as your image suggests, a routine could Xref the first one, find its width from its bounding box, increase that slightly for a spacing, and increment the insertion point to the right for each subsequent Xref.

 

If they wouldn't all be the same size, it could check the width of each one as it puts it in, to figure where to put the next one.  See BlockChart.lsp >here< for one that does that with Insert instead of Xref, but could easily be adapted.

Kent Cooper, AIA
0 Likes
Message 3 of 7

aries.1482
Enthusiast
Enthusiast

Thanks for reply, I understand theory, but I am not friendly with lisp, so can you help me with code directly?!

(P/s: The drawings wouldn't all be the same size)

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

Try this.

 

(defun C:MXR (/ path fp lst Reflst ref pnt dst)
  (setq path (strcat (getvar 'DWGPREFIX) "\\Pick List to import")
	fp (getfiled "Reference File List:" path "" 33)
	path (vl-filename-directory fp)
	lst (vl-directory-files path "*.dwg" 1)
	;lst (append lst (vl-directory-files path "*.dxf" 1)) ;if you want to see other types of files
	lst (vl-sort lst '<)
	)
  (if (and (setq Reflst (AT:ListSelect (strcat (itoa (length lst)) " Reference(s) in Folder") "Pick Reference(s) to Insert Into Drawing" 30 60 "true" lst))
	   (setq dst (getdist "Specify offset: "))
	   (setq pnt (polar '(0 0 0) pi dst))
	   )
    (foreach ref Reflst
      (command "_.-XREF" "_Overlay" (strcat path "\\" ref) "_non" (setq pnt (polar pnt 0 dst)) "" "" "")
      )
    )
  (princ)
  )

;; List Select Dialog (Temp DCL list box selection, based on provided list)
;; title - list box title
;; label - label for list box
;; height - height of box
;; width - width of box
;; multi - selection method ["true": multiple, "false": single]
;; lst - list of strings to place in list box
;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
(defun AT:ListSelect (title label height width multi lst / fn fo d f)
  (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
		   (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
		   (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
		   (strcat "width = " (vl-princ-to-string width) ";")
		   (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
		   )
    (write-line x fo)
    )
  (close fo)
  (new_dialog "list_select" (setq d (load_dialog fn)))
  (start_list "lst")
  (mapcar (function add_list) lst)
  (end_list)
  (setq item (set_tile "lst" "0"))
  (action_tile "lst" "(setq item $value)")
  (setq f (start_dialog))
  (unload_dialog d)
  (vl-file-delete fn)
  (if (= f 1)
    ((lambda (s / i s l)
       (while (setq i (vl-string-search " " s))
	 (setq l (cons (nth (atoi (substr s 1 i)) lst) l))
	 (setq s (substr s (+ 2 i)))
	 )
       (reverse (cons (nth (atoi s) lst) l))
       )
      item
      )
    )
  )

 

Message 5 of 7

aries.1482
Enthusiast
Enthusiast
Your code let me put in space between the drawings, but it may be too small or too big. I need it auto calculate, depend the width of each drawing.
0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Well, your drawings 01-05 seem pretty much the same.

 

(defun C:MXR (/ path fp lst Reflst ref pnt dst wid mnm)
  
  
  (setq path (strcat (getvar 'DWGPREFIX) "\\Pick List to import")
	fp (getfiled "Reference File List:" path "" 33)
	path (vl-filename-directory fp)
	lst (vl-directory-files path "*.dwg" 1)
	;lst (append lst (vl-directory-files path "*.dxf" 1)) ;if you want to see other types of files
	lst (vl-sort lst '<)
	)
  (if (and (setq Reflst (AT:ListSelect (strcat (itoa (length lst)) " Reference(s) in Folder") "Pick Reference(s) to Insert Into Drawing" 30 60 "true" lst))
	   (setq pnt '(0 0 0))
	   )
    (foreach ref Reflst
      (command "_.-XREF" "_Overlay" (strcat path "\\" ref) "_non" pnt "" "" "")
      (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list (vlax-ename->vla-object (entlast)) 'll 'ur))))
	(setq mnm (vlax-safearray->list ll)
	      wid (apply '- (reverse (mapcar 'car (mapcar 'vlax-safearray->list (list ll ur)))))))
      (or dst (setq dst (/ wid 10.)))
      (entmod (append (entget (entlast)) (list (cons 10 (mapcar '+ pnt (mapcar '- pnt mnm))))))
      (setq pnt (polar pnt 0 (+ wid dst)))))
  
  (princ)
  )

;; List Select Dialog (Temp DCL list box selection, based on provided list)
;; title - list box title
;; label - label for list box
;; height - height of box
;; width - width of box
;; multi - selection method ["true": multiple, "false": single]
;; lst - list of strings to place in list box
;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
(defun AT:ListSelect (title label height width multi lst / fn fo d f)
  (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
  (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
		   (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
		   (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
		   (strcat "width = " (vl-princ-to-string width) ";")
		   (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
		   )
    (write-line x fo)
    )
  (close fo)
  (new_dialog "list_select" (setq d (load_dialog fn)))
  (start_list "lst")
  (mapcar (function add_list) lst)
  (end_list)
  (setq item (set_tile "lst" "0"))
  (action_tile "lst" "(setq item $value)")
  (setq f (start_dialog))
  (unload_dialog d)
  (vl-file-delete fn)
  (if (= f 1)
    ((lambda (s / i s l)
       (while (setq i (vl-string-search " " s))
	 (setq l (cons (nth (atoi (substr s 1 i)) lst) l))
	 (setq s (substr s (+ 2 i)))
	 )
       (reverse (cons (nth (atoi s) lst) l))
       )
      item
      )
    )
  )

 

Message 7 of 7

aries.1482
Enthusiast
Enthusiast
Thanks! That's what I need.
0 Likes