

JWWの外部変形は非常に便利な機能です。多くの方が作られていますが今見つけられるのはEXE形式のものが多く、どうやってデータを加工しているのかわかりません、私なりに考えてPythonで作ってみます。
2.5Dの数値入力を楽にする外部変形:
Pythonでファイルを指定するとき、注意が必要
with open("F:\CAD\Jww\gaibu\temp.txt",mode='r') as f:
これだとERRno22になる
with open(r"F:\CAD\Jww\gaibu\temp.txt",mode='r') as f:
ファイルパス名の前に「r」をつけると、エラーなくなりました。
範囲選択された三角形の面積を求めるPythonのコード
f2=open('temp2.txt','w')
f3=open('temp.txt','w')
start = 0
cnt = 0
datas = [] #配列の初期化
datas2 = []
with open('Bak.txt') as f:
for s_line in f:
if start == 1:
#f3.write(s_line) ##
datas2 = s_line.split()
datas.append([datas2[0],datas2[1]])
datas.append([datas2[2],datas2[3]])
#f3.write(str(datas)) ## Listをstrに
cnt += 1 # cnt++ は使えない
if s_line == '#\n': #一行には改行がある
start = 1
datas = list(map(list,set(map(tuple,datas)))) #重複削除
#f3.write(str(datas))
x=float(datas[0][0])
y=float(datas[0][1])
cnt=0
datas3=[]
for i in datas: #原点を(0,0)に移動
xx=float(i[0])-x
yy=float(i[1])-y
datas3.append([xx,yy])
cnt += 1
print(datas3)
# ------------------------
x1=float(datas3[1][0])
y1=float(datas3[1][1])
x2=float(datas3[2][0])
y2=float(datas3[2][1])
men = 0.5*abs(x1*y2-x2*y1)
print(men)
#---------------
# test = list(map(int,datas))
# f2.write(str(datas3))
# f2.write('\n')
f2.write("ch 0 3 10 0 \"")
f2.write(str(abs((men))))
f2.close()
f3.close()
ファイルに書き込むのは、文字列型(Str)でないとエラーになるようです。
横文字2重線で取り消し
with open('Bak.txt','w') as f2:
with open('JWC_TEMP.TXT') as f:
for line in f:
#シーケンスNo endは-1まで
if line.find("hs",0,2) >= 0:
list_hs = line.split()
list_hs.pop(0)
list_hs=[float(x.strip()) for x in list_hs]
#print(list_hs)
if line.find("hch", 0, 3) >=0:
list_hch = line.split()
list_hch.pop(0)
list_hch=[float(x.strip()) for x in list_hch]
#print(list_hch)
if line.find("lg", 0, 2) >=0:
lg_Num = line[2:]
scale=list_hs[int(lg_Num)] #縮尺
#print(scale)
if line.find("cn", 0, 2) >=0 and line.find('cn"', 0, 3) != 0:
cn_Num = int(line[2:])
#print(cn_Num)
takasa = float(scale* (list_hch[cn_Num-1])) #
#print(takasa) 12.5
if line.find("ch", 0, 2) >=0:
list_ch = line.split() #分割
list_ch.pop(0) #文字削除
list_ch=[float(x.strip()) for x in list_ch[:3]]
#print(list_hch)
xs=list_ch[0]
ys=list_ch[1]
w=list_ch[2]+xs
yh=float(100*takasa/3/100)
ys=ys+yh
list_ans=[xs, ys, w, ys]
ans=" ".join(map(str,list_ans)) # " ".join 空白で連結
yh2=yh*2
ys=ys+yh
list_ans2=[xs, ys, w, ys]
ans2=" ".join(map(str,list_ans2))
print(ans, file=f2) #ファイルに書き出しできる
print(ans2, file=f2)
Python 文法いろいろ
ファイルを一行ずつ読み、文末改行削除、表示
with open('JWC_TEMP.TXT') as f:
for line in f:
print(line.replace("\n",""))
pythonに与えられた引数を調べる
C:\Users\hkmab\anaconda3\python.exe fukusen.py %1 %2 %3
pause
上記の「%1、%2」がどうなっているのか調べます。
import sys
args = sys.argv
print(args)

線の角度を求める

math.atan2()とmath.degrees() を使う
sympyライブラリーが使えそう
参考にしたサイト:
printフォマット

f をつけない場合は:

{}の中が展開されません。
図を描く
%matplotlib inline
このコードなくても動くようです。
コメント