Author Topic: Exporting Blocks to DWG files?  (Read 13409 times)

0 Members and 1 Guest are viewing this topic.

Atook

  • Swamp Rat
  • Posts: 994
  • AKA Tim
Exporting Blocks to DWG files?
« on: November 08, 2006, 11:49:07 AM »
Is there a way to export blocks in a drawing to seperate DWG files named after the block? Sort of a backwards insert if you will.

I know I can manually do it, set scale to 1, explode, wblock then move insertion to 0,0.

But I'm hoping to do this for a bunch of blocks in one drawing. I tried dragging the blocks from design center to a folder, but that didn't work. Any ideas?

Arizona

  • Guest
Re: Exporting Blocks to DWG files?
« Reply #1 on: November 08, 2006, 12:02:31 PM »
Since a block can be a drawing file it sounds like what you need to do is just create a wblock so that they are written to file. No need to insert them in another drawing.
How were you considering handling the quantities you have, programmatically?

ronjonp

  • Needs a day job
  • Posts: 7437
Re: Exporting Blocks to DWG files?
« Reply #2 on: November 08, 2006, 12:06:20 PM »

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

Atook

  • Swamp Rat
  • Posts: 994
  • AKA Tim
Re: Exporting Blocks to DWG files?
« Reply #3 on: November 08, 2006, 12:07:15 PM »
Doh! I've only used wblock to write selected objects to a file. I didn't even look for the option to write a block!

Thanks for the quick answer to an obvious question!

ronjonp

  • Needs a day job
  • Posts: 7437
Re: Exporting Blocks to DWG files?
« Reply #4 on: November 08, 2006, 12:32:13 PM »
This may do what you want.....Exports blocks to picked directory.

