Have a Question ?
Ask about our products, services, or latest research. Let's discuss how we can help you solve your problem.
Thursday, December 13, 2018
Exploring Onshape FeatureScript
Onshape FeatureScript is a new programming language designed by Onshape for building and working with 3D parametric models. The language is built into Onshape from the ground up, providing the foundation of Part Studio modeling, including robust geometric references, powerful parametric tools, and a type system with types built for math in three dimensions. I got an opportunity to explore Onshape FeatureScript and see what we can do and how it can help us accelerate the design process. This blog is about my experience with FeatureScript and what I have achieved in just 3 days including learning and implementation.
Quote : Onshape FeatureScript documentation
Onshape FeatureScript is a new programming language designed by Onshape for building and working with 3D parametric models. The language is built into Onshape from the ground up, providing the foundation of Part Studio modeling, including robust geometric references, powerful parametric tools, and a type system with types built for math in three dimensions.
The standard feature types in Onshape (like Extrude, Fillet, and Helix) are already written as FeatureScript functions by developers. Custom feature types extend this same mechanism to all users of Onshape.
FeatureScript can be added to any new or existing Onshape document by creating a Feature Studio
So, I thought of exploring Onshape FeatureScript and see what we can do and how it can help us accelerate the design process. This blog is about my experience with FeatureScript and what I have achieved in just 3 days including learning and implementation.
I wanted to create a script for generating 90-degree bevel gear with parameters like module, gear ratio, pressure angle etc. so as to get an on the go experience of FeatureScript in Onshape. So I began working on the app, jotting down the calculations required for the bevel gear. I decided to go with creating the entity by using loft operation to first create a gear base and then again using loft operation to create 1 tooth for the gear over the gear base, then using the circular pattern operation to create the entire teeth set.
This gave me a hands-on experience with the FeatureScript which proved to be a very good experience. The Learning curve for any person familiar with CAD environment and a bit of programming would be very fast. Debugging and rebuilding of model is very quick and it feels amazing sometimes.
My overall experience with the FeatureScript
In my attempt to create the straight bevel gear feature, I found FeatureScript to be very simple and easy to program. It has an elegant way to create Input UI dialog for any feature automatically while programming the feature.
Once I was able to implement basic input UI dialog, from there it was mostly about calculations related to gear standards. This proved to be a little trickier than usual as it took me some time to get used to handling units alongside the values for each variable and calculation. This proved to be an inconvenience initially, as there are multiple calculations required to calculate involute points for the tooth as well as base circle radius. But after some time, I realized that it will help to tackle various issues like incorrect units which we face sometimes in traditional applications.
User and API documentation is good and I was able to find the required API's from the documentation and use it to orchestrate the creation of bevel gear feature. I think next time I would be able to create a new feature in lesser time.
Challenges I faced while trying the Onshape FeatureScript
I am new to FeatureScript and that might be one of the reasons why I faced some of the challenges mentioned here. I am listing out my experiences, but someone who is more familiar, might not find it difficult.
I was trying to use a circular pattern to the teeth and applying fillets on roots. CircularPattern function requires axis as one of the parameter, which I was not able to provide as a vector direction, nor by querying the coordinate system. I even tried creating a line and using it as edge, but it too did not work. I finally obtained a description in the forum where it was suggested to add a spline to the model and then use it as axis. Surprisingly, this too did not work. What worked in the end in conjunction with the spline as axis, was the “equalSpace” option that had to be provided as parameter of the function.
const axis = qCreatedBy(id + "Axis", EntityType.EDGE);
circularPattern(context, id + "gearTeeths", {
  "patternType" : PatternType.PART,
  "entities" : qCreatedBy(id + "loft2", EntityType.BODY),
  "axis" : axis,
  "angle" : 360 * degree,
  "instanceCount" : definition.gearTeeths,
  "equalSpace" : true
});
One more finding which needs to kept in mind is that, acos, atan and other trigonometric functions return results in radians and not degrees, though the documentation mentions otherwise.
My own short summary on how to create FeatureScript
There are dedicated documents about how to create your own FeatureScript. This is my own version based on how I made a custom bevel gear feature using FeatureScript.
Log in to your Onshape account and click on the Insert new element button on the bottom left corner of the screen.
Insert new element - Onshape FeatureScript
Then click on the Create Feature Studio option. A Feature Studio tab will get opened alongside the part studio.
Create Feature Studio - Onshape FeatureScript
Now switch to this Feature Studio tab and click on New Feature on the top left side of the studio.
Add New Feature - Onshape FeatureScript
You will see the scripting page as follows.
Scripting page - Onshape FeatureScript
And voila, you are ready to start scripting. Just select any input parameters your feature will require by choosing from Feature Parameter drop-down and add them to define parameters parentheses
Define parameter - Onshape FeatureScript
Now start using sketch operation and other features by selecting the ones you require from respective dropdowns by adding them to define function action parentheses.
Define function action - Onshape FeatureScript
I have worked on many CAD customization projects, added custom feature in many CAD products. Working on Onshape FeatureScript has given me an unique experience. Its powerful and yet so easy, that someone even without much experience can start creating custom features quickly. I loved everything about this programing language, the syntax, documentation, debugging. I think, it's one-of-its-kind when it comes to adding your own custom features to CAD product. My overall experience has been great and I am going to continue to explore and create more custom features within onshape using FeatureScript.
Onshape FeatureScript for Bevel Gear
This is the FeactureScript I have created to generate a bevel gear design in Onshape. Feel free to download and try this script. Just comment your feedback below, I will be very glad to know what you think about it.
Creating bevel gear with Onshape FeatureScript
About Author
Hrishikesh Thakur
Hrishikesh Thakur is currently working as Sr. Member of Technical Staff at CCTech. He has worked with Autodesk, CoolSim and GE digital product development teams within CCTech. He is an alumnus of SSIPMT with Mechanical Engineering degree along with PG- Diploma in Advanced Computing (PG-DAC) from CDAC Acts Pune. His hobbies include Reading Novels, Chess, Badminton, Table-Tennis, Swimming, Bike Riding, Indian History, etc.
Blog Author - Hrishikesh Thakur
Comments
Like what your are reading ?
Subscribe to our newsletter and get our apps/news updates earlier than others, let's get in touch.