Python/ja: Difference between revisions
No edit summary |
No edit summary |
||
Line 21: | Line 21: | ||
== Pythonの始め方 == | == Pythonの始め方 == | ||
まず始めに、Python 3を学ぶ必要があります。最初に、Pythonのドキュメンテーションページ(http://www.python.org/doc/)を参照するとよいでしょう。 | |||
言語を学ぶのに最も早い方法は、Pythonのチュートリアルページを読むことです:http://docs.python.org/3/tutorial/ | |||
良いコードを書く方法、よくあるタスクを実行する方法のガイドについては、次を参照してください:[http://docs.python-guide.org/en/latest/ The Hitchhiker’s Guide to Python!] | |||
== Python 3とVectorworks == | == Python 3とVectorworks == | ||
VectorworksでのPythonスクリプティングは、ソフトウェアで[[VectorScript]]が動くのにとても似ています。Pythonスクリプトでは、「vs」という名前空間に存在するすべてのAPIが使用できます。もちろん、Pythonエンジンのすべての機能が使用でき、Pythonスタイルの型推論、クラス、イテレータ、ライブラリ、辞書、モジュール、list、tuple、rangeなどのパッケージシーケンス型もVectorworks環境で使用できます。 | |||
例えば、アラートダイアログを表示する簡単なPythonスクリプトは以下のようになります: | |||
[[Image:SimplePythonInVectorworks.jpg]] | [[Image:SimplePythonInVectorworks.jpg]] | ||
Line 39: | Line 39: | ||
# Type the script | # Type the script | ||
リソースマネージャでスクリプトラベルをダブルクリックして実行すると、アラートダイアログが表示されます。 | |||
== Python API == | == Python API == | ||
Python Vectorworks APIの完全な機能についてのリファレンスは、次のページを参照してください:[[VS:Function_Reference]] | |||
== サンプル == | == サンプル == | ||
Line 58: | Line 58: | ||
* Sample scripts to elevation information of VW objects: [[Python sample to Import elevation]] | * Sample scripts to elevation information of VW objects: [[Python sample to Import elevation]] | ||
== | == IDEおよびPythonスクリプトのデバッグ == | ||
Often users would use external IDE to edit the Python scripts that Vectorworks executes. Modern IDEs provide intelli-sense information (information about the semantics of the code while typing). To help intelli-sense for Vectorworks Python script APIs, you can point your IDE to the file [[File:vs.zip|vs.py (python file)]] (download, unzip, and place it appropriately so the IDE could find it). This way the IDE will know all Vectorworks Python functions and it would provide some information on the parameters and the behavior of the function. Note that those functions are empty and will not do anything if executed. | Often users would use external IDE to edit the Python scripts that Vectorworks executes. Modern IDEs provide intelli-sense information (information about the semantics of the code while typing). To help intelli-sense for Vectorworks Python script APIs, you can point your IDE to the file [[File:vs.zip|vs.py (python file)]] (download, unzip, and place it appropriately so the IDE could find it). This way the IDE will know all Vectorworks Python functions and it would provide some information on the parameters and the behavior of the function. Note that those functions are empty and will not do anything if executed. |
Revision as of 01:02, 11 December 2017
.Python|Python ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix ..Python Debugging|Debugging with Python
Pythonとは
Pythonとは、より迅速な作業とシステムの統合を可能にするプログラミング言語です。Pythonを習得することで、生産性が即座に向上し、メンテナンスのコストも削減できます。[1]
WikipediaのPyhtonの記事はこちら: http://en.wikipedia.org/wiki/Python_(programming_language)
さらに詳しくは、こちらのウェブサイト(英語)を参照してください: http://www.python.org/
Pythonのバージョン
Pythonには、Python 2.7と3.xの2つのバージョンがあります。
Vectorworksは、Python 3を使用しています。これは言語を習得してコードを書く上で非常に重要な点です。
! Vectorworksは、VW2015ではPython 3.3を使用しています。 Keep this in mind, as python adds new stuff in minor releases like enums in 3.4.
Pythonの始め方
まず始めに、Python 3を学ぶ必要があります。最初に、Pythonのドキュメンテーションページ(http://www.python.org/doc/)を参照するとよいでしょう。
言語を学ぶのに最も早い方法は、Pythonのチュートリアルページを読むことです:http://docs.python.org/3/tutorial/
良いコードを書く方法、よくあるタスクを実行する方法のガイドについては、次を参照してください:The Hitchhiker’s Guide to Python!
Python 3とVectorworks
VectorworksでのPythonスクリプティングは、ソフトウェアでVectorScriptが動くのにとても似ています。Pythonスクリプトでは、「vs」という名前空間に存在するすべてのAPIが使用できます。もちろん、Pythonエンジンのすべての機能が使用でき、Pythonスタイルの型推論、クラス、イテレータ、ライブラリ、辞書、モジュール、list、tuple、rangeなどのパッケージシーケンス型もVectorworks環境で使用できます。
例えば、アラートダイアログを表示する簡単なPythonスクリプトは以下のようになります:
- Right-click on the resource browser and create a new script
- Choose language for the script to be 'Python'
- Type the script
リソースマネージャでスクリプトラベルをダブルクリックして実行すると、アラートダイアログが表示されます。
Python API
Python Vectorworks APIの完全な機能についてのリファレンスは、次のページを参照してください:VS:Function_Reference
サンプル
These are some introductory samples that demonstrate plug-ins for Vectorworks written in Python. They are with increasing difficulty and demonstrate different aspects in the plug-in development under Vectorworks:
- Sample menu command: Python Sample Menu Command
- Sample point object: Python Sample Point Object
- Sample more complex point object: Python Sample Point Object (complex)
- Sample 2D path object: Python Sample 2D Path Object
- An object that display an image from the web: Python Sample WebLinkImage
- Sample of a menu and two objects: Python Sample Menu with Two Objects
- Sample that imports a folder of .png images as symbols: Python Sample Import Images as Symbols
- Sample scripts to elevation information of VW objects: Python sample to Import elevation
IDEおよびPythonスクリプトのデバッグ
Often users would use external IDE to edit the Python scripts that Vectorworks executes. Modern IDEs provide intelli-sense information (information about the semantics of the code while typing). To help intelli-sense for Vectorworks Python script APIs, you can point your IDE to the file File:Vs.zip (download, unzip, and place it appropriately so the IDE could find it). This way the IDE will know all Vectorworks Python functions and it would provide some information on the parameters and the behavior of the function. Note that those functions are empty and will not do anything if executed.
It is possible to debug Python scripts in Vectorworks using a third-party application.
See Python Debugging for more information.
List of some good IDE's:
- Aptana Studio 3 (Free)
- PyCharm (Free community edition, Paid full version)
See Also
- Scripting Common Tasks
- Installing Scripts
- List of Python tutorials for non-programmers
- List of Python tutorials for programmers
Notes
- ↑ As described on the Python official website: http://www.python.org