.NET

Reply
*perry
Message 1 of 7 (54 Views)

A couple basic net questions

54 Views, 6 Replies
05-04-2006 02:40 PM
One of the first things I learned doing Arx programming was that the Acad
block table could not be modified. Only the records it contains can be
(modelspace, paperspace). Thus, I never even attempted to open the block
table in write mode, dont know if you can (in Arx). However, most of the .Net
examples I have seen so far do exactly this. They dont attemp to modify the
block table, but they do open it in write mode, then go on to open the block
table records. In fact they pretty much open every table/record in write mode.
Is this the new (.Net) way of dealing with this?
Is there any harm in just opening everything for write, regardless if your
going to modify it or not?
In the same vein, I have to say I do feel kinda weird opening all these objects
(like when Im iterating through the blocktable) and then just leaving them and
waiting for the system to close them. Keep expecting some horrendous crash.
I do dispose() all my databases & transactions in which the table operations reside.

Another question, when starting a transaction against a database, whats the difference
between this code:
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction t = db.TransactionManager.StartTransaction())

and this code?
Document doc = Application.DocumentManager.MdiActiveDocument;
using (Transaction t = doc.TransactionManager.StartTransaction())

The both appear to be using the current database.

Thanks for any insights
Perry
*Tony Tanzillo
Message 2 of 7 (54 Views)

Re: A couple basic net questions

05-04-2006 05:53 PM in reply to: *perry
No one's talking about opening the block table, you
have to open each block reference for write.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"perry" wrote in message news:5164605@discussion.autodesk.com...
One of the first things I learned doing Arx programming was that the Acad
block table could not be modified. Only the records it contains can be
(modelspace, paperspace). Thus, I never even attempted to open the block
table in write mode, dont know if you can (in Arx). However, most of the .Net
examples I have seen so far do exactly this. They dont attemp to modify the
block table, but they do open it in write mode, then go on to open the block
table records. In fact they pretty much open every table/record in write mode.
Is this the new (.Net) way of dealing with this?
Is there any harm in just opening everything for write, regardless if your
going to modify it or not?
In the same vein, I have to say I do feel kinda weird opening all these objects
(like when Im iterating through the blocktable) and then just leaving them and
waiting for the system to close them. Keep expecting some horrendous crash.
I do dispose() all my databases & transactions in which the table operations reside.

Another question, when starting a transaction against a database, whats the difference
between this code:
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction t = db.TransactionManager.StartTransaction())

and this code?
Document doc = Application.DocumentManager.MdiActiveDocument;
using (Transaction t = doc.TransactionManager.StartTransaction())

The both appear to be using the current database.

Thanks for any insights
Perry
Distinguished Contributor
RonnieWilkins
Posts: 454
Registered: ‎04-07-2003
Message 3 of 7 (54 Views)

Re: A couple basic net questions

05-04-2006 07:13 PM in reply to: *perry
Wouldn't you need to have the BlockTable open for write if you wanted to add a new block?
Ronnie Wilkins, Jr.
AMS CAD + CAFM Solutions
Sr. Solutions Developer
Autodesk Certified Instructor: Inventor
*perry
Message 4 of 7 (54 Views)

Re: A couple basic net questions

05-05-2006 07:52 AM in reply to: *perry
Tony Tanzillo wrote:
> No one's talking about opening the block table, you
> have to open each block reference for write.
>
Perhaps I did not phrase the question(s) correctly.
I know that you must open a reference for write if you
intend to modify it.
However, does not the following line (from Arx .net labs)
open the block table for write?

//Now, drill into the database and obtain a reference to the BlockTable
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForWrite);
*perry
Message 5 of 7 (54 Views)

Re: A couple basic net questions

05-05-2006 07:54 AM in reply to: *perry
rwilkins wrote:
> Wouldn't you need to have the BlockTable open for write if you wanted to add a new block?
But you cannot add/modify the block table. You must work with the block table
records, ie modelspace/paperspace.
*perry
Message 6 of 7 (54 Views)

Re: A couple basic net questions

05-05-2006 11:15 AM in reply to: *perry
Apparently Alzheimers is setting in.
My apologies for weird questions.
I could have sworn that the BLOCKTABLE was not
modifyable, that ALL entities belonged to either
modelspace or paperspace. But I just ran the following
code snippet:
BlockTable bt = (BlockTable)t.GetObject(db.BlockTableId, OpenMode.ForWrite);
foreach (ObjectId btrId in bt)
{
BlockTableRecord btr = (BlockTableRecord)t.GetObject(btrId, OpenMode.ForRead);
Utilities.prompt("\nBlocktable record name is: " + btr.Name.ToString());
}
and, as I expected, it returned *modelspace and *paperspace, but it also
returned every other block in the drawing as well.
Guess I'm half right. ALL block defs belong to block table, of which *modelspace
and *paperspace are special cases, and can be listed therein. ALL entities belong to either *modelspace
or *paperspace.

Dont know if I should get a lot more coffee, or just get started on the beer
(Its almost noon here!)
Perry
*perry
Message 7 of 7 (54 Views)

Re: A couple basic net questions

05-05-2006 11:47 AM in reply to: *perry
Still curious about the transaction question though!
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.