Jump to content

IronPython: copy to clipboard in Web Player

Kerry McClain 2

Recommended Posts

I've got a requirement to copy some text to the clipboard when an action control (button) is clicked in Spotfire. I've got it working in the desktop version of Analyst, but I get this error when I try to execute the script in the Web Player:

Could not execute script 'myScript': Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.

My IronPython code looks like this:

import clr


from System.Windows.Forms import Clipboard

theText = "some text goes here"

Clipboard.SetText(theText)Is there a way to get this functionality (or something equivalent)to work in the Web Player



West Texas Analytics, LLC

Link to comment
Share on other sites

Unfortunately it is not possible to get the copy to clipboard functionality work in Web Player. The scripts triggered on Web Player are executed on the Node Manager machine and namespaces like System.Windows.Forms does not work when running the scripts on Web Player.




I have successfully solved this issue using a combination of IronPython and Javascript. The basic steps are:


* IronPython: Generate the text that needs to be copied to clipboard

* IronPython: Assign text to a Label property control

* IronPython: Add a space to the content of the HTML text area to trigger a rerender of the HTML, which triggers the Javascript


*JS: const el = document.createElement('textarea');

el.value = $("#divLabelPropertyControl").text();






Works perfectly in Analyst and in Consumer!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...