(Formely I/O).
This is a Python sample code for Design Automation API (DA) (v3). It demos the workflow on updating the width and height param of DWG Dynamic Block (using AutoCAD), RVT Window Family instance (using Revit), IPT Part parameters (using Inventor) and 3DS ... (using 3dsMax). The source demo files and plugin projects are cloned from learn.forge.designautomation
- Python: Download Python. The code can work with old version such as 2.7.9, but it requires to have TLS1.2 supported. It is recommended to use Python > 3.
- Forge Account: Learn how to create a Forge Account, activate subscription and create an app at this tutorial. Make sure to select the service Design Automation API V3 (beta). Make a note with the credentials (client id and client secret) of the app.
- Plugin: Build the the plugin in Plugins folder by corresponding version of Visual Studio and refererences of correspoinding Autodesk products. The app bundle zip will be put to bundles folder by post-build event
- Install dependencies via pip:
pip install -r requirements.txt
- input the credentials (client_id and client_secret) config.py. Input desired nickname and alais.
#Forge Client Id
Forge_CLIENT_ID = ''
#Forge Client Secret
Forge_CLIENT_SECRET =''
#desired nick name
desired_nickname = 'xiaodonglikename'
#Alias
alias = 'dev'
- run main.py with width and height value:
-
- python main.py --height [height value] --width [width value]
-
Follow the note of command line to select: bundle, app engines. The code will re-use the name of bundle name as the appBundle name and activity name of DA. Ensure to select the suitable engines for the corresponding bundle.
-
The code will create a new activity or appbundle if they do not exist. If they exist, one new version will be generated.
-
Before posting workitem, the code will upload the demo source file to OSS bucket of your Forge account. The updated model file will also be put to OSS bucket, with a new name.
-
Wait for the response about work item status. If it success, the output model file (model with the updated parameters) will be downloaded to output folder. Try with other tool (such as https://viewer.autodesk.com ) to verify if the model is valid and parameters are updated. If it fails, the log file will be downloaded to report folder.
Click the image below to check the demo video:
- When installing depencencies, for such similar error as below, try to upgrade pip
Could not fetch URL https://pypi.python.org/simple/pathlib/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661)
- When running the code, it failed with such error below, check if TLS1.2 and above is supported with SSL request with this Python enviroment.
requests.exceptions.SSLError: HTTPSConnectionPool(host='developer.api.autodesk.com', port=443): Max retries exceeded with url: /authentication/v1/authenticate (Caused by SSLError(SSLEOFError(8, u'EOF occurred in violation of protocol (_ssl.c:590)'),))
The best is to upgrade Python to version which > 3. Or try to install requests by security if in old version of Python, e.g.
pip install requests[security]
These samples are licensed under the terms of the MIT License. Please see the LICENSE file for full details.
Autodesk Forge Support
- Xiaodong Liang @coldwood
See more at Forge blog.