Author Topic: Calling ConvertToStaticBlock() on a Table.  (Read 3310 times)

0 Members and 1 Guest are viewing this topic.

tjr

  • Guest
Calling ConvertToStaticBlock() on a Table.
« on: August 07, 2008, 01:30:54 PM »
Does anyone have any experience with converting tables to static blocks using the above method? It's a void with an optional string arguement but whenever I call it i get some database error. I'm looking to know when I should call this thing and any example snippets would help me a lot.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Calling ConvertToStaticBlock() on a Table.
« Reply #1 on: August 07, 2008, 02:01:00 PM »
I would get the error also, but you can do it this way.

Code: [Select]
[CommandMethod( "TestTableToBlock" )]
public void TestTableToBlock() {
Document Doc = acadApp.DocumentManager.MdiActiveDocument;
Database Db = Doc.Database;
Editor Ed = Doc.Editor;
using ( Transaction Trans = Db.TransactionManager.StartTransaction() ) {
PromptEntityResult per = Ed.GetEntity( "\n Select table: " ) as PromptEntityResult;
Table tbl = Trans.GetObject( per.ObjectId, OpenMode.ForWrite ) as Table;
BlockTableRecord LoRec = Trans.GetObject( Db.CurrentSpaceId, OpenMode.ForWrite ) as BlockTableRecord;
BlockReference BlkRef = new BlockReference( tbl.Position, tbl.BlockTableRecord );
LoRec.AppendEntity( BlkRef );
Trans.AddNewlyCreatedDBObject( BlkRef, true );
tbl.Erase();
Trans.Commit();
}
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

tjr

  • Guest
Re: Calling ConvertToStaticBlock() on a Table.
« Reply #2 on: August 07, 2008, 02:44:38 PM »
Thanks I'll try that.

Glenn R

  • Guest
Re: Calling ConvertToStaticBlock() on a Table.
« Reply #3 on: August 07, 2008, 04:22:58 PM »
From memory, a table is implemented as an anon block of the form '*TSomeNumberHere', the '*' being the cue for an anon block. I would suggest trying to get that block from the Table object, then you have a 'standard' acad block.

Glenn R

  • Guest
Re: Calling ConvertToStaticBlock() on a Table.
« Reply #4 on: August 07, 2008, 04:25:14 PM »
Also, in these sort of situations, post the following:

Acad Version
.NET Framework version
Visual Studio version
what .NET Framework version you are targeting
Error you are getting
Test code for others to play along.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Calling ConvertToStaticBlock() on a Table.
« Reply #5 on: August 07, 2008, 04:44:45 PM »
From memory, a table is implemented as an anon block of the form '*TSomeNumberHere', the '*' being the cue for an anon block. I would suggest trying to get that block from the Table object, then you have a 'standard' acad block.
You are correct, and that is how I did it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: Calling ConvertToStaticBlock() on a Table.
« Reply #6 on: August 07, 2008, 04:47:23 PM »
My apologies Tim - after re-reading your code (which I just scanned as it's late here) you are doing what I suggested.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Calling ConvertToStaticBlock() on a Table.
« Reply #7 on: August 07, 2008, 04:54:22 PM »
My apologies Tim - after re-reading your code (which I just scanned as it's late here) you are doing what I suggested.
No problem.  I'm glad I was on the right track.   :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

tjr

  • Guest
Re: Calling ConvertToStaticBlock() on a Table.
« Reply #8 on: August 07, 2008, 06:47:27 PM »
Also, in these sort of situations, post the following:

Acad Version
.NET Framework version
Visual Studio version
what .NET Framework version you are targeting
Error you are getting
Test code for others to play along.

It is boo code written in a development build of Sharpdevelop3. I don't know if many others would have wanted to play along with that.   :-) I agree that I should have posted my acad version as well as the error though.