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: 

How can I export formatted text from a string indicator?

Does someone know how I can export formatted text (i.e., parts of the text have different formatting, such as color, fontsize, etc.) from a string indicator? Using copy/paste does not work, as it only exports unformatted plain text.
0 Kudos
Message 1 of 13
(4,017 Views)

Hi EduMIT,

there are several ways to export formatet text to other programs. If you have the report toolkit (http://sine.ni.com/nips/cds/view/p/lang/de/nid/5769), use those VIs. You can also use ActiveX controls. This offers kind of remoting other programs like MS Word. This link shows an example:

http://zone.ni.com/devzone/cda/epd/p/id/992

but you will find many other examples. Sometimes ActiveX is not documentated clearly, so you need some examples and some time to try it out.

An other possibility is to use standard function: Funtions>All Functions>Report Generation. On this way you could export test into html documents.

0 Kudos
Message 2 of 13
(3,998 Views)

Hello Sparti,

    Thank you for your suggestions, they are all very useful, and I plan to use the HTML feature under Report Generation to export the formatted text from Labview. However, I am still not sure how I can extract the formatted text from a *string indicator* and transfer it to one of those VIs, so that it can be exported to other applications. Let me give some more specific info on what I am trying to achieve:  I am monitoring the communication between two pieces of equipment. A string indicator shows all the data flow, with different colors for data coming from different instruments. I managed to do that by using a property node and playing with the selection and font color properties. Now, if you just wire the output of the string indicator, the formatting is gone and all you get is just plain black text (for instance, try to programmatically transfer the formatted text from one string indicator to a different string indicator and you will see that the formatting is not preserved). Even if you try the "brute force" method of manually selecting and copying the text in the indicator and pasting it to Word, LV does not export the formatting. But, if you paste *within*  LV (for example, paste it to a string constant in your diagram), then it works. To extract the formatted string from the indicator, I also tried to use a property node, but without success. I am trying to avoid duplicating part of my code to generate the same color-coding scheme on a report. It would be way easier to be able to transfer the formatted text from the string indicator. This is particularly annoying, because the information is there, stored in the data structure associated with the string indicator. But how can I put my hands on it? Any ideas?

0 Kudos
Message 3 of 13
(3,979 Views)

Hi EduMIT,

the way you want to transfer your datas does not work. This because the value in string does only contain letters, and no format. If you want to transfer format from one indicator to another, you have to work wirth property nodes. So you just read out all necessary format settings form the source indicator (by property node) and transfer those datas to the target property node (eg colors, text size, bold and so on).
An easier way could be to fill all datas (like passed/failed, complete/reading, value, unit ...)  in a table (in the background and not visible for the user). From this table you could uptate a specific indicator (eg: value = n, status = failed -> red and bold, ...) by a method. If you want to transfer datas, just read this table out by the same method reapplying on an other indicator. This way is encapsulated, upgradable and clearly arranged.

0 Kudos
Message 4 of 13
(3,952 Views)

Was just looking into this as well.. have a more complicates use case.. formatting for string is not the same everywhere as sections can be modified (see link below).

Thinking of just scanning the enitre string and then turn it in html/rtf. Anyone already some experience with this?

 

https://forums.ni.com/t5/LabVIEW/Programmatically-move-cursor-inside-string-indicator/m-p/4196681#M1...

 

Copy to clipboard doesn't work using the standard function.. it remains plain text.. soo more looking into that as well

beuvink_0-1639125323571.png

 

---

25+ years long fan of LabVIEW. Be aware that NI changed their business model with great impact .
0 Kudos
Message 5 of 13
(2,350 Views)

You can loop over each character, using selected text:

Text Formatting.png

You'd have to read each property of interest and manage state changes and translate it to some formatted string (like HTML or something custom).

 

This will get complex fast...

 

Can you explain the use case? E.g. during development you can simply copy the control\constant, and formatting will be copied.

0 Kudos
Message 6 of 13
(2,343 Views)

Hi Wiebe,

 

This was indeed the approach I had in mind. Something like below where the entire Text.Font cluster is compared to previous value. When defering panel updates I think for small texts this would be possible.

If I am going to implement something like this I will add the solution code to this forum. Just converting it to some raw HTML shouldn't be that complicated. Only a few parameters to process.

beuvink_0-1639734396227.png

 

About the use case. I am making a script interpreter, where I will also add some syntax highlighting and debugging highlighting.

For documenting, I tried to copy & pasting the formatted text into word and such for documenting. This looses all formatting.

Formatting is kept when copied within labview from one control to another.

---

25+ years long fan of LabVIEW. Be aware that NI changed their business model with great impact .
0 Kudos
Message 7 of 13
(2,300 Views)

@beuvink wrote:

Hi Wiebe,

 

This was indeed the approach I had in mind. Something like below where the entire Text.Font cluster is compared to previous value. When defering panel updates I think for small texts this would be possible.

If I am going to implement something like this I will add the solution code to this forum. Just converting it to some raw HTML shouldn't be that complicated. Only a few parameters to process.

beuvink_0-1639734396227.png

 

About the use case. I am making a script interpreter, where I will also add some syntax highlighting and debugging highlighting.

For documenting, I tried to copy & pasting the formatted text into word and such for documenting. This looses all formatting.

Formatting is kept when copied within labview from one control to another.


You could consider using .NET controls.

 

I never did that, but I'd thing copy-pasting from a .NET rich text control to office might be seamless. You wouldn't have to catch copy events, convert the text, and get the formatted text on the clipboard.

 

It could be a dead end.

0 Kudos
Message 8 of 13
(2,294 Views)

This was the approach I was thnking on for in order to copy to clipboard.

The labview clipboard function is text only. So when copy/paste HTML in this way it pastes in office as plain HTML code.

 

rtf specification is much more complex then HTML. Checking .net documentation I can see a method where you can copy to clipboard with type description.

However this seems like a dead end.. or do you have some other trick under your sleeves.. otherwise I will go for 'write to file', 'open file in browser', 'copy & paste' from there. Good enough for documentation.

beuvink_2-1639740248128.png

 

beuvink_3-1639740385813.png

 

Without constructor I get some error I didn't investigate further (same error with get text, just using clear as this is the most simple method)

beuvink_0-1639741106409.png

 

beuvink_1-1639741130204.png

 

 

 

 

 

---

25+ years long fan of LabVIEW. Be aware that NI changed their business model with great impact .
Download All
0 Kudos
Message 9 of 13
(2,290 Views)

Clear is static, so don't wire a constant (no need to).

 

The error will give you:

System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.

 

Go to VI properties and in Execution, set Preferred Execution System to "user interface".

 

It will clear the clipboard.

0 Kudos
Message 10 of 13
(2,284 Views)