.NET

Reply
Active Member
everts
Posts: 7
Registered: ‎08-30-2007
Message 1 of 4 (445 Views)

Problems to delete layer entities

445 Views, 3 Replies
03-22-2009 10:12 AM
hello everyone, I made an app in C# to draw boring (soil exploration) graphics, well, it was made to Land 06, but now, we want to use it in Civil 3d 09, but I encountered several compatibility problems in the code. That is, the code used for deleting entities on determinated layer does not work now, but thats not the only code that is not working, also the code for delete layer, code for hiding the layer, code for showing the layer and so on. So, I was wondering if you guys can help me with this problem.

Here is the code used for deleting entities (works fine in Land06):

public void DeleteLayerEntities(string layer)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
TypedValue[] tV = new TypedValue[1];
tV[0] = new TypedValue((int)DxfCode.LayerName, layer);
SelectionFilter selectionFilter = new SelectionFilter(tV);
PromptSelectionResult promptSelectionResult
= ed.SelectAll(selectionFilter);

try
{
DocumentLock mLock = Application.DocumentManager.MdiActiveDocument.LockDocument();
foreach (ObjectId id in promptSelectionResult.Value.GetObjectIds())
{
Entity entity = (Entity)tr.GetObject(id, OpenMode.ForWrite);
entity.UpgradeOpen();
entity.Erase();
entity.Dispose();
}
UpdateScreen();
mLock.Dispose();
tr.Commit();
}
catch (System.NullReferenceException) { ;}
}
*Tony Tanzillo
Message 2 of 4 (445 Views)

Re: Problems to delete layer entities

03-22-2009 05:10 PM in reply to: everts
For future reference, many here that use newsreaders
cannot easily look at code posted via the web, with or
without the code tags.

My advice is if you want the most possible responses,
that you attach your code in a .txt file.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


wrote in message news:6146620@discussion.autodesk.com...
hello everyone, I made an app in C# to draw boring (soil exploration)
graphics, well, it was made to Land 06, but now, we want to use it in Civil
3d 09, but I encountered several compatibility problems in the code. That
is, the code used for deleting entities on determinated layer does not work
now, but thats not the only code that is not working, also the code for
delete layer, code for hiding the layer, code for showing the layer and so
on. So, I was wondering if you guys can help me with this problem. Here is
the code used for deleting entities (works fine in Land06): public void
DeleteLayerEntities(string layer) { Document doc =
Application.DocumentManager.MdiActiveDocument; Database db = doc.Database;
Editor ed = doc.Editor; Transaction tr =
db.TransactionManager.StartTransaction(); TypedValue[] tV = new
TypedValue[1]; tV[0] = new TypedValue((int)DxfCode.LayerName, layer);
SelectionFilter selectionFilter = new SelectionFilter(tV);
PromptSelectionResult promptSelectionResult = ed.SelectAll(selectionFilter);
try { DocumentLock mLock =
Application.DocumentManager.MdiActiveDocument.LockDocument(); foreach
(ObjectId id in promptSelectionResult.Value.GetObjectIds()) { Entity entity
= (Entity)tr.GetObject(id, OpenMode.ForWrite); entity.UpgradeOpen();
entity.Erase(); entity.Dispose(); } UpdateScreen(); mLock.Dispose();
tr.Commit(); } catch (System.NullReferenceException) { ;} }
Active Member
everts
Posts: 7
Registered: ‎08-30-2007
Message 3 of 4 (445 Views)

Re: Problems to delete layer entities

03-23-2009 07:08 AM in reply to: everts
ok mr.Tanzillo , my appologies. It just i did not know how to format the code here. Here is the text file containing the code. Thanks. By the way, I am using a hyperlink because I dont know how to attach files :-(
[Code for deleting entities|http://everts.comuv.com/public/code.zip]
Active Member
everts
Posts: 7
Registered: ‎08-30-2007
Message 4 of 4 (445 Views)

Re: Problems to delete layer entities

03-23-2009 02:55 PM in reply to: everts
I was able to solve the problem by adapting the code from Kean Walmsley at the following link [http://through-the-interface.typepad.com/through_the_interface/2007/08/moving-entities.html|http://through-the-interface.typepad.com/through_the_interface/2007/08/moving-entities.html]

Thanks everybody
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.