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

Batch WBlock lisp routine to export all blocks from wcs 0,0,0

11 REPLIES 11
Reply
Message 1 of 12
3DSDS
568 Views, 11 Replies

Batch WBlock lisp routine to export all blocks from wcs 0,0,0

Hi,

I am looking for a lisp routine to export all blocks to a specific folder from my drawing using WCS 0,0,0 as the standard export point.

Can someone please assist.

11 REPLIES 11
Message 2 of 12
tramber
in reply to: 3DSDS

Any block has its own basepoint. What do you mean ?

Are you planning to WBLOCK as they are or to, sort of, redefine them by their entites somewhere but a future basepoint in common with all the others, i.e. the WCS origin ?

Message 3 of 12
3DSDS
in reply to: 3DSDS

I found this:-
(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 would like this but have the all blocks WBlocked from 0,0,0 as a standard. 

Message 4 of 12
tramber
in reply to: 3DSDS

Your prog is easy to read : it gonna WBLOC them all with their own origin points.

Your goal is far from that because you want to redefine them all...

And I am guessing that you don't even know how to describe us what process would give a new base point to your blocks and how !

If a block has a basepoint, a human should work if he wants another one. 

Message 5 of 12
3DSDS
in reply to: 3DSDS

To explain the full story, I have a series of project drawings, large assemblies, and all of the parts are blocks.

Each block has an insertion point in the assembly that is relative to the origin, 0,0,0.

What I need is all the blocks exported to individual DWGs such that in their DWG they are positioned based upon the assembly origin of 0,0,0.

This is to allow me to edit each individual block in its own DWG and insert it back into the assembly at its original position based upon the origin of the total assembly which is 0,0,0.

Hopefully this makes more sense.

Thanks in advance.

Message 6 of 12
tramber
in reply to: 3DSDS

From where they are inserted !!!? Only once foreach I guess....

And that would be your base ?

Strange...

 

You gonna have to first change the basepoints and click 0,0 before WBLOC them...

Use this, I love it :

https://www.lee-mac.com/changeblockinsertion.html

 

Unless you don't want to change their basepoint in the source drawing but only when you export ? But you are not clear.

 

Message 7 of 12
3DSDS
in reply to: 3DSDS

To explain the full story, I have a series of project drawings, large assemblies, and all of the parts are blocks.

Each block has an insertion point in the assembly that is relative to the origin, 0,0,0.

What I need is all the blocks exported to individual DWGs such that in their DWG they are positioned based upon the assembly origin of 0,0,0.

This is to allow me to edit each individual block in its own DWG and insert it back into the assembly at its original position based upon the origin of the total assembly which is 0,0,0.

Hopefully this makes more sense.

Thanks in advance.

Message 8 of 12
TomBeauford
in reply to: 3DSDS

You could just modify the block in the drawing without WBLOCK

or

WBLOCK with the block without changing the origin to modify it then update the block in the drawing.

 

You seem to be going out of your way to make something simple hard.

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
Message 9 of 12
Sea-Haven
in reply to: 3DSDS

If you start with a blank model insert a block at 0,0,0 scale 1 rotation 0, then wblock the new dwg will be based around correct 0,0,0. I know have done it, and go on to next block. 

 

 

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-wblock-lisp-routine-to-export-all-blocks-from-wcs-0-0-0/td-p/12902870
; By AlanH July 2024

(defun exwblk ( / dir blk fname bname)
(setq dir "D:\\acadtemp\\wblocks\\") ;chamge to suit

(setvar 'attreq 0) ; no attributes input when inserting

(vlax-for blk (vla-get-blocks  (vla-get-activedocument (vlax-get-acad-object)))
 (princ (setq bname  (vlax-get blk 'name)))
 (setq fname (strcat dir bname))
 (if (or (= bname "*Model_Space")(= bname "*Paper_Space")(wcmatch bname "Aecc*")(= (substr bname 1 1) "*"))
  (princ (strcat "\n" bname ))
  (progn
  (command "-insert" bname "s" 1 "0,0,0" 0.0)
  (command "-wblock" fname  "" "0,0" (entlast) "")
 )
 )
)

(princ)
)

(exwblk)

 

 

Message 10 of 12
3DSDS
in reply to: 3DSDS

Thanks, cannot get it to work

Message 11 of 12
Sea-Haven
in reply to: 3DSDS

 "Thanks, cannot get it to work" who are you posting to ? What error messages did you get ? If mine tested on Bricscad V24, 178 dwg's made from one dwg. 

 

I did have some problems with some funny named blocks *X9, if it seems to error type !bname and hopefully the block name will appear that is causing problems. 

 

I have changed code above to skip  for any block with "*" as 1st character.

Message 12 of 12
komondormrex
in reply to: 3DSDS

hi, 

and every insert should be a singular one? 

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