Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Custom feature script for 2 extrudes
KyleDarnell
Member Posts: 10 PRO
I would like to make a feature script that will make 2 extrudes. I do this exact same action very often and I would like to make this automated. Regarding FeatureScript I am still relatively new (I have made a few featurescipts for variable lists), so I wanted to ask what I would need to do to make these actions happen. Here is a link to a document with the task I will be wanting to make into a FeatureScript. It will be in the folder named "FEAURE SCRIPT?"
Thank you
Thank you
0
Best Answer
-
MichaelPascoe Member Posts: 1,994 PRO@KyleDarnell Welcome to FeatureScript!
Here are the general steps you will need to be able to do this:
https://cad.onshape.com/documents/82e1c77948a53493dda93e14/w/903175619ca8b00048792ef7/e/313a6c018bed8f931e1776a2annotation { "Feature Type Name" : "Edge Prep" } export const edgePrep = defineFeature(function(context is Context, id is Id, definition is map) precondition { // Define the parameters of the feature type // This is where your user interface goes annotation { "Name" : "Face", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 } definition.face is Query; } { // Define the function's action // Create a plane at the top right corner of the selected face const facePlane = evFaceTangentPlane(context, { "face" : definition.face, "parameter" : vector(1, 1) //This means that the plane will be at the top right corner 0,0 is the bottom left }); // Create a plane on the right side const sidePlane = plane(facePlane.origin, facePlane.x, -facePlane.normal); // Debug shows you items in the graphics area or in the monitor debug(context, facePlane, DebugColor.BLUE); debug(context, sidePlane, DebugColor.RED); // Sketch on the "frontPlane" var faceSketch = newSketchOnPlane(context, id + "sketchFacePlane", { "sketchPlane" : facePlane }); skCircle(faceSketch, "circle1", { "center" : vector(0, 0) * inch, "radius" : 1 * inch }); skSolve(faceSketch); // Find the sketch region from the sketch const faceSketchToExtrude = qSketchRegion(id + "sketchFacePlane"); // Extrude the sketch opExtrude(context, id + "extrudeFaceSketch", { "entities" : faceSketchToExtrude, "direction" : -facePlane.normal, "endBound" : BoundingType.BLIND, "endDepth" : 0.25 * inch }); // Find the extruded part const extrudedParts = qCreatedBy(id + "extrudeFaceSketch", EntityType.BODY); // Subtract parts opBoolean(context, id + "booleanRemoveFrontParts", { "tools" : extrudedParts, "targets" : qOwnerBody(definition.face), "operationType" : BooleanOperationType.SUBTRACTION }); });
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴0
Answers
https://cad.onshape.com/documents/95c00401c440b44ad8799ef5/v/3048d5049faa1f7427c2ed5c/e/f59ee8c28530122eb7fa9f5c
which lets you specify different extrude details for different selections. If you're set on making your own tool, however, I think most of the concepts from the 90sec FS tutorial on https://cad.onshape.com/FsDoc/ should be applicable. For getting the UI to look and operate like the official Extrude feature, you can heavily reference how other custom features achieve things you want, and port over applicable code.
Else, can you share a simple example of what this feature would do that you'd normally do with multiple features?
If you do want to write a custom feature, a great way to start is by copying our Extrude feature from here into a Feature Studio and modifying it as needed.
Here are the general steps you will need to be able to do this:
https://cad.onshape.com/documents/82e1c77948a53493dda93e14/w/903175619ca8b00048792ef7/e/313a6c018bed8f931e1776a2
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Anyway, the other challenge is to make the user input only the bare minimum and use the programming to infer the rest of it. I experimented with this UI:
and still have it work well enough (NOTE: I only hacked this up quickly and so far it only treats one end of the slot... still needs more work!) It could be done many ways, but I like mate connectors!