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

Delete an entity

3 REPLIES 3
Reply
Message 1 of 4
gilseorin
3493 Views, 3 Replies

Delete an entity

I just commited a deletion an entity belonged to selection set.
Any help, I would appreciate it.

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Interop.Common
Public Class GILSclass
_
Public Sub NFU()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = HostApplicationServices.WorkingDatabase()
Try
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim vls1() As TypedValue = {New TypedValue(8, "LEVEL")}
Dim sftr1 As New SelectionFilter(vls1)
Dim rs1 As PromptSelectionResult = ed.SelectAll(sftr1)
Dim i As Integer
Dim SS1 As Autodesk.AutoCAD.EditorInput.SelectionSet = rs1.Value
Dim idary1 As ObjectId() = SS1.GetObjectIds()
For i = 0 To idary1.Length - 1
Dim ent1 As DBText = trans.GetObject(idary1(i), OpenMode.ForRead, False)
ent1.Erase()
Next
End Using
Catch ex As Exception
Finally
End Try
End Sub
End Class
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: gilseorin

try to open the database "forwrite".
Ciao
GPaolo



ha scritto nel messaggio news:5400144@discussion.autodesk.com...
I just commited a deletion an entity belonged to selection set.
Any help, I would appreciate it.

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Interop.Common
Public Class GILSclass
_
Public Sub NFU()
Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = HostApplicationServices.WorkingDatabase()
Try
Using trans As Transaction =
db.TransactionManager.StartTransaction()
Dim vls1() As TypedValue = {New TypedValue(8, "LEVEL")}
Dim sftr1 As New SelectionFilter(vls1)
Dim rs1 As PromptSelectionResult = ed.SelectAll(sftr1)
Dim i As Integer
Dim SS1 As Autodesk.AutoCAD.EditorInput.SelectionSet =
rs1.Value
Dim idary1 As ObjectId() = SS1.GetObjectIds()
For i = 0 To idary1.Length - 1
Dim ent1 As DBText = trans.GetObject(idary1(i),
OpenMode.ForRead, False)
ent1.Erase()
Next
End Using
Catch ex As Exception
Finally
End Try
End Sub
End Class
Message 3 of 4
Anonymous
in reply to: gilseorin

Imports AcDb = Autodesk.AutoCAD.DatabaseServices

Friend Sub EraseEntities(ByVal entitiy As AcDb.Entity)
Using db As AcDb.Database =
AcDb.HostApplicationServices.WorkingDatabase()
Using tr As AcDb.Transaction =
db.TransactionManager.StartTransaction
Dim ent As AcDb.Entity = tr.GetObject(entitiy.ObjectId,
AcDb.OpenMode.ForWrite, False, True)
ent.Erase()
ent.Dispose()
tr.Commit()
End Using
End Using
End Sub

Friend Sub EraseEntities(ByVal entities() As AcDb.Entity)
Using db As AcDb.Database =
AcDb.HostApplicationServices.WorkingDatabase()
Using tr As AcDb.Transaction =
db.TransactionManager.StartTransaction
For Each e As AcDb.Entity In entities
Dim ent As AcDb.Entity = tr.GetObject(e.ObjectId,
AcDb.OpenMode.ForWrite, False, True)
ent.Erase()
ent.Dispose()
Next
tr.Commit()
End Using
End Using
End Sub

Friend Sub EraseEntities(ByVal entitiy As AcDb.ObjectId)
Using db As AcDb.Database =
AcDb.HostApplicationServices.WorkingDatabase()
Using tr As AcDb.Transaction =
db.TransactionManager.StartTransaction
Dim ent As AcDb.Entity = tr.GetObject(entitiy,
AcDb.OpenMode.ForWrite, False, True)
ent.Erase()
ent.Dispose()
tr.Commit()
End Using
End Using
End Sub

Friend Sub EraseEntities(ByVal entities() As AcDb.ObjectId)
Using db As AcDb.Database =
AcDb.HostApplicationServices.WorkingDatabase()
Using tr As AcDb.Transaction =
db.TransactionManager.StartTransaction
For Each id As AcDb.ObjectId In entities
Dim ent As AcDb.Entity = tr.GetObject(id,
AcDb.OpenMode.ForWrite, False, True)
ent.Erase()
ent.Dispose()
Next
tr.Commit()
End Using
End Using
End Sub

tp










escreveu na mensagem news:5400144@discussion.autodesk.com...
I just commited a deletion an entity belonged to selection set.
Any help, I would appreciate it.

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Interop.Common
Public Class GILSclass
_
Public Sub NFU()
Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = HostApplicationServices.WorkingDatabase()
Try
Using trans As Transaction =
db.TransactionManager.StartTransaction()
Dim vls1() As TypedValue = {New TypedValue(8, "LEVEL")}
Dim sftr1 As New SelectionFilter(vls1)
Dim rs1 As PromptSelectionResult = ed.SelectAll(sftr1)
Dim i As Integer
Dim SS1 As Autodesk.AutoCAD.EditorInput.SelectionSet =
rs1.Value
Dim idary1 As ObjectId() = SS1.GetObjectIds()
For i = 0 To idary1.Length - 1
Dim ent1 As DBText = trans.GetObject(idary1(i),
OpenMode.ForRead, False)
ent1.Erase()
Next
End Using
Catch ex As Exception
Finally
End Try
End Sub
End Class



I'm protected by SpamBrave
http://www.spambrave.com/
Message 4 of 4
gilseorin
in reply to: gilseorin

Thank you for your code, It helped.

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