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

Is there an API endpoint for checking interference between two parts?

I am using onshape through API request and I have a question regarding Interence check functionality. 

For UI, we have interence check option in both Assembly studio and Part studio, but I cannot find the enpoint that does the same functionality. 

Can someone help me to locate the endpoint that checks the interence of two parts? 


Thanks in advance.

Answers

  • Options
    MichaelPascoeMichaelPascoe Member Posts: 1,718 PRO
    edited December 2022

    I'm not sure this is possible. @caden_armstrong will know.

    The only way I know of currently is to use a custom feature like this: 
    https://forum.onshape.com/discussion/comment/45646/#Comment_45646


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • Options
    caden_armstrongcaden_armstrong Member, User Group Leader Posts: 127 ✭✭✭
    Michael is correct, there is no API end point for the interference check.
    You can do it with a featurescript and call the featurescript via the API, but this only works inside of a part studio.
  • Options
    md_al_mamun316md_al_mamun316 Member Posts: 13 EDU
    @caden_armstrong

    Thanks for the answer. I still have follow-up questions.

    • I have to use featurescript POST endpoint. Right? 
    • If I look at the request body, it is not clear to me. Can you explain me how I should send the request?  Should I fill the part_ids in "additionalProp1" field as a list? Below I included the request body. 
    • If I look at the response as well, I also don't know which parameter is indicating interference. Can you point-out parameter indicating interfence in the response? 
    Thanks a lot.

    }
    { "libraryVersion": 0, "microversionSkew": true, "queries": { "additionalProp1": [ "string" ], "additionalProp2": [ "string" ], "additionalProp3": [ "string" ] }, "rejectMicroversionSkew": true, "script": "string", "serializationVersion": "string", "sourceMicroversion": "string"
  • Options
    md_al_mamun316md_al_mamun316 Member Posts: 13 EDU
    edited December 2022
    @caden_armstrong @MichaelPascoe

    I am new to onshape and still learning a lot. I think you can ingnore my previous question as I have undestood Feature Script and Feature Studio. First I need to create a featurescript that checks the interference of given two parts then make API call to the featurescript. That is clear.

    However, I still have one problem.

    I have tried to create my featurescript for interference check but I am stuck after I got the part Ids as a precondition. There is interference function but I don't know how to use it. I hope you can help me on this one. Thanks in advance.

    You can see my featurescript below: 

    FeatureScript 1913;
    import(path : "onshape/std/geometry.fs", version : "1913.0");

    annotation { "Feature Type Name" : "Interference" }
    export const interference = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
    annotation { "Name" : "part1_id", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 1 }
    definition.part1_id is Query;
    annotation { "Name" : "part2_id", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 1 }
    definition.part2_id is Query;
    }
    {
    interference(context, id, definition);
    });
  • Options
    MichaelPascoeMichaelPascoe Member Posts: 1,718 PRO
    edited December 2022

    I'm not sure interference() is an op that is available. In your code you are trying to call your own feature into it's own definition. This course should get you started with FeatureScript: Learning Center - FeatureScript

    Try evCollision() instead of interference().

    evCollision(context, {
                    "tools" : tools,
                    "targets" : targets
            });

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • Options
    md_al_mamun316md_al_mamun316 Member Posts: 13 EDU
    edited December 2022
    Thanks for your reply. 

    My custom Collision feature works on UI. Here is the script:

    annotation { "Feature Type Name" : "Collision" }
    export const collisionFeature = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
    // Define the parameters of the feature type
    annotation { "Name" : "part1", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 1 }
    definition.part1 is Query;

    annotation { "Name" : "part2", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 1 }
    definition.part2 is Query;
    }
    {
    // Define the function's action
    var arrs = evCollision(context, { "tools" : definition.part1, "targets" : definition.part2 }); var count = 0; for (var ar in arrs) { if (ar['type'] == ClashType.INTERFERE) { count = count + 1; } } return count;
    });
    It works as I have checked it with script notices. 

    Now, my real question was to do it through API calls. I am testing it on API explorer (https://cad.onshape.com/glassworks/explorer#/ ). Here is request body that I am sending for featurescript POST endpoint:

    {
      "queries": {"part1": ["JFD"], "part2": ["JFL"]},
      "script": "function (context is Context, definition is map) { var arrs = evCollision(context,{tools: definition.part1, targets: definition.part2}); var count = 0; for(var ar in arrs){if(ar['type'] == ClashType.INTERFERE){count = count + 1;}}return count;}"
    }
    This also works as I get the following response:
    {
      "btType": "BTFeatureScriptEvalResponse-1859",
      "result": {
        "btType": "com.belmonttech.serialize.fsvalue.BTFSValueNumber",
        "value": 14,
        "typeTag": ""
      },
      "console": "",
      "notices": [],
      "libraryVersion": 1930,
      "serializationVersion": "1.1.23",
      "rejectMicroversionSkew": false,
      "microversionSkew": false,
      "sourceMicroversion": ""
    }
    However, when I do it using onshape_client package on Python it doesn't work. Here is my code:
    body = {
    "queries": {"part1": ["JFD"], "part2": ["JFL"]},
    "script": "function (context is Context, definition is map) { var arrs = evCollision(context,{tools: definition.part1, targets: definition.part2}); var count = 0; for(var ar in arrs){if(ar['type'] == ClashType.INTERFERE){count = count + 1;}}return count;}"
    }

    response = client.part_studios_api.eval_feature_script(did=document.id,
    wvm=document.w_or_v,
    wvmid=document.workspace_id,
    eid=document.element_id,
    bt_feature_script_eval_call_2377=body,
    _preload_content=False)
    I got the following error:

    {\n  "message" : "Error processing json",\n  "moreInfoUrl" : "",\n  "status" : 400,\n  "code" : 0\n}

    Can you help me on this? @caden_armstrong @MichaelPascoe
  • Options
    MichaelPascoeMichaelPascoe Member Posts: 1,718 PRO

    I'm not sure on this one.


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • Options
    md_al_mamun316md_al_mamun316 Member Posts: 13 EDU
    @MichaelPascoe can you suggest someone who can help?  
  • Options
    MichaelPascoeMichaelPascoe Member Posts: 1,718 PRO
    edited December 2022

    Caden is the best API guy I know. I stick to FeatureScript. If you are setting this up for your company, then I suggest having CADSharp do it. If this is for research or a personal project, try the resource below.

    Here is a neat API resource I noticed the other day: https://forum.onshape.com/discussion/19547/app-to-help-with-app-development#latest
    Sounds like it will be perfect for what you are trying to do. Contact @Aaron_Magnin to get in on the beta.


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • Options
    Aaron_MagninAaron_Magnin Member, Onshape Employees Posts: 114
    Thanks for plugging that, @MichaelPascoe! I think it'll be released very soon...once it does, I'll try to update this conversation. 
  • Options
    md_al_mamun316md_al_mamun316 Member Posts: 13 EDU
    @MichaelPascoe

    Thanks for the information. 
Sign In or Register to comment.