Hi,
I am trying to determine if an entity is part of the "Working Set". In other words, belongs to a Block or Xref that is currently being edited in-place.
Does the API have ability to check this?
Thanks,
Jon
Solved! Go to Solution.
Solved by ActivistInvestor. Go to Solution.
@Anonymous wrote:Hi,
I am trying to determine if an entity is part of the "Working Set". In other words, belongs to a Block or Xref that is currently being edited in-place.
Does the API have ability to check this?
Thanks,
Jon
I think you're looking for the WorkSetHas() method of the LongTransaction class.
You get an instance of that class from the LongTransactionManager's CurrentLongTransactionFor() method.
This does look like what I need, but having trouble trying to reference it. I am obviously missing something here....
OR
@Anonymous wrote:This does look like what I need, but having trouble trying to reference it. I am obviously missing something here....
OR
Here's an extension method for the Document class, that tells if the entity with the given ObjectId is in the working set:
namespace Autodesk.AutoCAD.ApplicationServices { public static class MyDocumentExtensions { public static bool WorkSetHas(this Document doc, ObjectId id, bool includingErased = true) { ObjectId id = Application.LongTransactionManager.CurrentLongTransactionFor(doc); if(!id.IsNull) { using(var trans = new ReadOnlyTransaction()) { LongTransaction ltr = (LongTransaction) trans.GetObject(id, OpenMode.ForRead); return ltr.WorkSetHas(entityId, includingErased); } } return false; } } } namespace Autodesk.AutoCAD.DatabaseServices { public class ReadOnlyTransaction : OpenCloseTransaction { protected override void DeleteUnmanagedObject() { Commit(); base.DeleteUnmanagedObject(); } public override void Abort() { Commit(); } } }
Thanks, that helped!
I was missing Application before LongTransactionManager
Dim oid As ObjectId = Autodesk.AutoCAD.ApplicationServices.Application.LongTransactionManager.CurrentLongTransactionFor(DocumentManager.MdiActiveDocument)
Whoops.
I wrote that one quickly and without testing it.
In case anyone is interested, here is a working version:
namespace Autodesk.AutoCAD.ApplicationServices { public static class MyDocumentExtensions { public static bool WorkSetHas(this Document doc, ObjectId entityId, bool includingErased = true) { // Assert.IsNotNull(doc, "doc"); ObjectId id = Application.LongTransactionManager.CurrentLongTransactionFor(doc); if(!id.IsNull) { using(var trans = new ReadOnlyTransaction()) { LongTransaction ltr = (LongTransaction) trans.GetObject(id, OpenMode.ForRead); return ltr.WorkSetHas(entityId, includingErased); } } return false; } } } namespace Autodesk.AutoCAD.DatabaseServices { public class ReadOnlyTransaction : OpenCloseTransaction { protected override void DeleteUnmanagedObject() { Commit(); base.DeleteUnmanagedObject(); } public override void Abort() { Commit(); } } }
Can't find what you're looking for? Ask the community or share your knowledge.