*Nermeen Bakr
Message 1 of 2 (346 Views)

Make a wblock using selection set with filter and save the wblock to another dwg

346 Views, 1 Replies
08-11-2005 05:27 AM
I don't know what i am doing wrong i am trying to make a wblock using
selection set with filter and i want to save this wblock to a dwg file as to
use it after that in the code.
Here is the code i wrote:
Public Function ssGetFilter(ByVal strPannelID As String, ByVal strWblockPath
As String, ByVal strPannelName As String)
Dim ed As Editor =
Dim values() As TypedValue = { _
New TypedValue(1001, strPannelName), _
New TypedValue(1001, strPannelID)} ', _

Dim sfilter As New SelectionFilter(values) ' Create the filter using our

Dim res As PromptSelectionResult = ed.SelectAll(sfilter)

If Not res.Status = PromptStatus.OK Then Return Nothing

Dim i As Integer
Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value
Dim idarray As ObjectId() = SS.GetObjectIds()
Dim objIdColl As New ObjectIdCollection
For i = 0 To idarray.Length - 1

Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim tempDb As New Autodesk.AutoCAD.DatabaseServices.Database(False, True)

db.Wblock(tempDb, objIdColl, New Point3d(0, 0, 0),

tempDb.SaveAs(strWblockPath, DwgVersion.Current)

Catch ex As Exception
End Try
End Function

Thanks in advance."

Nermeen Bakr
Project Manager
MCS (Modern Computing Services)
Website: http://www.mcsoil.com
Phone: +2 02 4036520 /+202 4051129
Fax: +2 02 4040503
New Member
Posts: 2
Registered: ‎03-14-2008
Message 2 of 2 (346 Views)

Re: Make a wblock using selection set with filter and save the wblock to another dwg

03-17-2008 12:39 AM in reply to: *Nermeen Bakr
Dear Mr.Nermeen Bakr,
In the first place I would thank you that with slight modification in your code I was able to solve my issue of generating wblock. The following code is working fine now :

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application

Imports DBTransMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager

#Region "Draw a wblock"
Public Sub AddNewBTRB()
'added new
Dim db As Database = New Database(), _
tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager, _
t As Transaction = tm.StartTransaction(), _
bt As BlockTable = tm.GetObject(db.BlockTableId, OpenMode.ForWrite), _
btr As BlockTableRecord = tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myDwg As Document
Dim myBT As BlockTable

myDwg = Application.DocumentManager.MdiActiveDocument
myTransMan = myDwg.TransactionManager
myTrans = myTransMan.StartTransaction

'Open the database for Write
myBT = myDwg.Database.BlockTableId.GetObject(OpenMode.ForWrite)

Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor

Dim opt As New EditorInput.PromptSelectionOptions
Dim optR As EditorInput.PromptSelectionResult

optR = ed.GetSelection(opt)

If optR.Value Is Nothing = False Then
Dim I As Long

Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = optR.Value
Dim idarray As ObjectId() = SS.GetObjectIds()
Dim objIdColl As New ObjectIdCollection

For I = 0 To idarray.Length - 1

Dim tempDb As Database = Application.DocumentManager.MdiActiveDocument.Database

tempDb.Wblock(db, objIdColl, New Point3d(0, 0, 0), DuplicateRecordCloning.Ignore)
db.SaveAs("c:\test1.dwg", DwgVersion.Current) 'added new

End If

'Dispose of the Transaction Objects
End Sub
#End Region

Hope the above will solve your issue.


Sandeep Banerjee, New Delhi, India
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.