Determine a solid body that contains an edge

daniel_cravens
daniel_cravens Member Posts: 29 ✭
I would like to create a split normal feature that will splits a body with a normal plane containing an edge. The user selects the edge. I want to find the body that contains the user selected edge. But I can't figure out how to get just the solid body without also picking up the origin planes.

***

annotation { "Feature Type Name" : "Split Normal" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Select edge for split.", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
        definition.edge is Query;
        
    }
    {
        
        var endPoints is Query = qAdjacent(definition.edge, AdjacencyType.VERTEX, EntityType.VERTEX);


        var point1 is Vector = evVertexPoint(context, {
                "vertex" : qNthElement(endPoints, 0)
        });
        var point2 is Vector = evVertexPoint(context, {
                "vertex" : qNthElement(endPoints, 1)
        });

        var body = qIntersection(qEverything(EntityType.BODY)->qContainsPoint(point1),qEverything(EntityType.BODY)->qContainsPoint(point2));
        debug(context,body);
    });


Best Answer

  • daniel_cravens
    daniel_cravens Member Posts: 29 ✭
    Answer ✓
    This is what I ended up using:       
    var body = qBodyType(qEverything(EntityType.BODY), BodyType.SOLID)->qContainsPoint(point1);

    ***

    annotation { "Feature Type Name" : "Split Normal" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Select edge for split.", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
            definition.edge is Query;
            
        }
        {
            
            var endPoints is Query = qAdjacent(definition.edge, AdjacencyType.VERTEX, EntityType.VERTEX);


            var point1 is Vector = evVertexPoint(context, {
                    "vertex" : qNthElement(endPoints, 0)
            });
            var point2 is Vector = evVertexPoint(context, {
                    "vertex" : qNthElement(endPoints, 1)
            });
            
            var midPoint is Vector = point2 - point1;

            var body = qBodyType(qEverything(EntityType.BODY), BodyType.SOLID)->qContainsPoint(point1);
            var face = qOwnedByBody(body, EntityType.FACE)->qContainsPoint(point1)->qContainsPoint(point2);
            
    // Create Plane Normal to Edge

            var tangentLine = evEdgeTangentLine(context, {
                    "edge" : definition.edge,
                    "parameter" : 0.5
            
            });
            
            var tangentPlane = evFaceTangentPlane(context, {
                    "face" : face,
                    "parameter" : vector(0.5, 0.5)
            });
            
            var normal is Vector = cross(tangentPlane.normal,tangentLine.direction);
            
            var plane = opPlane(context, id + "plane1", {
                    "plane" : { "origin" : point1, 
                    "normal" : normal,
                    "x" : tangentLine.direction}
            });
            
            debug(context, plane);

    // Split Body

    /*
            
            opSplitPart(context, id + "splitPart1", {
                    "targets" : body,
                    "tool" : plane
            });
    */
            

Answers

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,126 image
    const body = qOwnerBody(definition.edge);
    Senior Director, Technical Services, EMEA
  • daniel_cravens
    daniel_cravens Member Posts: 29 ✭
    Answer ✓
    This is what I ended up using:       
    var body = qBodyType(qEverything(EntityType.BODY), BodyType.SOLID)->qContainsPoint(point1);

    ***

    annotation { "Feature Type Name" : "Split Normal" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Select edge for split.", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
            definition.edge is Query;
            
        }
        {
            
            var endPoints is Query = qAdjacent(definition.edge, AdjacencyType.VERTEX, EntityType.VERTEX);


            var point1 is Vector = evVertexPoint(context, {
                    "vertex" : qNthElement(endPoints, 0)
            });
            var point2 is Vector = evVertexPoint(context, {
                    "vertex" : qNthElement(endPoints, 1)
            });
            
            var midPoint is Vector = point2 - point1;

            var body = qBodyType(qEverything(EntityType.BODY), BodyType.SOLID)->qContainsPoint(point1);
            var face = qOwnedByBody(body, EntityType.FACE)->qContainsPoint(point1)->qContainsPoint(point2);
            
    // Create Plane Normal to Edge

            var tangentLine = evEdgeTangentLine(context, {
                    "edge" : definition.edge,
                    "parameter" : 0.5
            
            });
            
            var tangentPlane = evFaceTangentPlane(context, {
                    "face" : face,
                    "parameter" : vector(0.5, 0.5)
            });
            
            var normal is Vector = cross(tangentPlane.normal,tangentLine.direction);
            
            var plane = opPlane(context, id + "plane1", {
                    "plane" : { "origin" : point1, 
                    "normal" : normal,
                    "x" : tangentLine.direction}
            });
            
            debug(context, plane);

    // Split Body

    /*
            
            opSplitPart(context, id + "splitPart1", {
                    "targets" : body,
                    "tool" : plane
            });
    */