.NET

.NET

Reply
*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
Hi:
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)
Try
Dim ed As Editor =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim values() As TypedValue = { _
New TypedValue(1001, strPannelName), _
New TypedValue(1001, strPannelID)} ', _


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


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
objIdColl.Add(idarray(i))
Next

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),
DuplicateRecordCloning.Ignore)


tempDb.SaveAs(strWblockPath, DwgVersion.Current)

tempDb.Dispose()
db.Dispose()
Catch ex As Exception
MsgBox(ex.Message)
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
sandeep2203
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
'custom
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
objIdColl.Add(idarray(I))
Next

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

myTrans.Commit()
End If

'Dispose of the Transaction Objects
myTrans.Dispose()
myTransMan.Dispose()
End Sub
#End Region

Hope the above will solve your issue.

Regards,

Sandeep Banerjee, New Delhi, India
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
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.