.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1 REPLY 1
Reply
Message 1 of 2
Anonymous
582 Views, 1 Reply

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

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
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost