WBLOCK an AcadBlock using VBA

WBLOCK an AcadBlock using VBA

Anonymous
Not applicable
4,065 Views
3 Replies
Message 1 of 4

WBLOCK an AcadBlock using VBA

Anonymous
Not applicable
Will AutoCAD's VBA allow one to WBLOCK an AcadBlock?
0 Likes
4,066 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
"CharlieGolfRomeo" wrote in message
news:[email protected]...

> Will AutoCAD's VBA allow one to WBLOCK an AcadBlock?

No, but you certainly might be able to kludge it
using SendCommand(), or with AxDbDocument and the
CopyObjects() method.

Or, you might want to have a look at AcadX.arx, which
can be found at www.caddzone.com/acadx/acadx.htm.

The Utility class in AcadX has a WBlock() method that can
wblock a selection set, the entire drawing, or any AutoCAD
block to .dwg or .dxf format, in any file version supported
by the SAVEAS command.

AcadXUtility.WBlock( FileName As String,
[Document As AcadDocument],
[Objects As Variant],
[SaveAsType As Short],
[Precison As Short] )

FileName is the name of the output file (a .DWG or DXF
extension is required).

Document is the AutoCAD document object containing
the objects to be saved. If not specified the active
document is used.

Objects can be an AcadBlock; array of AcadEntity; or
an AcadSelectionSet specifying the objects to be saved.
If not supplied, the entire drawing is wblocked.

SaveAsType specifies the type of file and version,
can be any of the following:

acR12_dxf
acR13_dwg
acR13_dxf
acR14_dwg
acR14_dxf
acR15_dwg
acR15_dxf

(Default = acR15_DWG)

Precision is optional and is used only for DXF
output. It specifies the type and precision of
the DXF output. If this value is not supplied,
or is -1, the output is in binary DXF format.
0 Likes
Message 3 of 4

Anonymous
Not applicable
Here is one answer.

--

Public Sub SaveBlockToDisk(BlockName As String,
FilePath As String)
Dim Block As AcadBlock
Dim BlockRef As
AcadBlockReference
Dim Sset As AcadSelectionSet
Dim Point(0 To 2) As
Double

 

  For Each Block In
ThisDrawing.Blocks
    If Block.Name = BlockName
Then
      'create insertion
point
      Point(0) = 0: Point(1) = 0: Point(2) =
0
      'insert the
block
      Set BlockRef =
ThisDrawing.ModelSpace.InsertBlock(Point, BlockName, 1#, 1#, 1#,
0#)
      'refresh
application
     
Application.Update
      'create a selection set
object
      Set Sset =
ThisDrawing.SelectionSets.Add("Temp")
      'add the
block to the selection set
      Sset.Select
acSelectionSetLast
      'write the block to
file
      ThisDrawing.Wblock FilePath &
BlockName & ".dwg", Sset
      'delete the
temporary block reference
     
BlockRef.Delete
      'delete the selection
set
     
Sset.Delete
      'refresh
application
     
Application.Update
    End If
  Next Block
End
Sub

 

Public Sub Test()
  SaveBlockToDisk
"Block1", "C:\"
End Sub

--
Joe Sutphin
Visual Basic How-To For
AutoCAD
for more book details click on the link

href="http://eomnisource.hypermart.net">http://eomnisource.hypermart.net

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Will
AutoCAD's VBA allow one to WBLOCK an AcadBlock?
0 Likes
Message 4 of 4

GallowayUS_com_RonAllen1
Collaborator
Collaborator

Thanks Joe- Useful as ever! : )

Ron Allen
Galloway BIM
0 Likes