TextNote Height

TextNote Height

Anonymous
Not applicable
1,942 Views
7 Replies
Message 1 of 8

TextNote Height

Anonymous
Not applicable

I am working on creating a lot of formatted TextNotes from an Excel document. I have no issues creating the TextNotes, however the issue is with getting the height of the note.

 

Inside of a new transaction I am creating all the text. I am using the TextNote.Create Method with the overloads Document, ElementId, XYZ, Double, String, ElementID.

 

All is fine, however with the newly created TextNote, the height is always returned as 0.0.

 

I need to be able to read the height to set the position for the next piece of text. This is in 2018

 

Thanks

0 Likes
Accepted solutions (1)
1,943 Views
7 Replies
Replies (7)
Message 2 of 8

aignatovich
Advisor
Advisor
Accepted solution

Hi!

 

As a quick tip for such situations is document regeneration.

However it is not the best way to solve this task. I already did the same )) Tomorrow, I'll provide a bit more information, how to calculate text size without something like: create textnote, regenerate, measure size, than move or recreate textnote, because it is extremely slow.

0 Likes
Message 3 of 8

Anonymous
Not applicable

Thanks.  I have found that if every text note creation is in its own Transaction, the height reports properly.  SubTransactions don't exhibit the same behavior.  I will end up with thousands of transactions with this process. Its not ideal, due to the undo for the users.

0 Likes
Message 4 of 8

Revitalizer
Advisor
Advisor

Hi,

 

you can put the many Transactions into a TransactionGroup, resulting in a single undo step for the user.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 5 of 8

aignatovich
Advisor
Advisor

You can organize transactions in one TransactionGroup. If you call transactionGroup.Assimilate() after all inner transaction being commited, you will have only one item in undo list titled as transaction group. However, it is not the most efficient way to deal with changes in building model, in most cases document regeneration should be your choice

Message 6 of 8

aignatovich
Advisor
Advisor

And about text size calculations:

Font size converter (excell font size to Revit font size and vice a versa):

 

    public static class FontSizeConverter
    {
        private const double Factor = 25.4/96.0;
        private const double Delta = 2.5;

        public static double ToMillimeters(double fontSize)
        {
            return (fontSize - Delta)*Factor;
        }

        public static double ToFontSize(double millimeters)
        {
            return millimeters / Factor + Delta;
        }
    }

Text size calculation (leave maxWidth parameter if your text is not bounded):

 

 

        public Point Measure(string value, int maxWidth = 0)
        {
            using (var graphics = Graphics.FromHwnd(IntPtr.Zero))
            {
                var size = graphics
                    .MeasureString(value, GetFont(), maxWidth);

                return new Point(size.Width, size.Height);
            }
        }

 

 

0 Likes
Message 7 of 8

Anonymous
Not applicable

Thanks for your suggestions.  It was best preforming to leave all the text generation in one big Transaction and regenerate the document when I needed to get the height of the text block. using a bunch of little transactions  inside a TransactionGroup was very slow, and subtransactions didn't provide the information needed either.

0 Likes
Message 8 of 8

WorldDue
Enthusiast
Enthusiast

Do you have the details of the GetFont() function in there?

I can't seem to get the adequate size and styles from the TextNoteType to the Graphics of c#

0 Likes