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

Batch WBLOCK of blocks in drawing?

16 REPLIES 16
Reply
Message 1 of 17
Anonymous
11948 Views, 16 Replies

Batch WBLOCK of blocks in drawing?

Anonymous
Not applicable
I am trying to find a way to export all of the blocks in a drawings into a
folder- basically what I have in mind is a script or something that would
WBLOCK all of the blocks in the selected drawing, using the original names
of the block, into the parent folder. It doesn't seem very difficult, please
help.
Thanks.

Batch WBLOCK of blocks in drawing?

I am trying to find a way to export all of the blocks in a drawings into a
folder- basically what I have in mind is a script or something that would
WBLOCK all of the blocks in the selected drawing, using the original names
of the block, into the parent folder. It doesn't seem very difficult, please
help.
Thanks.
16 REPLIES 16
Message 2 of 17
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
It's not difficult at all. Do you know lisp at all?

--
Kevin Nehls


"MTT" wrote in message
news:DADD9141E92256B781D95BFE627A7B52@in.WebX.maYIadrTaRb...
> I am trying to find a way to export all of the blocks in a drawings into a
> folder- basically what I have in mind is a script or something that would
> WBLOCK all of the blocks in the selected drawing, using the original names
> of the block, into the parent folder. It doesn't seem very difficult,
please
> help.
> Thanks.
>
>
0 Likes

It's not difficult at all. Do you know lisp at all?

--
Kevin Nehls


"MTT" wrote in message
news:DADD9141E92256B781D95BFE627A7B52@in.WebX.maYIadrTaRb...
> I am trying to find a way to export all of the blocks in a drawings into a
> folder- basically what I have in mind is a script or something that would
> WBLOCK all of the blocks in the selected drawing, using the original names
> of the block, into the parent folder. It doesn't seem very difficult,
please
> help.
> Thanks.
>
>
Message 3 of 17
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Very little... I can run routines!, and I know enough to pick through them
and change a few variables, etc.

"Kevin Nehls" wrote in message
news:CFD97AE3F299458518C75CB582483339@in.WebX.maYIadrTaRb...
> It's not difficult at all. Do you know lisp at all?
>
> --
> Kevin Nehls
>
>
> "MTT" wrote in message
> news:DADD9141E92256B781D95BFE627A7B52@in.WebX.maYIadrTaRb...
> > I am trying to find a way to export all of the blocks in a drawings into
a
> > folder- basically what I have in mind is a script or something that
would
> > WBLOCK all of the blocks in the selected drawing, using the original
names
> > of the block, into the parent folder. It doesn't seem very difficult,
> please
> > help.
> > Thanks.
> >
> >
>
>
0 Likes

Very little... I can run routines!, and I know enough to pick through them
and change a few variables, etc.

"Kevin Nehls" wrote in message
news:CFD97AE3F299458518C75CB582483339@in.WebX.maYIadrTaRb...
> It's not difficult at all. Do you know lisp at all?
>
> --
> Kevin Nehls
>
>
> "MTT" wrote in message
> news:DADD9141E92256B781D95BFE627A7B52@in.WebX.maYIadrTaRb...
> > I am trying to find a way to export all of the blocks in a drawings into
a
> > folder- basically what I have in mind is a script or something that
would
> > WBLOCK all of the blocks in the selected drawing, using the original
names
> > of the block, into the parent folder. It doesn't seem very difficult,
> please
> > help.
> > Thanks.
> >
> >
>
>
Message 4 of 17
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Well, if I had the time I'd write one up. I thought I had one but I can't
find it right now. If you try over in the customization NG you might find
someone that's already got one written. Sometimes people will help out and
just write one for you other times you might get criticized for at least not
giving it a try.

--
Kevin Nehls


"MTT" wrote in message
news:B60DB71FE65987A1BE4CFA11D729810E@in.WebX.maYIadrTaRb...
> Very little... I can run routines!, and I know enough to pick through them
> and change a few variables, etc.
0 Likes

Well, if I had the time I'd write one up. I thought I had one but I can't
find it right now. If you try over in the customization NG you might find
someone that's already got one written. Sometimes people will help out and
just write one for you other times you might get criticized for at least not
giving it a try.

--
Kevin Nehls


