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.
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 ?
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.
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.
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.
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.
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.
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.
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)
"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.
Can't find what you're looking for? Ask the community or share your knowledge.