.NET

Reply
Active Member
WRonX
Posts: 7
Registered: ‎06-21-2011
Message 1 of 2 (589 Views)

Table height problem - how to insert Table by choosing it's bottom-right corner?

589 Views, 1 Replies
07-06-2011 04:03 AM

Hi.

 

I have to make it possible to insert table by choosing any of it's corners. I cannot get it to work with choosing bottom corners - I can't get the exact height of the table.

 

The sample code of the one-row table is:

 

acApp.Document doc = acApp.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;

Transaction tr = ed.Document.Database.TransactionManager.StartTransaction();
try
{
    BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);

    Table tb = new Table();
    tb.InsertColumns(0, 24, 1);

    tb.SetRowHeight(4);
    tb.Columns[0].Width = 24;
    tb.Columns[1].Width = 24;

    tb.Cells[0, 0].TextHeight = 2;
    tb.Cells[0, 0].TextString = "some text";
    tb.Cells[0, 0].Alignment = CellAlignment.MiddleRight;

    tb.Cells[0, 1].TextHeight = 2;
    tb.Cells[0, 1].TextString = other_text_from_variable;
    tb.Cells[0, 1].Alignment = CellAlignment.MiddleCenter;

    tb.HorizontalCellMargin = 0;
    tb.VerticalCellMargin = 0;

    tb.GenerateLayout();
    tb.Position = // exactly... what should I do here? 

    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
    btr.AppendEntity(tb);
    tr.AddNewlyCreatedDBObject(tb, true);
    tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
    ed.WriteMessage("\n ERR: " + ex.Message);
}
finally
{
    tr.Dispose();
}

 

Now... I'm trying to make 1-row table width the height 4. I should set tb.Position by just subtracting 4 from the Y-value of the clicked point... NOT.

tb.Height gives me 4. But I get the table with height 5.667. And I can't just use that value for subtracting, because even then, bottom-right corner is about 0.2 above or below clicked point... (X-value is correct and equals the clicked point's X-value.)

 

The same thing happens when I insert a table with the number of rows depending on the number of the records selected from DB. The same thing happens, when I use obsolete .NumRows and .NumColumns. What am I missing?

*Expert Elite*
chiefbraincloud
Posts: 752
Registered: ‎02-13-2008
Message 2 of 2 (573 Views)

Re: Table height problem - how to insert Table by choosing it's bottom-right cor

07-06-2011 09:45 AM in reply to: WRonX

I didn't examine your code closely, or try it myself, but my guess is that the combination of the TextHeight you are using and the Margins set in the TableStyle (or CellStyle..?) are forcing your RowHeights to change and making your table bigger.

 

Here is a link to a Through the Interface post which shows how to create a TableStyle from scratch (plus insert a Table and populate it).

 

http://through-the-interface.typepad.com/through_the_interface/2009/01/more-fun-with-autocad-tables-...

 

Note:  There is a complete set of code at the beginning, then further down there is an update for AutoCAD 2011 and greater, with another complete set of code.  And there is a comment on the post in which another person says that they found the RowHeights to be automatically adjusted to fit the TextHeight + the Margin when the RowHeight is set to anything less than that.

Dave O.                                                                  Sig-Logos32.png

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community