.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1 REPLY 1
Reply
Message 1 of 2
WRonX
829 Views, 1 Reply

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

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?

Tags (2)
1 REPLY 1
Message 2 of 2
chiefbraincloud
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost