1
3

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 1 year has passed since last update.

pyRevit の始め方

Last updated at Posted at 2022-09-14

目次

1. pyRevitとは
2. インストール
3. フォルダの設定
4. HelloWorld

pyRevitとは

  • PythonやDynamo、Grasshopperなどを用いてリッチなGUIのRevitアドインをつくれるツール
  • .NETフレームワークを用いる通常のアドイン開発と比べてとても簡単
  • (英語ですが)公式チュートリアル・ドキュメントあり

インストール

下記リンクから最新版のインストーラーをダウンロードして、pyRevitをPCにインストールします。現在(2022.09.14)の最新版はバージョン4.8.12です。

image.png
プラグインをインストールすると、Revitのタブバーに「pyRevit」タブが表示されます。
image.png
pyRevit」パネルから「About」ボタンをクリックするとダイアログが表示され、pyRevitのバージョンを確認できます。
image.png

フォルダの設定

pyRevitでは、以下のようなフォルダ構成によってUIをつくります。各フォルダの名前がUIに表示されます。「<ボタン名>.pushbutton」フォルダにpythonスクリプトとアイコン用の画像を入れます。

フォルダ構成
C:.
└─<エクステンション名>.extension
    └─<タブ名>.tab
       └─<パネル名>.panel
           └─<ボタン名>.pushbutton
               └─icon.png
               └─script.py

今回の例では、Cドライブ直下に「pyrevit_sample」というフォルダを作成しました。ボタンのアイコンにはRevitのロゴ画像を使用しています。

フォルダ構成
C:\pyrevit_sample
    └─SampleExt.extension
        └─SampleTab.tab
           └─SmaplePnl.panel
               └─SampleBtn.pushbutton
                   └─icon.png
                   └─script.py

image.png

  • 既定のフォルダ名(<タブ名>.tab など)になっていないフォルダは無視されます。
  • ボタンをクリックした際に実行するpythonスクリプト「script.py」から別のpythonスクリプトを呼び出すことも可能です
  • 複数のボタンで利用するスクリプトや設定値を保存するJSONファイルは、「<エクステンション名>.extension」フォルダ直下に入れて「script.py」から呼び出します。
フォルダ構成
C:.
└─MyExtension.extension
    ├─config.json             #共有の設定値
    ├─mylib.py                 #共有のクラス・関数
    └─NotionLink4Revit.tab
       ├─Issues.panel
       │   ├─Apply Issues.pushbutton
       │   │   └─icon.png
       │   │   └─script.py
       │   │   └─gui.py        #「script.py」から呼び出すpythonスクリプト
       │   ├─Delete Issues.pushbutton
       │   │   └─icon.png
       │   │   └─script.py
       │   └─Delete Issues.pushbutton
       │       └─icon.png
       │       └─script.py
       ├─Debug.panel
       │   └─(略)
       ├─Properties.panel
       │   └─(略)
       └─Properties.panel
           └─(略)

image.png

pyRevit」パネルから「Setting」ボタンをクリックして、「pyRevit Settings」ダイアログを開きます。「Custom Extension Directories」から「Add folder」ボタンをクリックし、先ほど作った「C:\pyrevit_sample」フォルダを設定します。

<エクステンション名>.extension__」フォルダの1つ上のフォルダを指定します。「__<エクステンション名>.extension」フォルダを指定すると読み込まれないので注意してください。

image.png

HelloWorld

実際にPythonスクリプトを書いて "HelloWorld" を表示してみます。
以下コードを書いて保存して、

script.py
# encoding: UTF-8
print ("Hello World")

Reload」ボタンをクリックして「はい」を選択します。
image.png

リロードすると新しく作成した「ボタン」ボタンが現れて、クリックすると "HelloWorld" が表示されます。
image.png

1
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?