Welcome to the PTC API Playground! In this repository, you will find:
WELCOME TO THE PTC PLAYGROUND!
The goal of this project is to enable anyone to get started with creating simple Python apps that connect to Onshape and ThingWorx REST API's. We've created a number of "snippet libraries" that show you how to use API keys to get and set information with Python notebooks. These libraries and example python notebooks are hosted in Google Colab, a web hosted version of Jupyter Notebooks.
The simplest way we've found for using the snippets is to add them as a custom snippet library in Google Colab as shown below. Then you can click on the arrows to insert them into your new Pyton notebook.
- Open a document in Google Colab.
- In the toolbar at the top (left) of your Google Colab you can go into the Tools > Settings > Sites Menu
- Copy the Master Snippets Library URL (click here for the Onshape API Snippets URL or here for the ThingWorx API Snippets URL) into the "Custom Snippet notebook URL box".
- Hit save!
- You can now open the snippets library in the menu on the left with the angled brackets: "<>". This is where all of the default snippets and the snippets from the "master snippets library" are.
- Add them to your document!
Click here to see the latest version of the Onshape API Snippets library. The first step is to use snippet 0.1 to import the Onshape Client.
Then you will need to create API Keys from Onshape's Developer Portal. These keys can either be put directly in snippet 0.2 of the library, or saved in a file called "colabkeys.py" with the following format and used with snippet 0.3 (all api keys below are fake or have been deleted - replace with your own).
access = 'Z97asb1257FkEwzp3EmCpa'
secret = 'nHwN3q7asdvg4aryFC9rxYyo9U4o415WokYa8VOQ9YfUh4Zx'
Click here to see the latest version of the ThingWorx API Snippets library. Click here to learn more about the ThingWorx REST API.
To get started with ThingWorx REST API, you will need an API key and make sure that it has the propper permissions for the entities you want to access. There are instructions here for learning how to generate an appkey and give it proper permissions.
We have created a custom Python Library/Package called PTCColab to simplify some of the complexities involved with using the Onshape and ThingWorx REST API's. Click here to see the latest version of the snippets library that uses the PTCColab library.
PTCColab was built with the intention of being a springboard for app development that use the Onshape API with basic connections to the Thingworx API. PTCColab can be used in any Python3 REPL however, PTC-API-Playground has been designed to work seemlessly with Google Colab, the Google Hosted Jupyter Notebook environment. The examples/"master snippet library" can be referenced for any Python Notebook or script. Specific documentation for PTCColab can be found here. Happy Hacking!
General Tips:
- To connect to PTCColab using Snippets 1.1 is required to import the PTCColab library
- 1.2 is required to connect to any Onshape connection with PTCColab.
- 1.7 is required to connect to any Thingworx connection with PTC Colab.
- For any function in PTC Colab, there is probably an optional boolean parameter called "verbose" which will give you more information into the black box. (Although you can see the implementation directly in the PTCColab repository.)
- Happy hacking!
Below are some examples of how the snippets libraries have been used to create simple services or applications with Onshape and ThingWorx. NOTE: You will need to upload your own app keys and document parameters to run the example notebooks.
- Click here to see a notebook designed to teach the basics of the math behind transformation matrices with Onshape
- Click here to see a notebook that updates a counter text in Onshape
- Click here to see a notebook that sends information between an Octoprint server running on your local network and ThingWorx.