Author Topic: RootNamespace  (Read 23127 times)

0 Members and 1 Guest are viewing this topic.

sinc

  • Guest
Re: RootNamespace
« Reply #30 on: December 28, 2007, 10:20:11 AM »
joke.AddRimShot()

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: RootNamespace
« Reply #31 on: December 28, 2007, 10:27:23 AM »
I find it strange the points and line are created inside the transaction. ….but maybe I’m just that way..

One more thing, I haven’t seen the book, so I don’t know the context of how this sample was presented,
but one thing I would certainly try to hammer home from the start is the need for handling exceptions.
« Last Edit: December 28, 2007, 11:04:27 AM by Daniel »

sinc

  • Guest
Re: RootNamespace
« Reply #32 on: December 28, 2007, 12:43:05 PM »
Speaking of exception handling, it would also be nice if the Autodesk developer documentation included the possible exceptions that various methods can throw...  The core .NET documentation from Microsoft typically includes this information, but the Autodesk stuff leaves something to be desired.

Glenn R

  • Guest
Re: RootNamespace
« Reply #33 on: December 28, 2007, 03:15:30 PM »
Kerry,

Before I go on a rant, can you confirm something for me please? Is the VB code you posted, a direct copy, of what's written in Mr. Winters book?

Cheers,
Glenn.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: RootNamespace
« Reply #34 on: December 28, 2007, 05:27:13 PM »

yes Glenn, cut and paste unfortunately.

There are [lots] of examples in a similar vein. By the time osmosis takes effect (firsthand and inherited) this will/may become the acccepted standard for VB code.

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: RootNamespace
« Reply #35 on: December 28, 2007, 05:39:32 PM »
Kerry,

Excellent - thanks for the confirmation...the rant will now continue :)

Do you see, what is, dare I say it, catastrophically wrong, with the code demonstrated by Mr. Winters and why nobody should follow this as a 'good' example?

Cheers,
Glenn.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: RootNamespace
« Reply #36 on: December 28, 2007, 07:37:42 PM »
Kerry,

Excellent - thanks for the confirmation...the rant will now continue :)

Do you see, what is, dare I say it, catastrophically wrong, with the code demonstrated by Mr. Winters and why nobody should follow this as a 'good' example?

Cheers,
Glenn.

Glenn,
I must admit that VB code makes my eyes glaze over and I didn't really look at the example code from a technical viewpoint until you raised the flag.

I'm usually reticent about knocking peoples efforts but I think in this case it must be done .. particularly as the sample posted is purported as being a template for drawing anything in ModelSpace.

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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: RootNamespace
« Reply #37 on: December 28, 2007, 07:55:30 PM »
Speaking of exception handling, it would also be nice if the Autodesk developer documentation included the possible exceptions that various methods can throw...  The core .NET documentation from Microsoft typically includes this information, but the Autodesk stuff leaves something to be desired.

Richard,
The only way this will happen is if enough people contact Kean Walmsley and Stephen Preston at AutoDesk with a compelling argument.
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: RootNamespace
« Reply #38 on: December 28, 2007, 09:13:35 PM »
A couple of things ...
aside from the lack of a using keyword  for the transaction which wraps an object implementing IDisposable for automatic disposal.  ..

