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

Batch insert blocks...

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
1153 Views, 10 Replies

Batch insert blocks...

okay a bit of a weird request.

But i want to insert a directory of blocks into a dwg file and have each
instance of the block insertion point be offset by 10 on the x axis.

-insert block "A" at 0,0 ; -insert block "B" at 10,0, etc.

Has anyone seen a lisp to do this?

--
________________________________
replace [dot] from e-mail if replying directly
________________________________
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: Anonymous

The Real JD wrote:
> okay a bit of a weird request.
>
> But i want to insert a directory of blocks into a dwg file and have each
> instance of the block insertion point be offset by 10 on the x axis.
>
> -insert block "A" at 0,0 ; -insert block "B" at 10,0, etc.
>
> Has anyone seen a lisp to do this?
>

No, but it wouldn't be hard to write one:

dos_getdir to select directory

vl-directory-files to get a list of files

setq insertpoint (list 0 0 0)

foreach file in the file list
insert file at insertpoint.....
setq insertpoint
(list
(+ 10 (cadr insertpoint))
(caddr insertpoint)
(cadddr insertpoint)
)

done
Message 3 of 11
Anonymous
in reply to: Anonymous

Thanks for pointing me in the right direction. My lisp skills are basic at
best, but i'll see what i can do with it. Thx!

"Kevin Nehls" wrote in message
news:4873536@discussion.autodesk.com...
The Real JD wrote:
> okay a bit of a weird request.
>
> But i want to insert a directory of blocks into a dwg file and have each
> instance of the block insertion point be offset by 10 on the x axis.
>
> -insert block "A" at 0,0 ; -insert block "B" at 10,0, etc.
>
> Has anyone seen a lisp to do this?
>

No, but it wouldn't be hard to write one:

dos_getdir to select directory

vl-directory-files to get a list of files

setq insertpoint (list 0 0 0)

foreach file in the file list
insert file at insertpoint.....
setq insertpoint
(list
(+ 10 (cadr insertpoint))
(caddr insertpoint)
(cadddr insertpoint)
)

done
Message 4 of 11
Anonymous
in reply to: Anonymous

The Real JD wrote:
> Thanks for pointing me in the right direction. My lisp skills are basic at
> best, but i'll see what i can do with it. Thx!

If you have any questions or get stuck just ask. We've all been there.
Message 5 of 11
Anonymous
in reply to: Anonymous

Already stuck...

I was looking in autocad help to get the syntax right for the foreach...
it's talking about stacks and doesn't provide an example...

any help would be appreciated
Message 6 of 11
Anonymous
in reply to: Anonymous

This is what i've got so far..

(defun c:quikinsert ()
(setq dir1 (dos_getdir))
(setq lst1 (vl-directory-files dir1 "*.dwg" 1))
(setq insertpoint (list 0 0 0))
(foreach mydwg lst1 ()
(command "-insert" mydwg
(setq insertpoint
(list
(+ 10 (cadr insertpoint))
(caddr insertpoint)
(cadddr insertpoint)
))
"1" "1" "1" "0")
))

It looks like it will go to insert but can't find the file because it's not
part of the path.
Should i be doing this in another way? Or is there another variable list to
get the path with the drawings, and not just the drawing files name....
Message 7 of 11
Anonymous
in reply to: Anonymous

The Real JD wrote:
> This is what i've got so far..
>
> (defun c:quikinsert ()
> (setq dir1 (dos_getdir))
--> Take a look at the documentation for dos_getdir, there's some
additional parameters you can pass to customize it a little more if you
like.

> (setq lst1 (vl-directory-files dir1 "*.dwg" 1))

Crap! Forgot one major point, you need to append the directory to each
drawing....
(setq lst1
(mapcar '(lambda (x)
(strcat dir1 x))
lst1)
)

> (setq insertpoint (list 0 0 0))
> (foreach mydwg lst1 ()
> (command "-insert" mydwg
(command "-insert" mydwg insertpoint "1" "1" "0")
--> This should be your entire INSERT command

Now set insertpoint to the new value offset for the new location
> (setq insertpoint
> (list
> (+ 10 (cadr insertpoint))
> (caddr insertpoint)
> (cadddr insertpoint)
> ))

> )
--> Remove that paren, your command should finish as I show above.

> ))
>
> It looks like it will go to insert but can't find the file because it's not
> part of the path.
> Should i be doing this in another way? Or is there another variable list to
> get the path with the drawings, and not just the drawing files name....

Sorry about that, the fix is above.
Message 8 of 11
Anonymous
in reply to: Anonymous

I added the path (as seen below) it worked for finding the first one, but it
gets stuck on the insertion giving an error.

I'll modify the code to what you posted. Thanks!

(setq dir1 (dos_getdir))
(setq lst1 (vl-directory-files dir1 "*.dwg" 1))
(setq insertpoint (list 0 0 0))
(foreach mydwg lst1
(command "-insert" (strcat dir1 mydwg)
(setq insertpoint
(list
(+ 10 (cadr insertpoint))
(caddr insertpoint)
(cadddr insertpoint)
)
)
)
)

"Kevin Nehls" wrote in message
news:4873721@discussion.autodesk.com...
The Real JD wrote:
> This is what i've got so far..
>
> (defun c:quikinsert ()
> (setq dir1 (dos_getdir))
--> Take a look at the documentation for dos_getdir, there's some
additional parameters you can pass to customize it a little more if you
like.

> (setq lst1 (vl-directory-files dir1 "*.dwg" 1))

Crap! Forgot one major point, you need to append the directory to each
drawing....
(setq lst1
(mapcar '(lambda (x)
(strcat dir1 x))
lst1)
)

