• Home
  • Products
  • Blog
  • Contact
  • About
  • Future Products
  • Cadquery
Parametric Products, LLC Store

blog

Working faster in Onshape with FeatureScript add-ins

6/5/2016

 
As an Onshape user, sometimes I find that things should just be a little easier. It's not that the core product cannot work-- it just takes more steps than I want.

A good example is creating a sphere. That should be pretty easy right?   Surprisingly, creating a sphere is missing in Onshape.  You can do it using these steps:
  1. Create a sketch
  2. Draw a center line
  3. Draw a half circle
  4. Add a dimension
  5. Revolve the sketch

It's not difficult, but if you add lots of little examples like this up, it ends up taking longer to draw something than I'd like.

All is not lost. An Onshape tool called Featurescript has recently been released, that we can use to fill the gaps. Using Featurescript, it is possible to create an addin that provides the one-step sphere I'd like.

Making a sphere add-in
When finished it should  look like this:
Picture
I'd like to provide a vertex and a radius as input (2).  And, I'd like it available on my toolbar for quick access (1).  

How do you do it? Turns out, its not very difficult. First, create a new feature:
Picture
Next,  change the template for our needs:
Picture
We've modified the template as follows:
  1. We've just modified the auto-generated code to name this a Sphere.
  2. Accept a vertex as input. This will be the center of the sphere.
  3. A radius
  4. call a function called makeSphere that actually creates the sphere. 

But what about this makeSphere function?  Here, we need  to write the code that makes a sphere. It is simply the code version of what you would do by hand.   It ends up being about 25 lines of code:
Picture
The steps are as follows:
  1. create a sketch
  2. create a semi-circular shape
  3. draw a rotation axis
  4.  revolve the sketch around the axis
  5. delete the sketch so it doesn't clutter the work space.

Once this is saved, you can use this feature from Part Studios inside of your Onshape document. First, create a sketch, and put a vertex somewhere.  Then, select the vertex and use the feature selector to choose your new feature:
Picture

Now you should be able to use the new sphere function.   But what about that last little bit:  adding it to your toolbar?  

​To do that, you first need to create a version (1),  and then add this feature to your toolbar (2).
Picture

​You can name the version anything you want.  Onshape requires that you use a version when you add the feature to your toolbar, you select which version you want. That way, you can change the feature and not worry about breaking older documents.

If you already have an Onshape account, you can see the full example we've worked through here:

If you would like to create spheres in your own projects, don't use this demo project, though.  There is a better version of the sphere feature in our  Torus, Sphere, and Dome feature for Onshape , which allows you to select multiple vertices to create multiple spheres at once.   You an use it for free, to save the effort of creating it yourself.

Other things that should be easier

There are several other things we wish were easier in Onshape too, like:
  1. Create planes a lot more easily, especially tangent planes on surfaces
  2. Create 3D points from imported text
  3. Create multiple offset or midplanes in one step
  4. Create washers in one step

We've created features that implement these as well, and we'll blog about these more in the future.  If you are interested in trying them out they are all available for free in our online catalog.


Comments are closed.

    Dave Cowden

    Developer and owner of Parametric Products, LLC

    Archives

    July 2016
    June 2016
    May 2016

    Categories

    All
    Features

    RSS Feed

Copyright (c) 2016 Parametric Products, LLC. All rights reserved.
  • Home
  • Products
  • Blog
  • Contact
  • About
  • Future Products
  • Cadquery