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.

Options

Modeling a Square Tube in different ways to lear featurescript

emerson_botteroemerson_bottero Member, Developers Posts: 37 ✭✭
I think is the best when you can get something done in more than one way and feature script allows that. I don't mean to find the easy way, I want to learn from it.

1 - Create 2 square sketchs, Extrude both, remove the smaller from the biggest with Boolean. That one was easy!

--> Create 2 Sketchs
          skRegularPolygon(sketch1, "polygon1", {
                    "center" : vector(0, 0) * inch,
                    "firstVertex" : vector(1/2,1/2) * mysize,
                    "sides" : 4
            });   
            
            skRegularPolygon(sketch2, "polygon2", {
                    "center" : vector(0, 0) * inch,
                    "firstVertex" : vector(1/2,1/2) * (mysize - mythick),
                    "sides" : 4
            });

--> Extrude Both

             extrude(context, id + "extrude1", {
                "entities" : qSketchRegion(id + "sketch1"),
                "endBound" : BoundingType.BLIND,
                "depth" : definition.myLength
            })

            extrude(context, id + "extrude2", {
                "entities" : qSketchRegion(id + "sketch2"),
                "endBound" : BoundingType.BLIND,
                "depth" : definition.myLength
            });
            
--> Booleans           
            opBoolean(context, id + "boolean1", {
                  "tools" : qCreatedBy(id + "extrude2", EntityType.BODY),
                  "targets" : qCreatedBy(id + "extrude1", EntityType.BODY),
                  "operationType" : BooleanOperationType.SUBTRACTION
            });
            
            opDeleteBodies(context, id + "delete1", {
                  "entities" : qCreatedBy(id + "sketch1", EntityType.BODY)
            });
            
            opDeleteBodies(context, id + "delete2", {
                  "entities" : qCreatedBy(id + "sketch2", EntityType.BODY)
            });


2 - Create 2 square sketchs, extrude the region in between. Couldn't query this region :(

3 - Create a sketch, extrude as surface, Thicken the surfaces. Couldn't Extrude as surface

--> Create a Sketch
          skRegularPolygon(sketch1, "polygon1", {
                    "center" : vector(0, 0) * inch,
                    "firstVertex" : vector(1/2,1/2) * mysize,
                    "sides" : 4
            });   
--> Extrude as Surface gives me this ERROR "
throw EXTRUDE_NO_DIRECTION"

          extrude(context, id + "extrude1", {
                "bodyType": ToolBodyType.SURFACE,
                "entities" : qSketchRegion(id + "sketch1"),
                "surfaceEntities" : qCreatedBy(id + "sketch1"),
                //"direction" : evOwnerSketchPlane(context, {"entity" : qSketchRegion(id +  "sketch1")}).normal, 
                "depth" : definition.myLength,
                
        });

--> Thicken the surfaces (couldn't test)

         opThicken(context, id + "thicken1", {
                    "entities" : qCreatedBy(id + "extrude1", EntityType.BODY),
                    "thickness1" : 0.1 * inch,
                    "thickness2" : 0.1 * inch
            });

Can Someone show how to make options 2 and 3 possible? :dizzy:

Comments

  • Options
    lanalana Onshape Employees Posts: 693
    2. - put both squares into the same sketch, pass "entities" : qSketchRegion (id + "sketch1", true)  to extrude - that would filter out the inner region.
    3. - pass 
     "surfaceEntities" :  qCreatedBy(id + "sketch1", EntityType.EDGE) , no need for "entities" field to extrude.

    We recommend using opExtrude in feature script instead of extrude for better performance. 
  • Options
    emerson_botteroemerson_bottero Member, Developers Posts: 37 ✭✭
    Ok. First 15 min to respond !  :D. You Rock.

    2 - you nail it. I'm using opExtrude.

    3 - using extrude because didn't found BodyType option in opExtrude.
    extrude(context, id + "extrude1", {
                    "bodyType": ToolBodyType.SURFACE,                
                    "surfaceEntities" : qCreatedBy(id + "sketch1", EntityType.EDGE),
                    "endBound" : BoundingType.BLIND,
                    "depth" : definition.myLength
                });

    Didn't work and I could'n find why, I still get EXTRUDE_INVALID_ENTITIES. But
     
     extrude(context, id + "extrude1", {
                    "bodyType": ToolBodyType.SURFACE,                
                    "surfaceEntities" : qCreatedBy(id + "sketch1", EntityType.FACE),
                    "endBound" : BoundingType.BLIND,
                    "depth" : definition.myLength
                });
    Worked but it forms an SOLID, not SURFACE Body, I debug the query and both are working.
  • Options
    Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @emerson_bottero

    opExtrude doesn't need BodyType option.  If you pass it edges in the "entities" field, it will make surfaces:
    https://cad.onshape.com/FsDoc/library.html#opExtrude-Context-Id-map

    If you post the URL of your document here, we'll be happy to take a look at why that extrude() is failing.
    Jake Rosenfeld - Modeling Team
  • Options
    emerson_botteroemerson_bottero Member, Developers Posts: 37 ✭✭
    @Jake_Rosenfeld

    here it is.
    https://cad.onshape.com/documents/04194902b685ea2fdd1ea39e/w/d56fefaa6afcbf2753009eeb/e/4fc1173c8bd6628cd5713f2e

    I did what I never saw in the documentation but I use ons sub-node of the LookupTable as valuewithunits, works as long as the entry has units in it. :)
  • Options
    Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    Hi @emerson_bottero

    You have it pinned down when you ask "Shouldn't this be 4 edges, not 8?"  Due to the way our sketching system works, there are actually two sets of edges created when you sketch: the wire bodies that you directly create in your sketching operations, and the edges around the sketch regions that you create indirectly.

    Long story short, the query that you want is:
    qOwnedByBody(qBodyType(qCreatedBy(id + "sketch1", EntityType.BODY), BodyType.WIRE), EntityType.EDGE);
    a.k.a. "All the edges of wire bodies created by the sketch operation"
    Jake Rosenfeld - Modeling Team
  • Options
    emerson_botteroemerson_bottero Member, Developers Posts: 37 ✭✭
    edited February 2018
    thanks @Jake_Rosenfeld That's really complicated. Can I create a function or my on query for reuse in the rest of the code?

    edit1: I did this and it worked.

    <div>function QSketchEdges(id is Id)</div><div>{</div><div>&nbsp; &nbsp; return qOwnedByBody(qBodyType(qCreatedBy(id, EntityType.BODY), BodyType.WIRE), EntityType.EDGE);</div><div>}</div>


    and used like that.
    <br><div>opExtrude(context, id + "extrude1", {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "entities" :&nbsp; QSketchEdges(id + "sketch1"),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "direction" : evOwnerSketchPlane(context, {"entity" : qSketchRegion(id + "sketch1")}).normal,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "endBound" : BoundingType.BLIND,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "endDepth" : definition.myLength&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; });</div><p></p>


  • Options
    Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @emerson_bottero

    A correction from my coworker: qBodyType actually happily filters entities based on the body type of their owner, so a simpler Query is:
    qBodyType(qCreatedBy(id + "sketch1", EntityType.EDGE), BodyType.WIRE);

    Nice function!
    Jake Rosenfeld - Modeling Team
Sign In or Register to comment.