Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:

  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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.

Stopping short with an Extrude Up_To_Surface

daniel_splawskidaniel_splawski Member Posts: 66 ✭✭
I'm working on a feature which will remove material from a model to make a poor man's linear bearing for 3d printed parts.  I've managed to construct half of the feature properly, however I'm having trouble removing some additional material from the inside of the hole to reduce friction.  In the model attached below (V1) I'm trying to remove the material which is removed by Extrude 2.  

If I want to leave 5mm of bearing surface adjacent to either face of the part, what would be the most elegant way to accomplish that task using feature script?  Force the user to select the faces and use and use and do the math perhaps?   

https://cad.onshape.com/documents/19e92e1f4787384f63407015/w/7149ceba90a47ea8b5f4db99/e/376b383db7dd5a4d32bb3014
Tagged:

Comments

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 450
    Hi Daniel,

    To calculate the bounds of a part, you can use evBox3d. This will give you a bounding box (Relative to the coordinate system of your choosing), and you can use the edge of that bounding box to figure out how far you need to extrude.

    So the relevant code would look something like this:

    // z-coordinate of the far edge of the targetBody bounding box, measured from the sketch plane
    var endDistance = evBox3d(context, { "topology" : definition.targetBody, "cSys" : planeToCSys(sketchPlane) }).maxCorner[2]; const edgeThickness = 5 * millimeter; // or whatever opExtrude(context, id + "extrude2", { "entities" : qSketchRegion(id + "sketch2"), "direction" : sketchPlane.normal, "startBound" : BoundingType.BLIND, "startDepth" : -edgeThickness, // Negative because opExtrude assumes startBound is backwards "endBound" : BoundingType.BLIND, "endDepth" : endDistance - edgeThickness }); opBoolean(context, id + "boolean1", { "tools" : qCreatedBy(id + "extrude2", EntityType.BODY), "targets" : definition.targetBody, "operationType" : BooleanOperationType.SUBTRACTION });
    I've added this code to my own copy of your document (and touched up a few other things).
    https://cad.onshape.com/documents/5762ead8e4b06a2590f00f74/w/393d106f583dbefce85ae57a/e/866fd9a31820bb0918cecbfc

    I hope the new version works for you! 


    Best,
    Kevin
  • daniel_splawskidaniel_splawski Member Posts: 66 ✭✭
    Thank you so much, this looks excellent.  I put the code through a diff checker to see what the few touch ups were and it all makes sense, more or less.  One question, what's the benefit of the opBoolean>subtraction as opposed to extrude>"operationType" : NewBodyOperationType.REMOVE? :smile:

    Thanks again. 
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 450
    edited June 2016
    Great question.

    extrude() is a feature which calls opExtrude() and opBoolean(). In practice, you can call either from FeatureScript, but often the interface of the feature tends to be designed for end users more than developers. In this case, I just didn't want to figure out how the e.g. the secondDirectionOppositeDirection flag needed to be set in code, so I just called opExtrude which allows a negative depth. While writing the feature it also allowed me to add a debug() entities before the opBoolean() to see exactly what I was subtracting before subtracting it.

    If I fiddled with it, calling extrude would have been possible (proof: your original example called extrude() within the Part Studio). It's just a matter of your preference and the situation at hand.

Sign In or Register to comment.