> (setq insertpoint (list 0 0 0))
> (foreach mydwg lst1 ()
> (command "-insert" mydwg
(command "-insert" mydwg insertpoint "1" "1" "0")
--> This should be your entire INSERT command

Now set insertpoint to the new value offset for the new location
> (setq insertpoint
> (list
> (+ 10 (cadr insertpoint))
> (caddr insertpoint)
> (cadddr insertpoint)
> ))

> )
--> Remove that paren, your command should finish as I show above.

> ))
>
> It looks like it will go to insert but can't find the file because it's
not
> part of the path.
> Should i be doing this in another way? Or is there another variable list
to
> get the path with the drawings, and not just the drawing files name....

Sorry about that, the fix is above.
Message 9 of 11
Anonymous
in reply to: Anonymous

All of the (cad....)'s below need 1 d removed, should be (car ...) (cadr
...) (caddr ...)
(setq insertpoint
(list
(+ 10 (cadr insertpoint))
(caddr insertpoint)
(cadddr insertpoint)
)
)

"The Real JD" wrote in message
news:4873738@discussion.autodesk.com...
I added the path (as seen below) it worked for finding the first one, but it
gets stuck on the insertion giving an error.

I'll modify the code to what you posted. Thanks!

(setq dir1 (dos_getdir))
(setq lst1 (vl-directory-files dir1 "*.dwg" 1))
(setq insertpoint (list 0 0 0))
(foreach mydwg lst1
(command "-insert" (strcat dir1 mydwg)
(setq insertpoint
(list
(+ 10 (cadr insertpoint))
(caddr insertpoint)
(cadddr insertpoint)
)
)
)
)

"Kevin Nehls" wrote in message
news:4873721@discussion.autodesk.com...
The Real JD wrote:
> This is what i've got so far..
>
> (defun c:quikinsert ()
> (setq dir1 (dos_getdir))
--> Take a look at the documentation for dos_getdir, there's some
additional parameters you can pass to customize it a little more if you
like.

> (setq lst1 (vl-directory-files dir1 "*.dwg" 1))

Crap! Forgot one major point, you need to append the directory to each
drawing....
(setq lst1
(mapcar '(lambda (x)
(strcat dir1 x))
lst1)
)

> (setq insertpoint (list 0 0 0))
> (foreach mydwg lst1 ()
> (command "-insert" mydwg
(command "-insert" mydwg insertpoint "1" "1" "0")
--> This should be your entire INSERT command

Now set insertpoint to the new value offset for the new location
> (setq insertpoint
> (list
> (+ 10 (cadr insertpoint))
> (caddr insertpoint)
> (cadddr insertpoint)
> ))

> )
--> Remove that paren, your command should finish as I show above.

> ))
>
> It looks like it will go to insert but can't find the file because it's
not
> part of the path.
> Should i be doing this in another way? Or is there another variable list
to
> get the path with the drawings, and not just the drawing files name....

Sorry about that, the fix is above.
Message 10 of 11
Anonymous
in reply to: Anonymous

Thanks Jeff!

And thanks Kevin for all the help!

"Jeff Mishler" wrote in message
news:4873744@discussion.autodesk.com...
All of the (cad....)'s below need 1 d removed, should be (car ...) (cadr
...) (caddr ...)
(setq insertpoint
(list
(+ 10 (cadr insertpoint))
(caddr insertpoint)
(cadddr insertpoint)
)
)

"The Real JD" wrote in message
news:4873738@discussion.autodesk.com...
I added the path (as seen below) it worked for finding the first one, but it
gets stuck on the insertion giving an error.

I'll modify the code to what you posted. Thanks!

(setq dir1 (dos_getdir))
(setq lst1 (vl-directory-files dir1 "*.dwg" 1))
(setq insertpoint (list 0 0 0))
(foreach mydwg lst1
(command "-insert" (strcat dir1 mydwg)
(setq insertpoint
(list
(+ 10 (cadr insertpoint))
(caddr insertpoint)
(cadddr insertpoint)
)
)
)
)

"Kevin Nehls" wrote in message
news:4873721@discussion.autodesk.com...
The Real JD wrote:
> This is what i've got so far..
>
> (defun c:quikinsert ()
> (setq dir1 (dos_getdir))
--> Take a look at the documentation for dos_getdir, there's some
additional parameters you can pass to customize it a little more if you
like.

> (setq lst1 (vl-directory-files dir1 "*.dwg" 1))

Crap! Forgot one major point, you need to append the directory to each
drawing....
(setq lst1
(mapcar '(lambda (x)
(strcat dir1 x))
lst1)
)

> (setq insertpoint (list 0 0 0))
> (foreach mydwg lst1 ()
> (command "-insert" mydwg
(command "-insert" mydwg insertpoint "1" "1" "0")
--> This should be your entire INSERT command

Now set insertpoint to the new value offset for the new location
> (setq insertpoint
> (list
> (+ 10 (cadr insertpoint))
> (caddr insertpoint)
> (cadddr insertpoint)
> ))

> )
--> Remove that paren, your command should finish as I show above.

> ))
>
> It looks like it will go to insert but can't find the file because it's
not
> part of the path.
> Should i be doing this in another way? Or is there another variable list
to
> get the path with the drawings, and not just the drawing files name....

Sorry about that, the fix is above.
Message 11 of 11
Anonymous
in reply to: Anonymous

Jeff Mishler wrote:
> All of the (cad....)'s below need 1 d removed, should be (car ...) (cadr
> ...) (caddr ...)

Good catch. That's what I get for not testing before posting 😉

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

Post to forums  

Autodesk Design & Make Report

”Boost