jw_cad 外部変形 - (898) pythonでクリップボードを使う -

外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。

 

pythonクリップボードを使う

:pythonクリップボードを使う
@echo off
if not exist %~dpn0.py (
  for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
    more +%%n %0 > %~dpn0.py
  )
)
mshta %0 > jwc_temp.txt
copy jwc_temp.txt myfiles > nul
python %~dpn0.py > jwc_temp.txt
goto:eof

REM #jww
REM #e

<script language="jscript">
  close() //スクリーンを閉じる
// clipboardData.clearData() //クリップボードのテキストデータをクリアする
  set_txt = "ようこそ ありがとう"
  clipboardData.setData("Text",set_txt) //クリップボードにテキストデータをセットする
  get_txt = clipboardData.getData("Text") //クリップボードのテキストデータを取得する
  with (new ActiveXObject("Scripting.FileSystemObject")) {
    g = GetStandardStream(1) //標準出力
    g.WriteLine(get_txt) //クリップボードのテキストデータを出力する
  }
</script>

#!この次の行からプログラムを書いてください
# coding: shift_jis
import sys,re

try :
  f = open("myfiles", "r")
  for a in f:
    get_txt = a.rstrip()
  f.close()
except :
  sys.exit()

print("h#clip=%s" % get_txt)
print("cc4\ncn0 10 10 1 3")
print("ch 0 0 1 0 \"%s" % get_txt)

 

 

python用のクリップボードのライブラリをインストールすれば便利です。

pyperclip

:pythonクリップボードを使う(2)
@echo off
:if not exist %~dpn0.py (
  for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
    more +%%n %0 > %~dpn0.py
  )
:)
python %~dpn0.py > jwc_temp.txt
goto:eof

REM #jww
REM #e

#!この次の行からプログラムを書いてください
# coding: shift_jis
import pyperclip

pyperclip.copy('ようこそ ありがとう')
get_txt = pyperclip.paste()

print("h#clip=%s" % get_txt)
print("cc4\ncn0 10 10 1 3")
print("ch 0 0 1 0 \"%s" % get_txt)