Author Topic: do I use ownerID to step through nesting levels?  (Read 9856 times)

0 Members and 1 Guest are viewing this topic.

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
do I use ownerID to step through nesting levels?
« on: February 02, 2007, 01:18:32 AM »
If I use GetNestedEntity to get an object, do I use the OwnerID property to get the level above the entity.
The level above would be a block (speaking in common terms, not .net object types...).
It might be a block, an xref, or the madelspace or paperspace block.
I tried the ownerID property to get the entity, but I think I am assuming too much.
The following fuction catches when I feed it the ownerID of an entity:

 Public Function getEntNet(ByVal objID As AcDb.ObjectId) As AcDb.Entity
        Dim db As Database = AcDb.HostApplicationServices.WorkingDatabase()
        Dim tm As AcDb.TransactionManager = db.TransactionManager
        Dim myT As AcDb.Transaction = tm.StartTransaction()
        Dim ent As AcDb.Entity = Nothing
        If Not objID.IsNull Then
            Try
                ent = CType(tm.GetObject(objID, OpenMode.ForRead, True), AcDb.Entity)
                myT.Commit()
            Catch ex As Exception
                ent = Nothing
            Finally
                myT.Dispose()
            End Try
        End If
        Return ent
    End Function

Do I need to be more specific in my casting?
I typically have no problem finding them lunkers in Lake Sabrina, obviosly my fishing is better than my netting - and my analogies are better than my programming, I'm on a roll....
James Maeding

Glenn R

  • Guest
Re: do I use ownerID to step through nesting levels?
« Reply #1 on: February 02, 2007, 01:26:52 AM »
Let's say you select a line in plain open ModelSpace...what do you expect it's owner to be?
« Last Edit: February 02, 2007, 06:37:25 AM by Glenn R »

Glenn R

  • Guest
Re: do I use ownerID to step through nesting levels?
« Reply #2 on: February 02, 2007, 01:39:06 AM »
I'll give you a hint...an AcDbEntity is graphical, but.................

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: do I use ownerID to step through nesting levels?
« Reply #3 on: February 02, 2007, 01:54:25 AM »
Ohhh time for a class ..


[Settles down with popcorn]

« Last Edit: February 02, 2007, 05:51:34 AM by Kerry Brown »
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.

Glenn R

  • Guest
Re: do I use ownerID to step through nesting levels?
« Reply #4 on: February 02, 2007, 03:22:44 AM »
And another...ALL GRAPHICAL entities WILL have the same TYPE of owner...........

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: do I use ownerID to step through nesting levels?
« Reply #5 on: February 02, 2007, 04:15:02 AM »
We should leave this one for James , yes ?

James, do you have a copy of DBVIEW, which Glenn recently reminded me about.
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.

Glenn R

  • Guest
Re: do I use ownerID to step through nesting levels?
« Reply #6 on: February 02, 2007, 04:26:22 AM »
Yes we should and anybody else who wants to anty up and post a reply.

DBVIEW is excellent, but a trip to the ARX docs will sort this one out as well Kerry.

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: do I use ownerID to step through nesting levels?
« Reply #7 on: February 02, 2007, 04:48:45 PM »
I think you guys are wondering why I would ask for an objects owner, when something "plain" in modelspace is so simple.
I am doing a tool to list properties of an object, then allow you to step up or down in an objects nesting level and see those properties.
In the case of a plain line, it is essentially not nested.
My prog would not let you step up to a higher nesting level, as there is none in that case.
What about an object in a block though?
If I grab a line using the GetNestedEntity method, how do I get the entity object for the block insert it came from?
I need to get the object so I can list its layer properties.
In lisp, the nentsel returned a "trail" of data allowing you to step back via the entity name.
If you did this with VBA, I think you used the parent property or something.
I'm wondering how to do this in .net.

Also keep in mind, I'm not just interested in listing the entity's info, my prog lets you change the layer properties of any of the levels.
I swear, I tried looking at the ARX docs, I read all I could and it seemed like the ownerID was the right thing to look at.
I thought it would be an easy topic to figure out, but its not been so far...
thanks for the replies.
James Maeding

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: do I use ownerID to step through nesting levels?
« Reply #8 on: February 02, 2007, 04:52:46 PM »
Wait, I think I see the hint.  I will try casting it to a block table record and see what happens.
I'm only half as dense as I look, so there is an upper limit :)
James Maeding

Glenn R

  • Guest
Re: do I use ownerID to step through nesting levels?
« Reply #9 on: February 02, 2007, 05:53:01 PM »
:) Any luck?

Glenn R

  • Guest
Re: do I use ownerID to step through nesting levels?
« Reply #10 on: February 02, 2007, 06:04:18 PM »
A AcDbBlockTableRecord will be the TYPE of OWNER of all things graphical.

Now for a little lesson in CLASSICAL INHERITANCE. I'm sure you're familiar with inheritance, so I won't go into the nitty gritty, however, when designing class heirarchies, it's often useful to SAY your inheritance out loud to see if it makes sense.

For example, let's say we have 3 classes - 1 base class, called CAR, and 2 derived classes called SPORTSCAR and FAMILYCAR. SportsCar and FamilyCar both derive/inherit from Car. In classical inheritance, you can now say,  a SportsCar is a type of Car, also, a FamilyCar is a type of Car. However, you could not say a Car is a SportsCar nor is a Car a FamilyCar...it doesn't make sense. Does that make sense?

Right, back to our little problem. I said above an AcDbEntity is graphical, but......an AcDbObject is not! Now seeing as everything graphical must have an owner of type AcDbBlockTableRecord, which in turn derives from AcDbSymbolTableRecord, which in turns derives from............AcDbObject!!!

Now, is an AcDbBlockTableRecord a graphical entity? No it certainly isn't. So, in your function, you could specify the return type as AcDbBlockTableRecord or, more generically, as AcDbObject and cast appropriately.

Apologies for the hasty reply, but I've just gotten up, am hungry and going for breakfast.

Cheers,
Glenn.

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: do I use ownerID to step through nesting levels?
« Reply #11 on: February 03, 2007, 12:56:47 AM »
wow, thanks for the tip.  I am soaking in this inheritance and casting stuff.  It makes perfect sense, it just takes me a while to get used to.  I'll report back.
James Maeding

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: do I use ownerID to step through nesting levels?
« Reply #12 on: February 03, 2007, 01:52:18 AM »
wait, what about a block insert, isn't that graphical?
So if I picked a line, within a block insert, within an xref, I would expect the ownerID of the line to be the ID of an insert.
But that did not work, of course.  So I'm not sure how to get the insert entity from the line properties still.
thx
James Maeding

Glenn R

  • Guest
Re: do I use ownerID to step through nesting levels?
« Reply #13 on: February 03, 2007, 02:10:05 AM »
wait, what about a block insert, isn't that graphical?

Correct.

So if I picked a line, within a block insert, within an xref, I would expect the ownerID of the line to be the ID of an insert.

Incorrect :)

The owner of the line in the Block insert is the AcDbBlockTableRecord representing the insert that contains the line.
The owner of the block insert is the AcDbBlockTableRecord representing the xref.
The owner of the inserted xref, in this case, would be the AcDbBlockTableRecord representing modelspace.
Finally, the owner of modelspace is the block table itself.

Confused yet? ;)

Glenn R

  • Guest
Re: do I use ownerID to step through nesting levels?
« Reply #14 on: February 03, 2007, 02:21:20 AM »
If you're using GetNestedEntity, in it's PromptNestedEntityResult you can get the ACTUAL graphical containers using GetContainers, of the entity thusly picked.