"MTT" wrote in message
news:B60DB71FE65987A1BE4CFA11D729810E@in.WebX.maYIadrTaRb...
> Very little... I can run routines!, and I know enough to pick through them
> and change a few variables, etc.
Message 5 of 17
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
I think this program does what you want

(defun c:wblockm ()
(setq cmdecho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
;
(if (not dos_getdir)
(setq path (getstring "\nDS> Target Folder: " T))
(setq path (dos_getdir "Target Folder" (getvar "DWGPREFIX")))
)
(if (/= path nil)
(progn
(if (= (substr path (strlen path) 1) "\\")
(setq path (substr path 1 (1- (strlen path))))
)
(princ "\nDS> Building List of Blocks ... ")
(setq lst nil)
(setq itm (tblnext "BLOCK" T))
(while (/= itm nil)
(setq nam (cdr (assoc 2 itm)))
(setq pass T)
(if (/= (cdr (assoc 1 itm)) nil)
(setq pass nil)
(progn
(setq ctr 1)
(repeat (strlen nam)
(setq chk (substr nam ctr 1))
(if (or (= chk "*")(= chk "|"))
(setq pass nil)
)
(setq ctr (1+ ctr))
)
)
)
(if (= pass T)
(setq lst (cons nam lst))
)
(setq itm (tblnext "BLOCK"))
)
(setq lst (acad_strlsort lst))
(princ "Done.")
;
(foreach blk lst
(setq fn (strcat path (chr 92) blk))
(if (findfile (strcat fn ".dwg"))
(command "_.WBLOCK" fn "_Y" blk)
(command "_.WBLOCK" fn blk)
)
)
)
)
;
(setvar "CMDECHO" cmdecho)
(princ)
)

I think this program does what you want

(defun c:wblockm ()
(setq cmdecho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
;
(if (not dos_getdir)
(setq path (getstring "\nDS> Target Folder: " T))
(setq path (dos_getdir "Target Folder" (getvar "DWGPREFIX")))
)
(if (/= path nil)
(progn
(if (= (substr path (strlen path) 1) "\\")
(setq path (substr path 1 (1- (strlen path))))
)
(princ "\nDS> Building List of Blocks ... ")
(setq lst nil)
(setq itm (tblnext "BLOCK" T))
(while (/= itm nil)
(setq nam (cdr (assoc 2 itm)))
(setq pass T)
(if (/= (cdr (assoc 1 itm)) nil)
(setq pass nil)
(progn
(setq ctr 1)
(repeat (strlen nam)
(setq chk (substr nam ctr 1))
(if (or (= chk "*")(= chk "|"))
(setq pass nil)
)
(setq ctr (1+ ctr))
)
)
)
(if (= pass T)
(setq lst (cons nam lst))
)
(setq itm (tblnext "BLOCK"))
)
(setq lst (acad_strlsort lst))
(princ "Done.")
;
(foreach blk lst
(setq fn (strcat path (chr 92) blk))
(if (findfile (strcat fn ".dwg"))
(command "_.WBLOCK" fn "_Y" blk)
(command "_.WBLOCK" fn blk)
)
)
)
)
;
(setvar "CMDECHO" cmdecho)
(princ)
)
Message 6 of 17
Anonymous
in reply to: Anonymous

Anonymous
Not applicable
Jim,
Thank you- that works perfectly. I appreciate the help. I looked through the
LISP, and I don't think I could have figured that out myself, in a LONG
time.

Matt.
"JIMSMART" wrote in message
news:f14a720.3@WebX.maYIadrTaRb...
I think this program does what you want
(defun c:wblockm ()
(setq cmdecho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
;
(if (not dos_getdir)
(setq path (getstring "\nDS> Target Folder: " T))
(setq path (dos_getdir "Target Folder" (getvar "DWGPREFIX")))
)
(if (/= path nil)
(progn
(if (= (substr path (strlen path) 1) "\\")
(setq path (substr path 1 (1- (strlen path))))
)
(princ "\nDS> Building List of Blocks ... ")
(setq lst nil)
(setq itm (tblnext "BLOCK" T))
(while (/= itm nil)
(setq nam (cdr (assoc 2 itm)))
(setq pass T)
(if (/= (cdr (assoc 1 itm)) nil)
(setq pass nil)
(progn
(setq ctr 1)
(repeat (strlen nam)
(setq chk (substr nam ctr 1))
(if (or (= chk "*")(= chk "|"))
(setq pass nil)
)
(setq ctr (1+ ctr))
)
)
)
(if (= pass T)
(setq lst (cons nam lst))
)
(setq itm (tblnext "BLOCK"))
)
(setq lst (acad_strlsort lst))
(princ "Done.")
;
(foreach blk lst
(setq fn (strcat path (chr 92) blk))
(if (findfile (strcat fn ".dwg"))
(command "_.WBLOCK" fn "_Y" blk)
(command "_.WBLOCK" fn blk)
)
)
)
)
;
(setvar "CMDECHO" cmdecho)
(princ)
)
0 Likes

Jim,
Thank you- that works perfectly. I appreciate the help. I looked through the
LISP, and I don't think I could have figured that out myself, in a LONG
time.

Matt.
"JIMSMART" wrote in message
news:f14a720.3@WebX.maYIadrTaRb...
I think this program does what you want
(defun c:wblockm ()
(setq cmdecho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
;
(if (not dos_getdir)
(setq path (getstring "\nDS> Target Folder: " T))
(setq path (dos_getdir "Target Folder" (getvar "DWGPREFIX")))
)
(if (/= path nil)
(progn
(if (= (substr path (strlen path) 1) "\\")
(setq path (substr path 1 (1- (strlen path))))
)
(princ "\nDS> Building List of Blocks ... ")
(setq lst nil)
(setq itm (tblnext "BLOCK" T))
(while (/= itm nil)
(setq nam (cdr (assoc 2 itm)))
(setq pass T)
(if (/= (cdr (assoc 1 itm)) nil)
(setq pass nil)
(progn
(setq ctr 1)
(repeat (strlen nam)
(setq chk (substr nam ctr 1))
(if (or (= chk "*")(= chk "|"))
(setq pass nil)
)
(setq ctr (1+ ctr))
)
)
)
(if (= pass T)
(setq lst (cons nam lst))
)
(setq itm (tblnext "BLOCK"))
)
(setq lst (acad_strlsort lst))
(princ "Done.")
;
(foreach blk lst
(setq fn (strcat path (chr 92) blk))
(if (findfile (strcat fn ".dwg"))
(command "_.WBLOCK" fn "_Y" blk)
(command "_.WBLOCK" fn blk)
)
)
)
)
;
(setvar "CMDECHO" cmdecho)
(princ)
)
Message 7 of 17
GavrielKing
in reply to: Anonymous

GavrielKing
Advocate
Advocate
This DOES work perfectly!!!! Can you tell me where I would put a "default" Target Directory so the user won't have to enter it manually? ALSO, do you have one that will automatically convert the wblocks to 2000.dwg when using AutoCAD 2006? Or, do you know of a way to convert an entire directory of dwg files from 2004 to 2000, without having to specify any filenames and without having to use the batch drawing converter? I am probably dreaming of the impossible, but I thought I would ask. Any advice is greatly appreciated. Thank you.
0 Likes

This DOES work perfectly!!!! Can you tell me where I would put a "default" Target Directory so the user won't have to enter it manually? ALSO, do you have one that will automatically convert the wblocks to 2000.dwg when using AutoCAD 2006? Or, do you know of a way to convert an entire directory of dwg files from 2004 to 2000, without having to specify any filenames and without having to use the batch drawing converter? I am probably dreaming of the impossible, but I thought I would ask. Any advice is greatly appreciated. Thank you.
Message 8 of 17
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Thanks for your work JIMSMART, it does precisely what I was looking for. We're in the middle of a transition from Autocad to Revit MEP and I have to create all symbols based on our cad library. I just open our block files, run the LISP, then import the wblock into Revit and save the family as is.

 

Great time saver. Great saviour.

0 Likes

Thanks for your work JIMSMART, it does precisely what I was looking for. We're in the middle of a transition from Autocad to Revit MEP and I have to create all symbols based on our cad library. I just open our block files, run the LISP, then import the wblock into Revit and save the family as is.

 

Great time saver. Great saviour.

Message 9 of 17
stevor
in reply to: GavrielKing

stevor
Collaborator
Collaborator
1. re 'Default' for contents variable of path, ONE way: is to use the standard old get_s, of various names. ; from http://auscadd.com/free-lsp-1.html ; Getstring with Default, no test for prompt string, no spaces (defun Get_S (ds ps / gs ) (if (not (STR_P ds)) (setq ds "-" )) (setq gs (strcase (getstring (strcat ; not incLude spaces ps " < " ds " > " ) )) ) (if (= "" gs) ds gs )) ; from JIMSMART's code (defun c:wblockm () (setq cmdecho (getvar "CMDECHO")) (setvar "CMDECHO" 0) ;| start change here (if (not dos_getdir) (setq path (getstring "\nDS> Target Folder: " T)) (setq path (dos_getdir "Target Folder" (getvar "DWGPREFIX"))) ) |; end of removed code, begin added code (setq wb*path (if wb*path wb*path (getvar "DWGPREFIX") ) wb*path (Get_S wb*path "\n Target Folder ")) (setq path wb*path ) ; end of change, resume original code 2. re: 'Save format to 2000:' plenty of BATCH methods here and eslewhere; but maybe someone has the shortcut.
S
0 Likes

1. re 'Default' for contents variable of path, ONE way: is to use the standard old get_s, of various names. ; from http://auscadd.com/free-lsp-1.html ; Getstring with Default, no test for prompt string, no spaces (defun Get_S (ds ps / gs ) (if (not (STR_P ds)) (setq ds "-" )) (setq gs (strcase (getstring (strcat ; not incLude spaces ps " < " ds " > " ) )) ) (if (= "" gs) ds gs )) ; from JIMSMART's code (defun c:wblockm () (setq cmdecho (getvar "CMDECHO")) (setvar "CMDECHO" 0) ;| start change here (if (not dos_getdir) (setq path (getstring "\nDS> Target Folder: " T)) (setq path (dos_getdir "Target Folder" (getvar "DWGPREFIX"))) ) |; end of removed code, begin added code (setq wb*path (if wb*path wb*path (getvar "DWGPREFIX") ) wb*path (Get_S wb*path "\n Target Folder ")) (setq path wb*path ) ; end of change, resume original code 2. re: 'Save format to 2000:' plenty of BATCH methods here and eslewhere; but maybe someone has the shortcut.
S
Message 10 of 17
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

Hi, May i know what should i do after i run the script.

0 Likes

Hi, May i know what should i do after i run the script.

Message 11 of 17
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

JIMSMART, thank you so much. Your script works beautifully.

 


@Anonymous wrote:

Hi, May i know what should i do after i run the script.


The code he wrote is defining a command called "wblockm". After pasting all of the stuff he wrote, just use wblockm like a regular command, and it will start working. Note that there's an m on the end. wblock is the built in command; wblockm is Jim's custom command.

 

Optional:

To make the process easier, one can make AutoCAD define Jim's custom command every time a document is opened.

-Type the command "VLISP" to bring up the LISP editor. Create a new LISP file, paste Jim's stuff, save it as wblockm.lsp in a location used for LISP files.

-In acaddoc.lsp, enter a line that says (load "wblockm.lsp")

http://jtbworld.com/autocad-acaddoc-lsp (information about acaddoc.lsp)

 

0 Likes

JIMSMART, thank you so much. Your script works beautifully.

 


@Anonymous wrote:

Hi, May i know what should i do after i run the script.


The code he wrote is defining a command called "wblockm". After pasting all of the stuff he wrote, just use wblockm like a regular command, and it will start working. Note that there's an m on the end. wblock is the built in command; wblockm is Jim's custom command.

 

Optional:

To make the process easier, one can make AutoCAD define Jim's custom command every time a document is opened.

-Type the command "VLISP" to bring up the LISP editor. Create a new LISP file, paste Jim's stuff, save it as wblockm.lsp in a location used for LISP files.

-In acaddoc.lsp, enter a line that says (load "wblockm.lsp")

http://jtbworld.com/autocad-acaddoc-lsp (information about acaddoc.lsp)

 

Message 12 of 17
Anonymous
in reply to: Anonymous

Anonymous
Not applicable

You are an angle Jim. Thanks!

You are an angle Jim. Thanks!

Message 13 of 17
aausummit
in reply to: Anonymous

aausummit
Contributor
Contributor

Thanks Jimsmart,


That worked great. Unfortunately, when using Civil 3D, I get prompted with a dialog asking if I want to include Map data with the WBLOCK. Not a problem with a drawing with only a few blocks, but when I did it with a converted Microsation TXDOT topo map drawing, it had several thousands of blocks. My workaround? (you'll love this). I put a thimble (don't ask) on the "N" key on my keyboard and put my phone on top and took a break instead of tapping No to the prompt manually. How much trouble would it be, if possible, to avoid that Aggie engineering hack and include that line in your lisp routine? 

===========
C3D 2020.5.2
===========
W10 Pro v1903/18362.1016
Intel Core i7-2600K CPU @3.40GHz
24 GB RAM
AMD Radeon HD 6900 Series
0 Likes

Thanks Jimsmart,


That worked great. Unfortunately, when using Civil 3D, I get prompted with a dialog asking if I want to include Map data with the WBLOCK. Not a problem with a drawing with only a few blocks, but when I did it with a converted Microsation TXDOT topo map drawing, it had several thousands of blocks. My workaround? (you'll love this). I put a thimble (don't ask) on the "N" key on my keyboard and put my phone on top and took a break instead of tapping No to the prompt manually. How much trouble would it be, if possible, to avoid that Aggie engineering hack and include that line in your lisp routine? 

===========
C3D 2020.5.2
===========
W10 Pro v1903/18362.1016
Intel Core i7-2600K CPU @3.40GHz
24 GB RAM
AMD Radeon HD 6900 Series
Message 14 of 17
Woon22
in reply to: Anonymous

Woon22
Contributor
Contributor

Hi there I know this is an old post but I am looking for a way to wblock multiple blocks into individual DXF files but it retains the blocks current state (there are parameters and actions). The reason I want to retain the block is because I have a bunch of blocks that are fairly complicated and they are linked to a table so they can automatically update width and height. I have found lisp routines that wblock the blocks themselves but I need the blocks to be retained in the current state. This is my first post and maybe I am asking in the wrong topic section but I figured I had to start somewhere. I can post drawing examples if need be. Thanks

0 Likes

Hi there I know this is an old post but I am looking for a way to wblock multiple blocks into individual DXF files but it retains the blocks current state (there are parameters and actions). The reason I want to retain the block is because I have a bunch of blocks that are fairly complicated and they are linked to a table so they can automatically update width and height. I have found lisp routines that wblock the blocks themselves but I need the blocks to be retained in the current state. This is my first post and maybe I am asking in the wrong topic section but I figured I had to start somewhere. I can post drawing examples if need be. Thanks

Message 15 of 17
mattia.conatoF3EFB
in reply to: Anonymous

mattia.conatoF3EFB
Explorer
Explorer
I found this very useful for my work, thanks!
I'd like to ask a thing though. Using this routine it generates all the different dwgs in the specified folder as expected, but as soon as I open one of the files, AutoCAD opens a window saying "blockname.dwg contains creation elements. Open in Block Editor?". Basically, the dwg does contain the block definition only, but nothing in the drawing.
My question is then: is there a way to have in this routine something that avoids the popup of this window? Something like: I create you a dwg file which contains the block (defined as the original file) and nothing else. I ask this because I have hundreds of blocks to manage and an automated way to produce dwg ready-to-use could be a gamechanger for me.
Every help is appreciated, thanks.
0 Likes

I found this very useful for my work, thanks!
I'd like to ask a thing though. Using this routine it generates all the different dwgs in the specified folder as expected, but as soon as I open one of the files, AutoCAD opens a window saying "blockname.dwg contains creation elements. Open in Block Editor?". Basically, the dwg does contain the block definition only, but nothing in the drawing.
My question is then: is there a way to have in this routine something that avoids the popup of this window? Something like: I create you a dwg file which contains the block (defined as the original file) and nothing else. I ask this because I have hundreds of blocks to manage and an automated way to produce dwg ready-to-use could be a gamechanger for me.
Every help is appreciated, thanks.
Message 16 of 17
Sea-Haven
in reply to: aausummit

Sea-Haven
Mentor
Mentor

If your using CIV3D then just look for the line in the code that is WBLOCK and add the "N" if I remember correctly as last item in the wblock line. 

If your using CIV3D then just look for the line in the code that is WBLOCK and add the "N" if I remember correctly as last item in the wblock line. 

Message 17 of 17

mattia.conatoF3EFB
Explorer
Explorer
Thanks for your reply! Unfortunately I'm using AutoCAD LT. I don't think it is the same, probably...
0 Likes

Thanks for your reply! Unfortunately I'm using AutoCAD LT. I don't think it is the same, probably...

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report