CyberChaos(さいばかおす)

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

Autolisp言語で簡易CADチャットボットのプログラムを書いてもらった。

2023-05-19 19:30:25 | Autocad

Pythonで簡易CADチャットボットを作った - CyberChaos(さいばかおす) (goo.ne.jp)

でChatGPTにPythonで書いてもらったCADチャットボットプログラムを

今度はAutolisp言語で書き換えてもらった。

さて結果はどうなることやら。以下がそのコード。

(defun create-line ()
(setq start-x (atoi (vl-string->list (getstring "始点のX座標を入力してください。"))))
(setq start-y (atoi (vl-string->list (getstring "始点のY座標を入力してください。"))))
(setq end-x (atoi (vl-string->list (getstring "終点のX座標を入力してください。"))))
(setq end-y (atoi (vl-string->list (getstring "終点のY座標を入力してください。"))))

(command "_line" (list start-x start-y) (list end-x end-y))
)

(defun create-circle ()
(setq center-x (atoi (vl-string->list (getstring "中心のX座標を入力してください。"))))
(setq center-y (atoi (vl-string->list (getstring "中心のY座標を入力してください。"))))
(setq radius (atoi (vl-string->list (getstring "半径を入力してください。"))))

(setq x1 (- center-x radius))
(setq y1 (- center-y radius))
(setq x2 (+ center-x radius))
(setq y2 (+ center-y radius))

(command "_circle" (list center-x center-y) radius)
)

(defun process-user-input ()
(setq user-input (getstring "何をしましょうか?"))
(setq has-line (vl-string-search "直線" user-input))
(setq has-circle (vl-string-search "円" user-input))

(if has-line
(create-line)
(if has-circle
(create-circle)
(alert "そのような操作はできません。"))
)
)

(defun cad ()
(setq root (vlax-get-or-create-object "AutoCAD.Application"))
(setq doc (vla-get-ActiveDocument root))
(setq model-space (vla-get-ModelSpace doc))

(setq canvas (vla-AddCanvas model-space (vlax-3d-point '(0 0 0)) 400 400))

(setq button (vla-AddButton canvas "操作を入力" '(0 0 0) "process-user-input"))
(vla-put_Enabled button :vlax-true)

(vla-ShowBalloon button "CAD" "CAD" "操作を入力してください。" 1)
)

(defun c:cad ()
(cad)
(princ)
)

上記のコードは、AutoCADのカスタムコマンドとして実行することを想定しています。c:cadというコマンドを呼び出すことで、CAD環境が起動し、操作を受け付けます。

このコードをAutoCADのLISPエディタに貼り付け、保存してからc:cadというコマンドを実行すると、CADアプリケーションが起動し、指定された操作を行うことができます。

ご注意ください。

P.S.

全く動かんorz

やはり苦楽したAutocad2020ではダメなのか?

禿臆で更新できるAutocad2023とかを扱ってる輩から買い直すしかないのか?


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でも可能なのではないかと考えているが・・・


任意のソースコードをQRコード化するPythonアプリ

2023-05-19 14:46:45 | python

import tkinter as tk
import qrcode

def generate_qrcode():
python_code = code_entry.get("1.0", tk.END)

qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=10,
border=4,
)
qr.add_data(python_code)
qr.make(fit=True)

filename = filename_entry.get()
image = qr.make_image(fill_color="black", back_color="white")
image.save(filename)

# TKinterウィンドウの作成
window = tk.Tk()
window.title("QR Code Generator")

# テキスト入力フォーム
code_label = tk.Label(window, text="Python Code:")
code_label.pack()
code_entry = tk.Text(window, height=10, width=50)
code_entry.pack()

# ファイル名入力フォーム
filename_label = tk.Label(window, text="Filename:")
filename_label.pack()
filename_entry = tk.Entry(window)
filename_entry.pack()

# 保存ボタン
generate_button = tk.Button(window, text="Generate and Save QR Code", command=generate_qrcode)
generate_button.pack()

# TKinterウィンドウの実行
window.mainloop()

↑このQRコードを読み取るとwww