From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Autosizing string indicator with carriage returns in the string

Solved!
Go to solution

I am trying to have a string indicator on my front panel automatically resize to accomodate the varying strings that get sent to it.

I found the "Get Text Rect.vi" function and it seems to do exactly what i want but only for the first line of my string.

It will not resize to show characters after a carriage return / new line.

Below is a picture of the autosized string next to a picture of the full string that i manually sized.

 

autosized.png                   full size.png

 

How can i autosize my string indicator box to incorporate all of my text?

0 Kudos
Message 1 of 8
(3,251 Views)

Hi Eric,

 

please show what you have tried so far.

 

Using GetTextRect is the way to go here…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(3,246 Views)

Search for Text.Document Bounds property

 

http://zone.ni.com/reference/en-XX/help/371361K-01/lvscript/text_document_bounds058height/

 

You could use this to adjust the font and text size to get it to fit.

Omar
0 Kudos
Message 3 of 8
(3,243 Views)

 

The GetTextRect function is working perfectly for me for the first line of my string.

My string is made up of multiple concatenated strings with carriage returns added.

The string indicator isn't sizing itself to incorporate the additional characters on the other lines.

 

See below for a simplified version of the code I am using.

I input a string constant that contains three lines, but when i size the box it only includes the first line.

The left shows the indicator on my front panel and the right shows the code that generated it.

size line.png 

 

Thanks,

 

-Eric

0 Kudos
Message 4 of 8
(3,227 Views)
Solution
Accepted by topic author EricBSEE

Would the "Size to Text" Invoke Node work?

Omar
0 Kudos
Message 5 of 8
(3,224 Views)

You are definitely close Omar_II

 

Using a 'size to text' invoke node now shows all off my text, but splits it in half.

Any ideas on how to get it all on one line?

I suppose i could specify the width left to right since my "The following parts are missing:"  line is so long that nothing else will probably be longer than it.

But it would be nice to have the string indicator just show everything automartically without me fixing any sizes with a constant.

 

long.png    

0 Kudos
Message 6 of 8
(3,207 Views)

Here is an idea.  I don't have the time to play with the code shown above to see if it works the way it seems like you want, or can't and you need to do this idea to work around it.

 

If you put your string through a for loop so that it indexes through it line by line.   Feed each line through Get Text Rectangle and keep track of which line is the longest.  Keep a running sum of the heights.  Then use that to set the boundaries of the text indicator.

0 Kudos
Message 7 of 8
(3,202 Views)

Omar's soultion was correct.

 

It actually turned out that i had a small glitch in my main code casuing the resizing to not work.

I tried it out on my simplified code that i used as an example and after adding the "size to text" invoke node after the GetTextRect.vi code, the box is now the right size regardless of what i send to the string.

 

Thanks!!

 

works.png

0 Kudos
Message 8 of 8
(3,188 Views)