Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape, CAD, maker project and design.

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.

Find point(s) of intersection between spline and body

ray_heasmanray_heasman Member Posts: 6
( I accidentally asked this in the Community Support forum, at first. Sorry. :-/ )

Hi,

I'm trying to write a tool to help me add cables, wires, tubes, etc. to a current project.

This is my first featurescript so I am also using this problem to learn about featurescript.

I am trying to find the point at which a spline enters a body. I construct the spline, and then use evCollision to find collisions. evCollision successfully finds the collision and reports the face being collided with, and my spline.

For simplicity for now, let's assume that the intersection is always a face. I want to extract the 3D co-ordinates of the collision.

I was hoping to do the following:
  1. Create a sketch on the face.
  2. Add a point to the sketch.
  3. Set a ConstraintType.PIERCE between the spline and the point on the sketch.
  4. Solve the sketch.
  5. Extract the co-ordinates of the point on the sketch and map them to world space.
  6. Destroy the sketch.
  7. Use the co-ordinates I extracted.
That seems like the long way around to just get the point of intersection. Please let me know if there is a better way. I just want the first point of intersection on the spline, or every point of intersection on the spline, with any other bodies.

Anyway, the problem right now, is that skContraint is not documented. There is some token documentation, but it doesn't tell you what fields to set to get the results you want. Looking at the standard library only shows how to use a subset of the constraints.

So, I can't figure out how to set a PIERCE constraint.

Can someone tell me how to set a PIERCE constraint, or perhaps show a better way to extract the intersection point(s) I am looking for?

Thanks.


Best Answer

  • ray_heasmanray_heasman Member Posts: 6
    Accepted Answer
    NeilCooke said:
    evDistance().sides[0].point should do it
    evDistance works, thanks. However, I am trying to edit a part "In Context", and I can't seem to detect collisions with the other parts in the context. Is there a way?

Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 300 ✭✭✭
    as soon as opBooleand doesn't support wire bodies i would try iterating along the spline and evaluating distance from point with coordinates evEdgeCurvature().frame.origin to the selected entity. when distance will be zero+/-tolerance you will get the coordinates of piercing point
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 968
    evDistance().sides[0].point should do it
    Neil Cooke, Director of Technical Marketing, Onshape Inc.
  • ray_heasmanray_heasman Member Posts: 6
    Accepted Answer
    NeilCooke said:
    evDistance().sides[0].point should do it
    evDistance works, thanks. However, I am trying to edit a part "In Context", and I can't seem to detect collisions with the other parts in the context. Is there a way?
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 968
    Have you already manually included the part/face in the (assembly) context? If not then the part does not know about it. I have not tested this but once a body or face has been added it should behave like any other part/face (I could be wrong). 
    Neil Cooke, Director of Technical Marketing, Onshape Inc.
  • ray_heasmanray_heasman Member Posts: 6
    I haven't because I'm not sure how I would do that. I loaded an assembly with several parts, then I clicked "Create part studio in context", then created some test cubes and such. I find your suggestion works perfectly for the test cubes, but it doesn't pick up interference between splines and the other parts in the assembly.

    The idea is that I load in a complete assembly with lots of parts (over 700), as a step file. Then I create a part studio in context, and model a new part that that is all the wiring and tubing etc, then export it later so other people I am working with can include it as a dumb part into their assembly, and it will have static geometry in that part that represents all the tubing and wiring.

    Thanks for your help so far. I much appreciate it.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 968
    You could force the assembly context by copying the selected faces into your feature, something like this:
    FeatureScript 581;
    import(path : "onshape/std/geometry.fs", version : "581.0");
    
    annotation { "Feature Type Name" : "Force Refs" }
    export const ForceRefs = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Ref faces", "Filter" : EntityType.FACE }
            definition.faces is Query;
        }
        {
            opExtractSurface(context, id, { "faces" : definition.faces, "offset" : 0 * meter });
            
            debug(context, qCreatedBy((id), EntityType.BODY));
        });


    Neil Cooke, Director of Technical Marketing, Onshape Inc.
  • ray_heasmanray_heasman Member Posts: 6
    edited May 18
    Hm, thanks. I would have to extract every surface in the context, because the point is to programmatically find interference, not depend on manual input.

    Now I know about extract, perhaps I can find a better way...
  • ray_heasmanray_heasman Member Posts: 6
    NeilCooke said:
    You could force the assembly context by copying the selected faces into your feature, something like this:
    FeatureScript 581;
    import(path : "onshape/std/geometry.fs", version : "581.0");
    
    annotation { "Feature Type Name" : "Force Refs" }
    export const ForceRefs = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Ref faces", "Filter" : EntityType.FACE }
            definition.faces is Query;
        }
        {
            opExtractSurface(context, id, { "faces" : definition.faces, "offset" : 0 * meter });
            
            debug(context, qCreatedBy((id), EntityType.BODY));
        });


    Just FYI, opExtractSurface() is undocumented.
  • ray_heasmanray_heasman Member Posts: 6
    Actually, I seem to have discovered a bug. If no bodies are created in the part studio, then collision detection with the hosted context works like a charm. The instant I create something in the part studio context (in code or manually), the evCollision() only sees parts in the studio, and ignores anything from the hosted context.

    Interestingly, if I add a query parameter to select a face, selecting that face makes it possible for the evCollision to see it, even if I do nothing else (no extractSurface or whatever).

    It's starting to look like a chosen behaviour, but it's still not one useful to me.

    I'll figure out how to post a bug report.
Sign In or Register to comment.