TheSwamp

CAD Forums => CAD General => Topic started by: Rob... on May 20, 2014, 08:52:14 AM

Title: Extract Blocks From A DWG to Separate Files
Post by: Rob... on May 20, 2014, 08:52:14 AM
A quick search didn't reveal anything useful. Does anyone have a method or a LISP for saving blocks from a file out to separate files using the block name as the file name?

TIA
Title: Re: Extract Blocks From A DWG to Separate Files
Post by: ronjonp on May 20, 2014, 10:23:14 AM
Here's a quickie:
Code: [Select]
(defun c:exportblocks (/ blk blks x dir)
  (vl-load-com)
  (if (setq blks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
    (progn (setvar 'filedia 0)
   (setq dir (strcat (getvar 'dwgprefix) "_ExportedBlocks\\"))
   (vl-mkdir dir)
   (vlax-for blk blks
     (if (and (not (wcmatch (setq x (vla-get-name blk)) "*|*,*`**"))
      (= (vla-get-isxref blk) :vlax-false)
)
       (command "._-wblock" (strcat dir x) x)
     )
   )
   (setvar 'filedia 1)
    )
  )
  (princ)
)
Title: Re: Extract Blocks From A DWG to Separate Files
Post by: Rob... on May 20, 2014, 10:41:23 AM
Thank you, about to give it a test run. Will report back shortly.
Title: Re: Extract Blocks From A DWG to Separate Files
Post by: Rob... on May 20, 2014, 10:48:58 AM
It works like a charm! Thank you very much!
Title: Re: Extract Blocks From A DWG to Separate Files
Post by: ronjonp on May 20, 2014, 11:04:05 AM
It works like a charm! Thank you very much!


Glad to help  :)