Code: [Select]
(defun c:exportblocks (/ blk blks x dir)
  (setq
    blks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    dir (vl-filename-directory
   (getfiled "Select file to specify folder to place blocks:"
     (getvar 'dwgprefix)
     ""
     16
   )
)
  )
  (setvar 'filedia 0)
  (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)
  (startapp "explorer" (strcat "/e," dir))
)

*updated to exclude xrefs

Directory must have a DWG in it to select.
« Last Edit: December 28, 2006, 01:41:03 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

Bryco

  • Water Moccasin
  • Posts: 1864
Re: Exporting Blocks to DWG files?
« Reply #5 on: November 08, 2006, 02:21:32 PM »
If your company has mixed cad versions, remember wblock will save the block dwg in 2004 rather than the say acad 2000 that you have chosen in your options.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Exporting Blocks to DWG files?
« Reply #6 on: November 08, 2006, 06:20:29 PM »
Code: [Select]
;;                                                              ;;
;;              By: Andrea Andreetti                            ;;
;;                                                              ;;
(defun c:BLE (/ blocklist fextr)
(setq blocklist (ai_table "block" 8))
(setq fextr (acet-ui-pickdir "Select your folder for extraction:" "c:\\" "BLE BlockLIST Extractor"))
(if fextr (progn
      (foreach n blocklist
           (command "._-wblock" (strcat fextr "\\" n) n)
 ))
(alert "Please select a folder.")))
(c:BLE)
« Last Edit: November 08, 2006, 06:24:04 PM by Andrea »
Keep smile...

sinc

  • Guest
Re: Exporting Blocks to DWG files?
« Reply #7 on: November 08, 2006, 11:18:21 PM »
Is there a way to export blocks in a drawing to seperate DWG files named after the block? Sort of a backwards insert if you will.

I know I can manually do it, set scale to 1, explode, wblock then move insertion to 0,0.

But I'm hoping to do this for a bunch of blocks in one drawing. I tried dragging the blocks from design center to a folder, but that didn't work. Any ideas?

Are you trying to create a symbol library?

If so, are you familiar with Tool Palettes?  They can be used to insert blocks from one drawing into another very easily.  You can even specify things like Layer to use when inserting the blocks, so blocks always come in correctly regardless of the current user settings.

Easiest way is to just create a drawing that is empty except for your blocks.  Then browse to the drawing in Design Center and select "Create Tool Palette".  This creates a tool palette, with one Block Tool for each block in the drawing.  Extremely simple.

Having your symbol library in a Tool Palette works very well for some things, not-so-well for other things.  The feature would be MUCH more useful if you could group related Block Tools on the Tool Palette into Flyouts, but you can't.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Exporting Blocks to DWG files?
« Reply #8 on: November 09, 2006, 08:13:29 AM »
sinc,...

ToolPalettes do not allow user to enter variable LISP for scaling.
need to play always with INSUNITS...

Also, you need to export and import each time when making an update..
if you need to share the toolpalettes...this is very annoying.

I prefer making simple blocks......more flexibilities...
Keep smile...

Murph

  • Bull Frog
  • Posts: 402
  • P.I.T.A.
Re: Exporting Blocks to DWG files?
« Reply #9 on: November 09, 2006, 09:04:11 AM »
If you use Content Browser to hold and update all of your tools then drop them into the Tool Palettes, the updates are done automatically.

As to the INSUNITS issue, you can edit the atc files with Notepad to change that to any variable. I have not tried to do a LISP routine in there but, you can give it a whirl and see what happens.
Murphy's Law applies to all.
Whatever can go wrong, will, and at the most inopportune time.

Atook

  • Swamp Rat
  • Posts: 994
  • AKA Tim
Re: Exporting Blocks to DWG files?
« Reply #10 on: November 09, 2006, 10:42:30 AM »
Thanks gang! I ended up using RJP's solution after tweaking the code a bit (dropping things in the root of a drive has always been kapu for me).

As far as tool pallets go, I'm developing one, and I'm developing a block library at the same time. One weird issue I have is some blocks 'jig' coming in very large, then scaling down after I've chosen rotation. What causes this BTW?

Some good discussion here beyond the original question.

ronjonp

  • Needs a day job
  • Posts: 7437
Re: Exporting Blocks to DWG files?
« Reply #11 on: November 09, 2006, 10:57:45 AM »
Thanks gang! I ended up using RJP's solution after tweaking the code a bit (dropping things in the root of a drive has always been kapu for me).

As far as tool pallets go, I'm developing one, and I'm developing a block library at the same time. One weird issue I have is some blocks 'jig' coming in very large, then scaling down after I've chosen rotation. What causes this BTW?

Some good discussion here beyond the original question.

I updated the code above to allow selection of directory to place blocks....the only catch is there has to be something to pick in the directory  :-(

Tangent......how can you browse browse to an empty directory and output a path?

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Exporting Blocks to DWG files?
« Reply #12 on: November 09, 2006, 11:06:40 AM »
Thanks gang! I ended up using RJP's solution after tweaking the code a bit (dropping things in the root of a drive has always been kapu for me).

As far as tool pallets go, I'm developing one, and I'm developing a block library at the same time. One weird issue I have is some blocks 'jig' coming in very large, then scaling down after I've chosen rotation. What causes this BTW?

Some good discussion here beyond the original question.

take a look here

this is an old version....
the new one allow multi other options...
like multiple copy, redefinition, rescaling metric and Imperial conversion, Mview scaling transform, and many more..
(was tools of the week sept. 18 2005)

the new version is also compatible 2007.  ;)
« Last Edit: November 09, 2006, 11:08:21 AM by Andrea »
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Exporting Blocks to DWG files?
« Reply #13 on: November 09, 2006, 11:20:54 AM »
If you use Content Browser to hold and update all of your tools then drop them into the Tool Palettes, the updates are done automatically.

As to the INSUNITS issue, you can edit the atc files with Notepad to change that to any variable. I have not tried to do a LISP routine in there but, you can give it a whirl and see what happens.

1) I know how to update the toolpalettes...thanks
but this can't be done automaticly.

2) did you take a look of the act file ?..i think you mean xtp file....but even that.   :|

Keep smile...

T.Willey

  • Needs a day job
  • Posts: 5247
Re: Exporting Blocks to DWG files?
« Reply #14 on: November 09, 2006, 11:37:30 AM »
Tangent......how can you browse browse to an empty directory and output a path?
Here is one way
Code: [Select]
(defun Directory-Dia ( Message / sh folder folderobject result)
;; By Tony Tanzillo
;; Modified by Tim Willey

  (vl-load-com)
  (setq sh
     (vla-getInterfaceObject
        (vlax-get-acad-object)
        "Shell.Application"
     )
  )


  (setq folder
     (vlax-invoke-method
         sh
         'BrowseForFolder
         (vla-get-HWND (vlax-get-Acad-Object))
         Message
         0
      )
  )
  (vlax-release-object sh)


  (if folder
     (progn
        (setq folderobject
           (vlax-get-property folder 'Self)
        )
        (setq result
           (vlax-get-property FolderObject 'Path)
        )
        (vlax-release-object folder)
        (vlax-release-object FolderObject)
        (if (/= (substr result (strlen result)) "\\")
          (setq result (strcat result "\\"))
          result
        )
     )
  )
)
Called like
Code: [Select]
(setq DirPath (Directory-dia "Select directory to place new block definition."))
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.