CyberChaos(さいばかおす)

プログラミング言語、トランスパイラ、RPA、ChatGPT、データマイニング、リバースエンジニアリングのための忘備録

Pythonで簡易CADチャットボットを作った

2023-05-19 17:00:40 | python

VBA版をPython版にしてみた。

ChatGPTにVBA版のソースコードをPythonに変換してくれと頼んだら一発で成功!

Bardの登場がChatGPTに大きな影響を与えているのが実感できる。

使い物にならなかったのが全く別物といってよい程の改善が行われたようだ。

import tkinter as tk
from tkinter import messagebox

def create_line():
    start_x = int(tk.simpledialog.askstring("直線", "始点のX座標を入力してください。"))
    start_y = int(tk.simpledialog.askstring("直線", "始点のY座標を入力してください。"))
    end_x = int(tk.simpledialog.askstring("直線", "終点のX座標を入力してください。"))
    end_y = int(tk.simpledialog.askstring("直線", "終点のY座標を入力してください。"))

    canvas.create_line(start_x, start_y, end_x, end_y, width=2)

def create_circle():
    center_x = int(tk.simpledialog.askstring("円", "中心のX座標を入力してください。"))
    center_y = int(tk.simpledialog.askstring("円", "中心のY座標を入力してください。"))
    radius = int(tk.simpledialog.askstring("円", "半径を入力してください。"))

    x1 = center_x - radius
    y1 = center_y - radius
    x2 = center_x + radius
    y2 = center_y + radius

    canvas.create_oval(x1, y1, x2, y2, width=2, outline="red")

def process_user_input():
    user_input = tk.simpledialog.askstring("CAD", "何をしましょうか?")
    has_line = "直線" in user_input
    has_circle = "円" in user_input

    if has_line:
        create_line()
    elif has_circle:
        create_circle()
    else:
        tk.messagebox.showerror("エラー", "そのような操作はできません。")

root = tk.Tk()
root.title("CAD")

canvas = tk.Canvas(root, width=400, height=400)
canvas.pack()

button = tk.Button(root, text="操作を入力", command=process_user_input)
button.pack()

root.mainloop()

もちろんこれは簡易プロトタイプである。

こんなもん現場では全然実用にならない。もっと複雑な操作が要求される。

次の段階はAutocadにこの機能を組み込むことが目標である。

それが成功したら、どんどんいろんな操作・機能を追加していこうと思っている。

Autolispのソースコード内でPythonを呼び出して組み込み、自動で描画できれば開発が早まるだろう。

もしそれができなければ、Autolispで全て書かなければならない。

はたしてAutolisp言語にはチャットボットを作るための機能や関数はあるのだろうか?

Lisp言語の本では人工知能について言及があったからAutolispでも可能なのではないかと考えているが・・・



最新の画像もっと見る

コメントを投稿

ブログ作成者から承認されるまでコメントは反映されません。