AutoCAD Map 3D Developer
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Delete Polyline for Selected Objects
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi
I have a requirement which says, I have to open a dwg file, where I have to select some few polylines and then the selected polylines should be deleted.
I am able to select objects in the dwg file, but not able to delete it.
I am using AutoCAD Map 3D 2012 and VB.NET.
Here I am pasting part of the code that I am having as of now.
Dim acDocMgr As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.D
Dim acDoc As Document = acDocMgr.MdiActiveDocument
'Get the selected objects in the drawing area
Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
MsgBox(acSSPrompt.Status)
'If the prompt Status is OK, the objects are selected
If acSSPrompt.Status = PromptStatus.OK Then
MsgBox("OK")
'Selection Set for the selected objects
Dim acSSet As SelectionSet = acSSPrompt.Value
For Each acSSObj As SelectedObject In acSSet
Dim myMap As New Autodesk.AutoCAD.DatabaseServices.IdMapping
Dim myObjs As New Autodesk.AutoCAD.DatabaseServices.ObjectIdCollecti
If Not IsDBNull(acSSObj) Then
'Open the selected object for READ
Using trans As Transaction = acDoc.Database.TransactionManager.StartTransaction
Using lock As DocumentLock = acDoc.LockDocument
Dim acEnt As Entity = DirectCast(trans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite), Entity)
acEnt.UpgradeOpen()
acEnt.Erase()
End Using
End Using
End If
Next
Re: Delete Polyline for Selected Objects
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
why do you add your new question to an existing thread? For new questions please create new threads.
And to your code: you haven't commited the transaction ![]()
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Delete Polyline for Selected Objects
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Sorry for maintaining the same thread
I will open a new one
And I have committed the transaction, here I put just a part of the code.
Delete Polyline for Selected Objects in the dwg
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi
I have a requirement which says, I have to open a dwg file, where I have to select some few polylines and then the selected polylines should be deleted.
I am able to select objects in the dwg file, but not able to delete it.
I am using AutoCAD Map 3D 2012 and VB.NET.
Here I am pasting part of the code that I am having as of now.
Dim acDocMgr As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.D
Dim acDoc As Document = acDocMgr.MdiActiveDocument
'Get the selected objects in the drawing area
Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
MsgBox(acSSPrompt.Status)
'If the prompt Status is OK, the objects are selected
If acSSPrompt.Status = PromptStatus.OK Then
MsgBox("OK")
'Selection Set for the selected objects
Dim acSSet As SelectionSet = acSSPrompt.Value
For Each acSSObj As SelectedObject In acSSet
Dim myMap As New Autodesk.AutoCAD.DatabaseServices.IdMapping
Dim myObjs As New Autodesk.AutoCAD.DatabaseServices.ObjectIdCollecti
If Not IsDBNull(acSSObj) Then
'Open the selected object for READ
Using trans As Transaction = acDoc.Database.TransactionManager.StartTransaction
Using lock As DocumentLock = acDoc.LockDocument
Dim acEnt As Entity = DirectCast(trans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite), Entity)
acEnt.UpgradeOpen()
acEnt.Erase()
End Using
End Using
trans.Commit()
End If
Next
Re: Delete Polyline for Selected Objects
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
>> And I have committed the transaction, here I put just a part of the code.
No, with End Using you disposed this transaction, and after acEnt.Erase and before End Using I see not trans.Commit
It does not depend then on any lines after that snippet you showed here.
One more tip: if you opened an object with .ForWrite you don't need the .UpgradeOpen.
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Delete Polyline for Selected Objects in the dwg
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
now you are commiting the transaction when it is already disposed ... sorry, but when you run this code you should get exceptions (hope you watch them in VS).
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Delete Polyline for Selected Objects
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I am confused whether I should commit the transaction or not, as I have already disposed the entity.
Edited by
Discussion_Admin
I also merged the two topics into one
Re: Delete Polyline for Selected Objects
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
>> I am confused whether I should commit the transaction or not, as I have already disposed the entity.
You have first to commit the transaction and then dispose it.
Using trans As Transaction = acDoc.Database.TransactionManager.StartTransaction
'...do your work, modify your object
trans.Commit() 'now save the modifications to the database
End Using 'this disposes the transaction / free up it's ressources
HTH, - alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Re: Delete Polyline for Selected Objects
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I modified the code for transaction.
I tried to use Light Weight Polyline for deleting the polylines fromt the dwg file.
I have kept that code in bold letter below.
But it gives an error that there is no object as AcadLWPolyline for AutoCAD Map 3D 2012.
I am not not able to proceed on how to delete the polyline.
Please help me out.
Dim acDocMgr As DocumentCollection =Autodesk.AutoCAD.ApplicationServices.Application.
Dim acDoc As Document = acDocMgr.MdiActiveDocument
'Get the selected objects in the drawing area
Dim acSSPrompt As PromptSelectionResult = acDoc.Editor.GetSelection()
'If the prompt Status is OK, the objects are selected
If acSSPrompt.Status = PromptStatus.OK Then
'Selection Set for the selected objects
Dim acSSet As SelectionSet = acSSPrompt.Value
'Step through the objects in the Selection Set
For Each acSSObj As SelectedObject In acSSet
Dim myMap As New Autodesk.AutoCAD.DatabaseServices.IdMapping
Dim myObjs As New Autodesk.AutoCAD.DatabaseServices.ObjectIdCollecti
'Check to make sure a valid object was returned
If Not IsDBNull(acSSObj) Then
'Open the selected object for READ
Using trans As Transaction = acDoc.Database.TransactionManager.StartTransaction
Using lock As DocumentLock = acDoc.LockDocument
'Dim acEnt As Entity = DirectCast(trans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite), Entity)
Dim entities As New ObjectIdCollection(acSSPrompt.Value.GetObjectIds()
For Each oid As ObjectId In entities
If oid.ObjectClass.Name.Equals("AcDbPolyline") Then
Dim pl As Polyline = TryCast(trans.GetObject(oid, OpenMode.ForWrite), Polyline)
Dim acadPl As AcadLWPolyline = TryCast(pl.AcadObject, AcadLWPolyline)
acadPl.Erase()
End If
Next
trans.Commit() --- Here I commited the transaction & later it was disposed
End Using
End Using
End If
Next
Re: Delete Polyline for Selected Objects
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
you can't cast a Polyline to a AcadLwPolyline, that's the same as trying to cast a Circle to a Line, they are totally different objects.
If you only want to delete specific objects then use the filter-methods during the selection of objects or at least verify the objecttype of the object to delete.
- alfred -
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------



