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.

help using opBoolean

papawopapawo Member, Developers Posts: 206 PRO
where should i put the opBoolean so it subtract everytime it extrude?
----------------------
var i = 0;
        for (var vertex in evaluateQuery(context, definition.locationsAH))
        {
            var point is Vector = evVertexPoint(context, {
                    "vertex" : vertex
            });
            var sketchNormal is Vector = evOwnerSketchPlane(context, {
                    "entity" : vertex
            }).normal;
            var sketchPlane is Plane = plane(point, sketchNormal);
            
            var sketch = newSketchOnPlane(context, id + ("sketch" ~ i), {
                    "sketchPlane" : sketchPlane
            });
            skCircle(sketch, "circle", {
                    "center" : vector(0, 0) * inch,
                    "radius" : .25 * inch
            });
            skSolve(sketch);
            
         
            opExtrude(context, id + "extrude1"+i, {
                    "entities" :qSketchRegion(id + ("sketch" ~ i), true),
                    "direction" : evOwnerSketchPlane(context, {"entity" : definition.locationsAH}).normal,
                    "endBound" : BoundingType.BLIND,
                    "endDepth" : 100 * inch
            });
          
                
            opBoolean(context, id + "boolean1"+i, {
              "tools" : qCreatedBy(id + "extrude1"+i, EntityType.BODY),
              "targets":definition.partToCutAH,
              "operationType" : BooleanOperationType.SUBTRACTION
            });
         
           i += 1;  
      
          
        }    

Comments

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,216
    It would be easier for us to help if you posted a link to the full code and the error you're getting, but from what I'm seeing above, I am guessing you're running into an id gotcha (for which we've been meaning to report a more helpful error for a long time).  The issue is that you're doing operations as id+"extrude"+i and id+"boolean"+i.  So in the for loop, you get the following sequence:
    id+"extrude1"+0
    id+"boolean1"+0
    id+"extrude1"+1
    id+"boolean1"+1
    ...
    And the problem is that the id+"extrude1"+1 can't be used because the id+"extrude1" portion of the hierarchy has been closed.  The fixed is to do id+i+"extrude1" and id+i+"boolean1" instead.  That way the sequence is
    id+0+"extrude1"
    id+0+"boolean1"
    id+1+"extrude1"
    id+1+"boolean1"
    ...
    and everything is happy.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • papawopapawo Member, Developers Posts: 206 PRO
    i am indeed so happy ! ... thank you!   :)
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Some more info on this is available in the Id's type documentation.
Sign In or Register to comment.