Author Topic: Persistent reactors  (Read 4271 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8775
  • AKA Daniel
Persistent reactors
« on: September 03, 2007, 07:44:35 AM »
What types of persistent reactors can be attached to an entity. I know Groups is one, but are there any others that might come up in this function?

Thanks

Code: [Select]
//Gets collection of Group.ObjectId(s) from an Entity.ObjectId
    internal static ObjectIdCollection GroupIdsFromEntity(ObjectId objectId)
    {
      ObjectIdCollection GroupCollection = new ObjectIdCollection();
      Database Db = AcDb.HostApplicationServices.WorkingDatabase;
      var Tm = Db.TransactionManager;

      using (Transaction Tr = Tm.StartTransaction())
      {

        foreach (var e in Tr.GetObject
          (objectId, OpenMode.ForRead).GetPersistentReactorIds())
        {
          GroupCollection.Add((ObjectId)Tr.GetObject
            ((ObjectId)e, OpenMode.ForRead).ObjectId);
        }

        Tr.Commit();
      }

      return GroupCollection;
    }

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Persistent reactors
« Reply #1 on: September 03, 2007, 09:16:50 AM »

I haven't tracked it through Daniel, but fields come to mind ...
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8775
  • AKA Daniel
Re: Persistent reactors
« Reply #2 on: September 03, 2007, 09:42:20 AM »
Thanks Kerry. I suppose I ought to test the type

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Persistent reactors
« Reply #3 on: September 03, 2007, 09:43:01 AM »

I'm not sure what you mean by 'type' ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8775
  • AKA Daniel
Re: Persistent reactors
« Reply #4 on: September 03, 2007, 11:38:07 AM »
I meant, testing each ObjectId returned by GetPersistentReactorIds() to see if it points to an object that is a typeof Group.
This code seems to work, and may also work for other persistent reactors as well.

Code: [Select]
    //Gets collection of Group.ObjectId(s) from an Entity.ObjectId
    internal static ObjectIdCollection GroupIdsFromEntity(ObjectId objectId)
    {
      var GroupCollection = new ObjectIdCollection();
      var Db = AcDb.HostApplicationServices.WorkingDatabase;
      var Tm = Db.TransactionManager;
      using (var Tr = Tm.StartTransaction())
      {
        var TmpCollection = Tr.GetObject
          (objectId, OpenMode.ForRead).GetPersistentReactorIds();
        foreach (var e in TmpCollection)
        {
          var Gr = (DBObject)Tr.GetObject((ObjectId)e, OpenMode.ForRead);
          if (Gr.GetType() == typeof(Group))//<--- Test the type.
            GroupCollection.Add(Gr.ObjectId);
        }
        Tr.Commit();
      }
      return GroupCollection;
    }


see all my pretty var vars??

LE

  • Guest
Re: Persistent reactors
« Reply #5 on: September 03, 2007, 12:49:15 PM »
var Gr = (DBObject)Tr.GetObject((ObjectId)e, OpenMode.ForRead);


Quote
The var keyword is NOT a completely new type, instead the compiler just takes a look at the right-hand side of the expression. If the right-hand side is an int, for example, the compiler will "replace" the var keyword with int.

Dan;

In your sample code, is still needed the cast of (DBObject) ?


That new keyword will make the typing easier and it is making closer to what we can do with (setq) in autolisp..... interesting --- here is a link to some comments about it - bad and good

http://www.codepost.org/view/126

Thanks!
« Last Edit: September 03, 2007, 01:06:40 PM by LE »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8775
  • AKA Daniel
Re: Persistent reactors
« Reply #6 on: September 03, 2007, 01:49:51 PM »
The var keyword is NOT a completely new type, instead the compiler just takes a look at the right-hand side of the expression. If the right-hand side is an int, for example, the compiler will "replace" the var keyword with int.

Right, you can still see the full type by hovering the mouse over the var keyword, You can also right click on var to go to definition... so
I don’t think the new keyword will make maintaining code any harder... but ... am still on the fence on whether it’s faster or not.
If you type the left side, intellisense will pick the right, with var it won’t. so either way you have to type one side.

So far this new C# seems pretty nice.




In your sample code, is still needed the cast of (DBObject) ?
You’re correct, I do not need the cast, I was doing the copy/paste stuff  :oops:


LE

  • Guest
Re: Persistent reactors
« Reply #7 on: September 03, 2007, 02:01:52 PM »
You’re correct, I do not need the cast, I was doing the copy/paste stuff

It was a curiosity.... thanks!


I will wait for the final release to start playing with the new net version....