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

How to check if entity is part of "Working Set"?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
614 Views, 5 Replies

How to check if entity is part of "Working Set"?

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

5 REPLIES 5
Message 2 of 6
ActivistInvestor
in reply to: Anonymous


@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.

Message 3 of 6
Anonymous
in reply to: ActivistInvestor

This does look like what I need, but having trouble trying to reference it. I am obviously missing something here....

2017-08-04_22-06-48.png

OR

 

2017-08-04_22-10-28.png

 

 

Message 4 of 6
ActivistInvestor
in reply to: Anonymous


@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();
      }
   }
}
Message 5 of 6
Anonymous
in reply to: ActivistInvestor

Thanks, that helped!

 

I was missing Application before LongTransactionManager

 

Dim oid As ObjectId = Autodesk.AutoCAD.ApplicationServices.Application.LongTransactionManager.CurrentLongTransactionFor(DocumentManager.MdiActiveDocument)

 

 

Message 6 of 6

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.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report