Auto insertion of multiple dwg into a single dwg with LISP

Auto insertion of multiple dwg into a single dwg with LISP

Anonymous
Not applicable
3,322 Views
5 Replies
Message 1 of 6

Auto insertion of multiple dwg into a single dwg with LISP

Anonymous
Not applicable

Hi,

 

I have 20 dwg files, each one containing one page of a projet (all the pages are the same size). I would like to combine them all into a single dwg file. Right now, in AutoCAD 2012, I manually insert the dwg and manually (with the mouse) position them in a row. Then I save and everything is fine.

 

Now, I have 500 dwg files to combine this way. I want to create a LISP script to automate the process. Right now I have the following, but it doesn't work. This is my first lisp script and I am more a C++ guy 😉

 

 

(defun C:MyInsert ()
(vl-load-com)

(setq x 0)
(foreach path (vl-directory-files "C:/Users/My folder/" "*.dwg")

(command "-insert" path "x,0,0" "" "" "")
(setq x (+ x 100))
)

 

My goal is to insert every dwg files in the folder, but to with an offset of 100 in x with regard to the last one inserted.

 

To test my function, in the LISP console:

 

LISP test insert

 

But is returns "nil" twice.

 

So, if anyone could help me understand this...

 

Regards,

 

0 Likes
Accepted solutions (1)
3,323 Views
5 Replies
Replies (5)
Message 2 of 6

hmsilva
Mentor
Mentor

Untested....

 

(defun c:MyInsert ( / x)
   (vl-load-com)
   (setq x 0)
   (foreach path (vl-directory-files "C:/Users/My folder/" "*.dwg")
      (command "-insert" path (strcat (itoa x) ",0,0") "" "" "")
      (setq x (+ x 100))
   )
   (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 3 of 6

jdiala
Advocate
Advocate
Accepted solution
(defun C:MyInsert ()
(vl-load-com)

(setq x 0)
(foreach path (vl-directory-files "C:/Users/My folder/" "*.dwg")
(command "-insert" (strcat "C:/Users/My folder/" path) (list x 0.0 0.0)  "" "" "")
(setq x (+ x 100)) 
)
)
Message 4 of 6

jdiala
Advocate
Advocate
On your code "x,0,0", x is not evaluated hence giving you an error for a point. Also if "C:/Users/My folder/" is not in your support path, autocad will not be able able to find the file. So, concatenate the FolderName and the dwgname when you use insert.
Message 5 of 6

sameerulcdc
Contributor
Contributor

hi 

thank you for this lsp its working good

 

can u modify this lsp to existing block need to update with reference to insert from reference folder blocks 

 

thank you in advance

0 Likes
Message 6 of 6

baksconstructor
Advocate
Advocate

@sameerulcdc wrote:

can u modify this lsp to existing block need to update with reference to insert from reference folder blocks 


Use the Internet search for the word - "AutoImportCAD"

0 Likes