Kerry McClain 2 Posted November 6, 2019 Posted November 6, 2019 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 clr.AddReference('System.Windows.Forms') 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 Thanks, Kerry West Texas Analytics, LLC
Kirsten Smith (she/her) Posted November 7, 2019 Posted November 7, 2019 Issue resolved in Support ticket
Kirsten Smith (she/her) Posted November 13, 2019 Posted November 13, 2019 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. ================= Update: 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(); document.body.appendChild(el); el.select(); document.execCommand('copy'); document.body.removeChild(el); Works perfectly in Analyst and in Consumer!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now