top of page
Search
Writer's pictureCaden Armstrong

Use Chrome Extensions to Automate Onshape

Officially, there are two ways to automate with Onshape: The API and FeatureScript. Both the API and FeatureScript work extremely well and allow a good deal of innovative ways to achieve automation with Onshape. But despite best efforts, some parts of Onshape just aren't accessible. The FeatureScript notices tab, the measurements window, or even folders in the feature tree. But, I have discovered that a Chrome Extension has the ability to achieve automation never seen before (and very likely not recommend by Onshape)


Chrome extensions are fairly common (especially ones like ad block), but have you ever thought about how they work? Its surprisingly simple. A chrome extension is essentially a web page with access to some browser specific APIs, such as getting information about open tabs, or the current page. The key here is that Chrome gives the option to inject new code into any web page. This is how extensions like the XKCD replacement extension work. A script is injected that looks at the page and modifies the content.


So how can we use this to help automate Onshape?


Chrome extensions give two possibilities within Onshape: extracting data from the page, or add new elements to the page.


Extracting data from an Onshape page is both fairly easy, and very hard. Getting visible data is fairly trivial, the challenge comes when the data isn't visible. This was a challenge that I faced when I created my first chrome extension for extracting the FeatureScript notices tab data. When the FeatureScript notices tab is open, its easy to grab that data and save it out as a txt file. But what if the user does not have the tab open? If the tab isn't open, Onshape does not load that data anywhere. It only gets loaded when the tab is open. The solution was to first check if the tab was open, and then programmatically click the FeatureScript notices tab to open it, extracting the data, and then clicking it again to close the tab. This all happens so fast that the user has no idea the tab was even opened.


Extracting data is an obvious solution, but what about adding new elements to the Onshape page? Adding new buttons and menus is a fairly common possibility in a desktop CAD, but is a bit more limited in Onshape. Integrated applications have a list of options where new buttons/tabs can be added. In short, its mostly limited to right click context menus, and the right panel in a design studio. This makes sense from a technical standpoint, but limits options forcing all automation into a few contexts. But with a Chrome Extension, we can insert new buttons, text, graphics, anywhere in the Onshape page. This allows us to add automation into a context that makes sense. Take for example a button that would export all of the comments on a document. The most logical place to put that button is in the comments area of Onshape. With a Chrome Extension, we could detect the comment tab being opened, and add a new button that would perform that export action. The options for adding to Onshape are only limited by your imagination.




One last interesting point about using Chrome Extensions with Onshape is about using the API. Typically for an Onshape integrated application, the app needs to go through the Onshape Authentication process in order to access the API. This is good security and expected behaviour. The interesting difference for a Chrome extension is that the code is being injected into the Onshape page. If an API request is done with injected code, it utilizes the existing authentication. This means that a chrome extension skips the need of API keys, or going through OAuth. The extra fun part, is that Onshape is the origin of the requests, which actually gives us access to internal only APIs that are otherwise not publicly accessible.


What are the downsides to using a Chrome Extension? Well, there are plenty. Firstly, it does add some IT overhead and challenges. What's great about Onshape is that there is no installation or deployment. Onboarding new Onshape users is a breeze. Adding a custom Chrome Extension into the mix requires installing on every users computer, and then keeping them up to date when changes are made.


The next downside is stability. Any changes made to Onshape could result in the extension breaking. Typically FeatureScript and the API are backwards compatible, maintained in a way that does not break existing applications. Using a very unofficial method is sure to not be maintained or supported by Onshape, resulting in some headaches long term.


Lastly, complexity. Some automations, such as adding a new button, or reading the FeatureScript notices, is fairly simple. On the other hand a lot of automation ideas turn out to be incredibly complicated. The time required to develop an automation with a Chrome Extension might exceed the value provided by the extension. This is a very new idea, and is extremely experimental. Proceed with caution.

111 views0 comments

Recent Posts

See All

Comments


bottom of page