The sample code does not use the transaction’s GetObject member to determine the BlockTable or BlockTableRecord,
it uses the myDWG.Database.BlockTableId.GetObject( .. and  (DatabaseServices.BlockTableRecord.ModelSpace).GetObject( ...

This is (by my understanding) contrary to the ARX documentation and does not follow the guidelines established in the AutoCAD Managed Training Labs ; particularly Lab 3 – Database Fundamentals: Creating our Employee Object ...
where all object references are obtained through the transaction, not via a direct open/close paradigm.
added:
essentially, this sample is mixing methods for obtaining the references ... and my understanding is that if you do that "bad stuff can happen"

I'm sure that this could be explained better by someone coming from an ARX background.

I'd be happy to be shown incorrect, because I am imagining all the VB code currently being copied using this sample template.

« Last Edit: December 28, 2007, 09:41:29 PM 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.

sinc

  • Guest
Re: RootNamespace
« Reply #39 on: December 29, 2007, 12:42:22 AM »
No, that's not a problem.

The ObjectId.GetObject() method implicitly uses the top-level transaction.  So it is only an error to call ObjectId.GetObject() if there is no current transaction.  The VB code given starts a transaction, so that should be fine.

Except for the failure to use the "using" keyword.  That isn't exactly an error - the "using" keyword is really just a syntactical shortcut - but if the code doesn't use "using", then it should use a try-finally block, and put the Dispose() calls in the Finally block.

sinc

  • Guest
Re: RootNamespace
« Reply #40 on: December 29, 2007, 12:43:28 AM »
Speaking of exception handling, it would also be nice if the Autodesk developer documentation included the possible exceptions that various methods can throw...  The core .NET documentation from Microsoft typically includes this information, but the Autodesk stuff leaves something to be desired.

Richard,
The only way this will happen is if enough people contact Kean Walmsley and Stephen Preston at AutoDesk with a compelling argument.


A compelling argument shouldn't be necessary.  It should be blatantly obvious that API documentation is not complete if it does not document the exceptions.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: RootNamespace
« Reply #41 on: December 29, 2007, 02:07:14 AM »
No, that's not a problem.

The ObjectId.GetObject() method implicitly uses the top-level transaction.  So it is only an error to call ObjectId.GetObject() if there is no current transaction.  The VB code given starts a transaction, so that should be fine.


Richard, this is from Reflection in IL ..
From the VB code
    L_0048: call instance class [acdbmgd]Autodesk.AutoCAD.DatabaseServices.DBObject [acdbmgd]Autodesk.AutoCAD.DatabaseServices.ObjectId::GetObject(valuetype [acdbmgd]Autodesk.AutoCAD.DatabaseServices.OpenMode)
    L_004d: castclass [acdbmgd]Autodesk.AutoCAD.DatabaseServices.BlockTableRecord
<...>


From the C# code

    L_0076: callvirt instance class [acdbmgd]Autodesk.AutoCAD.DatabaseServices.DBObject [acdbmgd]Autodesk.AutoCAD.DatabaseServices.Transaction::GetObject(valuetype [acdbmgd]Autodesk.AutoCAD.DatabaseServices.ObjectId, valuetype [acdbmgd]Autodesk.AutoCAD.DatabaseServices.OpenMode, bool)
    L_007b: castclass [acdbmgd]Autodesk.AutoCAD.DatabaseServices.BlockTableRecord
<...>

it seems to me the VB does not use the transaction.
I may be placing too much importance on the things I've read .. or misunderstanding them , but the docs ARE pretty clear ...
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.

sinc

  • Guest
Re: RootNamespace
« Reply #42 on: December 29, 2007, 10:12:23 AM »
Yeah, I think the docs are pretty clear, too.

This is from the documentation for the DatabaseServices.ObjectId.GetObject() method:

Quote
Overloaded. This method calls the TransactionManager.GetObject() method of the top transaction passing on all the arguments it has received.

Transactions may be "nested".  You can create a transaction, then in the middle of processing that transaction, you can create and commit another transaction.  Each time you start a new transaction, you add it to the top of the stack.  GetObject() automatically uses the top-most transaction on the stack (i.e., the last one you created).  It should be functionally equivalent to calling Transaction.GetObject().  I'm guessing that calling GetObject() on the Transaction directly may result in slightly-better performance, because the ObjectId.GetObject() method would need to figure out which transaction to use, but the difference is probably minimal.  We'd have to do a benchmark test to actually find out if there's any significant time difference between the two.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: RootNamespace
« Reply #43 on: December 31, 2007, 10:52:01 AM »
Except for the failure to use the "using" keyword.  That isn't exactly an error - the "using" keyword is really just a syntactical shortcut - but if the code doesn't use "using", then it should use a try-finally block, and put the Dispose() calls in the Finally block.
OK, so if I understand what your saying, IF you use a "using" statement there is no need for a Try/Catch ?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: RootNamespace
« Reply #44 on: December 31, 2007, 11:53:30 AM »
Kerry, you have shown some very interesting things in the compressed code example to draw a line.  the 2 things that jump out at me right away are the casting of BTR to the TR instead of creating a BTR, and the use of SymbolUtilityServices.GetBlockModelspaceId.  The first I kinda understand, your just shortcutting the process.  The second, I didn't even know existed.  In the SymbolUtilityServices, what is the bool openedErased at the end used for?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)