Jump to content

Recommended Posts

Posted (edited)

Hello Dear AutoCAD programmers!

Please tell me how to export a block from a drawing using the code (excel-vba) using the command WBLOCK -> Block (existing block)? !Data source - "Block"

 

The code below allows you to export only the selected, but I need to export an existing block by selecting it by name.

 

Dim myBlock As AcadBlockReference
Dim oEnt As AcadEntity
Dim sourceObj As Object
Dim Sset As AcadSelectionSet

StartF = "C:\"
Set App = CreateObject("Excel.Application")
With App.FileDialog(3)
  .AllowMultiSelect = False
  .Title = "Select File with Block"
  .Filters.Clear
  .Filters.Add "Drawing Files", "*.dwg;*.dwt", 1
  .InitialFileName = StartF
  .InitialView = 2

  If .Show = 0 Then
    MsgBox "Not selected."
  Else
    For lf = 1 To .SelectedItems.Count
      Set awCopy = acadApp.Documents.Open(.SelectedItems(lf))

      For Each oEnt In awCopy.ModelSpace
      If TypeOf oEnt Is AcadBlockReference Then
        Set myBlock = oEnt
        If UCase(myBlock.EffectiveName) = UCase(blockname1) Then
            Set sourceObj = myBlock
            Exit For
        End If
      End If
     Next oEnt

    If VarType(sourceObj) <> vbEmpty Then
     Set Sset = awCopy.SelectionSets.Add("WBLOCKSET")
     Sset.AddItems sourceObj
     awCopy.Wblock "C:\Acad_user\temp\WBlock_example.dwg", Sset
     Sset.DELETE

    End If

    Next
  End If
End With

 

Perhaps the following line needs to be changed somehow:   

awCopy.Wblock "C:\Acad_user\temp\WBlock_example.dwg", Sset

 

Edited by Oga87

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...