Oga87 Posted September 23 Share Posted September 23 (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 September 23 by Oga87 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.