The following article explains the basics to writing a Plugin for n4ce and running it. The Python API (Application Programming Interface) is still in it's infancy and as such will probably change in the future. It can not therefor be guaranteed that code that works now, will still run in the future. Though we are doing our best to minimise changes to the API that will actually break existing Python code.
As of December 2024 the Python API allows the points in a Model to be looped over for reading, and also to put data back into a new or existing model.
Our preferred development environment for working with Python is VScode which can be downloaded from here:
https://code.visualstudio.com/download
Example Python scripts are provided in the folder "C:\ProgramData\Applications in Cadd\n4ce\Plugins\Demo"
The Tutorial.py file demonstrates some of what is possible with the API in its current state.
If you would like to test the ExcelFloorFlatnessGraph example, the necessary SDB file is attached to this article. Note you need to select the "School Hall" model BEFORE trying to run the Python script.
Once a script is ready to run, click on the appropriate model in n4ce, and then from the Plugin tab in the n4ce Project Manager click on "Run Script". Click on the required .py file in the open file dialog and it will run.
n4ce has its own build of Python built in. The default folder that n4ce launches the Python runtime is here. "C:\Program Files\Applications in Cadd\n4ce 4.40\Program\Python"
If you download any new Python Libraries and would like to use them running from n4ce, then they need to be copied into the folder "C:\Program Files\Applications in Cadd\n4ce 4.40\Program\Python\Lib\site-packages"
When installing libraries via the very helpful pip tool, the downloaded files are usually put into this folder "C:\Users\<UserName>\AppData\Roaming\Python\<PythonVersion>\site-packages". So they will need to be copied into the n4ce site-packages folder above for n4ce to locate and use them.
Setting up Intellisense.
To help development intellisense is used to show the user what possible properties or functions are available to them as they write code. To set this up please do the following....
1. Press F1 in VScode,
2. Search for Python Select Interpreter
3. Click the folder icon to "Enter an Interpreter path"
4. Click Find.... Then browse to the folder shown below and select the Python.exe file in there.
5. Once that is done, intellisense should appear for n4ce objects as you type.
Comments
0 comments
Please sign in to leave a comment.