Hi…,
I would like to have a “copy text to clipboard” component. I’ve tried a Python script, but I failed.
Any ideas?
Thanks
Michael
Hi…,
I would like to have a “copy text to clipboard” component. I’ve tried a Python script, but I failed.
Any ideas?
Thanks
Michael
Copy text? Rich text? Images? Byte arrays?
sorry to be imprecise. text is my desire.
Actually that didn’t work
This works:
import subprocess
def copy2clip(txt):
cmd='echo '+txt.strip()+'|clip'
return subprocess.check_call(cmd, shell=True)
copy2clip('This is on my clipboard!')
Hello, this is a super useful code. I have one problem. It seems that the code fails when trying to copy special characters (ex: “&”). Is there a way to resolve this?
Hi @camcopete,
Thanks to this stack exchange answer: https://superuser.com/a/550057
here’s the solution, hope you don’t mind the extra quotes.
import subprocess
def copy2clip(txt):
cmd='echo ' + '"' + txt.strip() + '"' + '|clip'
return subprocess.check_call(cmd, shell=True)
copy2clip(x)
Maybe there is a whole new and better solution nowadays you should look for it on the internet.
here’s the .net solution:
import clr
clr.AddReferenceByName("System.Windows.Forms")
from System.Windows.Forms import Clipboard
Clipboard.SetText(x)
Nice script. However seems that I can’t copy data that it is longer than a single line. I do get copied into the clipboard only the last row of data from a list. I do need to be able to copy an entire list full of data. Maybe this script can be adapted to this purpose?
Not working. I just get a popup and after that Rhino freezes entirely.
Ok, made some progress:
import rhinoscriptsyntax as rs
txt = rs.ClipboardText(x)
with List access
as x
input and finaly I can copy an entire list into clipboard, but still not working as I do need.
How I can remove the ['
and ']
from the beginning and from the end of the text?
Also looks like I do have the entire list copied into clipboard as a sigle line. Where should be a Return
to a new line I do get ', '
this characters.
My goal it is to copy an entire CSV formated data, that I can quickly paste into LibreOffice Calc.
I created this python script to paste the system info in the clipboard.
import rhinoscriptsyntax as rs
rs.Command('-SystemInfo C')
fromclipboard = rs.ClipboardText()
systeminfo = ('[details="System Info"]\n\n'
+
fromclipboard
+
'[/details]')
rs.ClipboardText(systeminfo)
You smashed me. I am not programmer, so it is difficult for me to find a proper way to fix this.
If I strip down the SysInfo
stuff from your code I am going back to the previous code:
import rhinoscriptsyntax as rs
a = rs.ClipboardText(x)
but still I can’t strip the ['
and ']
from beginning and the and and also I do need to replace the ', '
and replace-it with a NewLine character.
I don’t consider myself a programmer either.
Found a way to copy the panel content to clipboard, formatted for Excel data transfer.