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.

Getting sketches 3 characters geometryIds through API

guillauem_dguillauem_d Member Posts: 16
Hello !  :D

I'm trying to create circular holes on my part using the API.
To do this, i first created the sketch then the extrusion manually and analyzed extrusion .json using feature list : 

 {
        "type": 148,
        "typeName": "BTMParameterQueryList",
        "message": {
          "queries": [
            {
              "type": 138,
              "typeName": "BTMIndividualQuery",
              "message": {
                "geometryIds": ["JRC"],
                "hasUserCode": false,
                "nodeId": "F5vRpYBhnhF3bwB"
              }
            }
          ],
          "parameterId": "entities",
          "hasUserCode": false,
          "nodeId": "e/OW31rYeHDO6RYo"
        }
    },

I'm guessing "geometryIds": ["JRC"] is the id of the sketch that is being extruded.

Now i'd like to do this programmatically but i don't know how to find the sketch geometryIds, the only thing I find when creating a circular sketch through the API is '"entityId" : "jpUy8ZpUH4Uy", I tried using this as a geometryIds but it doesn't work.

How am I suppoed to find this the sketches 3 characters geometryIds ?

Thank you in advance !  :)

Answers

  • Caden_ArmstrongCaden_Armstrong Member Posts: 180 PRO
    There's a couple options.
    You could do it differently and just make a query for your sketch and pass that into the extrude feature without needing to know the geometry IDs. It's not super well documented on how to do that.

    Or you could get the geometry IDs and mimic how Onshape does it.
    You'll need to use the evaluateFeaturescript endpoint to run some featurescript in order to get the query and then the transient Id of the faces and edge.

    But the more important question, why are you using the API to put holes in a part. That sounds like something better suited for featurescript. Featurescript is great at modifying geometry. 
    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • guillauem_dguillauem_d Member Posts: 16
    thank you for your answer  :)

    I could learn featurescript, but I need to execute the command remotely trough API calls, and if i'm not mistaken, I can't execute featurescript through API calls ?

    For instance, I learned how to make a simple extruded square : 

    FeatureScript 1821;

    import(path : "onshape/std/geometry.fs", version : "1821.0");

    annotation { "Feature Type Name" : "My Feature", "Feature Type Description" : "" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            // Define the parameters of the feature type

            annotation { "Name" : "Length",
                        "UIHint" : [UIHint.SHOW_LABEL, UIHint.REMEMBER_PREVIOUS_VALUE],
                        "Description" : "Set the length of the solid" }
            isLength(definition.length, NONNEGATIVE_LENGTH_BOUNDS);
        }
        {
            // Define the function's action

            var length = definition.length;

            // Create a new sketch on the Top plane
            var sketch1 = newSketch(context, id + "sketch1", {
                    "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
                });

            // Draw a rectangle in the sketch
            skRectangle(sketch1, "rectangle1", {
                        "firstCorner" : vector(-length / 2, -length / 2),
                        "secondCorner" : vector(length / 2, length / 2)
                    });

            // Solve the sketch
            skSolve(sketch1);

            // Extrude the sketch to create a cube
            opExtrude(context, id + "extrude1", {
                        "entities" : qSketchRegion(id + "sketch1", true),
                        "direction" : evOwnerSketchPlane(context, { "entity" : qSketchRegion(id + "sketch1") }).normal,
                        "endBound" : BoundingType.BLIND,
                        "endDepth" : length
                    });
        });


    This works fine, but it's not possible to execute thise through an API call right ? I tried pasting the code through a POST  /partstudios/d/{did}/{wvm}/{wvmid}/e/{eid}/featurescript  but that doesn't work 
  • Caden_ArmstrongCaden_Armstrong Member Posts: 180 PRO
    You can call arbitrary featurescript code with the /featurescript endpoint, but that cannot change the context or add a feature to the tree.
    Its only used for getting information out of a part studio.

    To modify a part studio with the api you need to add a feature to the feature tree.
    https://cad.onshape.com/glassworks/explorer/#/PartStudio/addPartStudioFeature
    This can either be a custom feature or an onshape built in feature.
    But in this case the feature needs to exist in a feature studio in Onshape.
    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
Sign In or Register to comment.