1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AutoLISPでAutoCADコマンドを実行する

Last updated at Posted at 2020-01-09

AutoLISPからAutoCADの標準コマンドを実行するには、command関数を使用する。

command関数の使い方

command関数の引数に、AutoCADコマンドを文字列(" " で囲む)で記入する。

(command "コマンド名" "引数" "引数" ・・・) 
【例1】線分(LINE)コマンドで座標 20,30 から 座標 50,100 まで線分を作成する
(command "LINE" "20,30" "50,100" "") 

最後の引数の "" はEnterキーを押すのと同じ動作となる。
空Enterすることで、LINEコマンドを終了している。
この例のように、command関数の引数は、AutoCADのコマンドラインからコマンドを実行する場合と同じように記述する。
同じ動作をコマンドラインから実行するには、

LINE [Enter]
20,30 [Enter]
50,100 [Enter]
[Enter]

となる。

【例2】ユーザーが2点を選択して、線分を作成する
(command "LINE" PAUSE PAUSE "") 

引数の PAUSE は AutoLISPの定義済定数で、ユーザー入力を行うために使用する。

【例3】変数に保存された値から、線分を作成する
(setq p1 '(20 30))
(setq p2 '(50 100))
(command "LINE" p1 p2  "")  
【例4】getpoint関数を使用して、ユーザーが選択した点を変数に保存し、その変数に保存された値を使って線分を作成する
(setq p1 (getpoint "\n一点目を指示"))
(setq p2 (getpoint p1 "\n二点目を指示"))
(command "LINE" p1 p2  "") 
【例5】座標100,100を中心とした半径50の円を作成
(command "CIRCLE" "100,100" "D" "50")
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?