Author Topic: Extract Blocks From A DWG to Separate Files  (Read 1211 times)

0 Members and 1 Guest are viewing this topic.

Rob...

  • King Gator
  • Posts: 3815
  • Take a little time to stop and smell the roses.
Extract Blocks From A DWG to Separate Files
« 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
CAD Tech

ronjonp

  • Needs a day job
  • Posts: 7111
Re: Extract Blocks From A DWG to Separate Files
« Reply #1 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)
)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Rob...

  • King Gator
  • Posts: 3815
  • Take a little time to stop and smell the roses.
Re: Extract Blocks From A DWG to Separate Files
« Reply #2 on: May 20, 2014, 10:41:23 AM »
Thank you, about to give it a test run. Will report back shortly.
CAD Tech

Rob...

  • King Gator
  • Posts: 3815
  • Take a little time to stop and smell the roses.
Re: Extract Blocks From A DWG to Separate Files
« Reply #3 on: May 20, 2014, 10:48:58 AM »
It works like a charm! Thank you very much!
CAD Tech

ronjonp

  • Needs a day job
  • Posts: 7111
Re: Extract Blocks From A DWG to Separate Files
« Reply #4 on: May 20, 2014, 11:04:05 AM »
It works like a charm! Thank you very much!


Glad to help  :)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC