Mass Insert - Insert all dwg files from folder - Help with Columns

Mass Insert - Insert all dwg files from folder - Help with Columns

Jeremy.Oakes
Contributor Contributor
257 Views
2 Replies
Message 1 of 3

Mass Insert - Insert all dwg files from folder - Help with Columns

Jeremy.Oakes
Contributor
Contributor

Hello All,

 

I have scrapped together the following from many sources. Currently I am able to insert all the dwg files from a folder with a specified distance between each insert. In this case 100.

 

What I am wanting to do is place these files in an array or grid pattern. Preferable with the option to define how many in the x and y directions.

 

(defun c:MASSINSERT (/ userFolder userList insertPT itm)

(setq userFolder (getfiled "Select folder" "" "dwg" 0)); path with dwg name
(setq userFolder (substr userFolder 1 (1+ (vl-string-position 92 userFolder 1 T)))); path without dwg name
(setq userList (vl-directory-files userFolder "*.dwg" 1))
(setq insertPT (list 0 0 0))

(foreach itm userList
	(command "-insert" (strcat userFolder itm) insertPT "" "" "")
		(setq insertPT
			(list
			(+ 100 (car insertPT));define x distance between inserts
			(cadr insertPT)
			(caddr insertPT)
			)
		)
)
)

 

I have tried to do something like define each point individually and then increment points as needed. Something like this:

(setq insertPT
	(list
		(+ 100 xPT)
		(cadr insertPT)
		(caddr insertPT)
	)
)

The issue I have here is when I introduce multiple points. Also, I would prefer that once the "column" gets to 10, I ant to start a new row.

 

How can I insert the files in my list to a grid or array pattern specifying the number of columns?

Any help would be appreciated.

Jeremy Oakes
AutoCAD and REVIT
0 Likes
258 Views
2 Replies
Replies (2)
Message 2 of 3

Gobel_A
Enthusiast
Enthusiast

I use a similar function for several different page sizes and therefore with manual selection of the distance between inserted drawings (blocks). Additionally with the option to explode the inserted drawing. But the ability to limit the number of inserted drawings after which it would start inserting under/above the already inserted ones would be handy for me too. The advantage for me is that all inserted drawings have the same frame size.

(defun c:InsertBlks (/ d doc lst pt pt1 dir b blk blkn ex xx)
 (vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (if
    (and (setq
       dir (vl-filename-directory
         (getfiled "Select a DWG for folder" (getvar 'dwgprefix) "dwg" 8)
           )
     )
     (setq lst (vl-directory-files dir "*.dwg"))
	 (setq xx (princ (strcat "\n" (itoa (length lst)) " blocks found")))
     (setq pt1 (getpoint "\nSelect ins.point for first block: "))
     (setq d
        (distance (getpoint pt1 "\nSelect distance to space blocks (or 0,0): ")
              pt1
        )
     )
	 (setq ex (= "Y" (strcase (getstring "\nExplode inserted blocks? [Y/N] <N>: "))) xx T)
    )
     (foreach b    lst
	   (princ (strcat "\n" b " "))
       (setq blk (vla-insertblock
       (if (= (getvar 'cvport) 1)
         (vla-get-paperspace doc)
         (vla-get-modelspace doc)
       )
     (vlax-3d-point (setq pt1 (polar pt1 0.0 d)))
     (strcat dir "\\" b)
     1
     1
     1
     0.0
       ));insert, setq
	  (if ex (progn
	    (princ " exploding")
	    (setq blkn (vla-get-effectivename blk))
		(vl-catch-all-apply 'vla-explode (list blk)) (vl-catch-all-apply 'vla-delete (list blk))
		(vl-catch-all-apply 'vla-delete (list (vla-item (vla-get-blocks doc) blkn)))
	  ))
    ); for
  )
  (princ "Done.")
  (princ)
)

 

0 Likes
Message 3 of 3

Sea-Haven
Mentor
Mentor

To make a grid of your dwg you need a double loop, like above use a foreach for the full list of dwg's, then have say the x value in a loop say (while (< x 11) when x = 11 you reset x back to 1. I would look at also getting bounding box of (entlast) and resize the insert to a suitable size like say 80 units so you dont get tiny blocks and blocks that overlap. 

 

Just a thought (fix  (sqrt numberofdwgs)) is grid X = Y. 

 

 

(foreach dwgname dwglist
(setq x 1)
(while (< x 11)
... if can open next dwg
.... do insert etc
(setq x (1+x))
)
(setq x 1)
)

 

 

 

0 Likes