TheSwamp

CAD Forums => CAD General => Topic started by: Atook on November 08, 2006, 11:49:07 AM

Title: Exporting Blocks to DWG files?
Post by: Atook 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?
Title: Re: Exporting Blocks to DWG files?
Post by: Arizona 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?
Title: Re: Exporting Blocks to DWG files?
Post by: ronjonp on November 08, 2006, 12:06:20 PM
Perhaps.....http://www.theswamp.org/index.php?topic=9229.0
Title: Re: Exporting Blocks to DWG files?
Post by: Atook 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!
Title: Re: Exporting Blocks to DWG files?
Post by: ronjonp 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.
Title: Re: Exporting Blocks to DWG files?
Post by: Bryco 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.
Title: Re: Exporting Blocks to DWG files?
Post by: Andrea 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)
Title: Re: Exporting Blocks to DWG files?
Post by: sinc 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.
Title: Re: Exporting Blocks to DWG files?
Post by: Andrea 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...
Title: Re: Exporting Blocks to DWG files?
Post by: Murphy 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.
Title: Re: Exporting Blocks to DWG files?
Post by: Atook 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.
Title: Re: Exporting Blocks to DWG files?
Post by: ronjonp 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?
Title: Re: Exporting Blocks to DWG files?
Post by: Andrea 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 (http://www.caddepot.com/cgi-bin/cfiles/cfiles.cgi?0,0,0,0,7,2323)

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.  ;)
Title: Re: Exporting Blocks to DWG files?
Post by: Andrea 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.   :|

Title: Re: Exporting Blocks to DWG files?
Post by: T.Willey 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."))
Title: Re: Exporting Blocks to DWG files?
Post by: ronjonp on November 09, 2006, 11:58:29 AM
Thanks Tim :)

You'd think there would be a built in function like getdirectoryd or sumtin.  :-D
Title: Re: Exporting Blocks to DWG files?
Post by: T.Willey on November 09, 2006, 12:01:35 PM
Thanks Tim :)

You'd think there would be a built in function like getdirectoryd or sumtin.  :-D
You're welcome Ron.  I think ET has one you can use, but I like to use code I know.