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.

throw Exception error

daniel_cravensdaniel_cravens Member Posts: 29
Hi, I am new to onshape and only a hobbiest. I have solid c# skills but am completely new to feature scripting. 

I am receiving a throw Exception error when I attempt to call my feature "opTrapezoid" from my feature "Dove Tail". The Dove Tail feature is intended to calculated a point along a user-defined edge to draw a trapezoid, and then to sketch a trapezoid by calling the opTrapezoid feature. I'm not sure why I am getting the throw Exception error.

The link to the document is below. I've also pasted in the notices and relevant code.

https://cad.onshape.com/documents/4a05a3fe360ed36e462f3c76/w/88116110cd3e087d5b3fd67f/e/344d30709c1ff4d0a01a8b7e?renderMode=0&uiState=66708736321e044a1143ad8b

Thank you in advance for any help and/or advice.

Notices


throw Execution error
77:21   
onshape/std/feature.fs (defineFeature)
206:13   
Feature Studio 1 (const doveTail)
56:17   
onshape/std/feature.fs (defineFeature)
   
Part Studio 1 (Dove Tail 1)
   
Part Studio 1
@newSketch: Duplicate id in context: FFaX7BXSI6lImH2_1.trapezoid1.sketch1
262:20   
onshape/std/sketch.fs (newSketchOnPlane)
99:28   
Feature Studio 1 (const opTrapezoid)
56:17   
onshape/std/feature.fs (defineFeature)
206:13   
Feature Studio 1 (const doveTail)
56:17   
onshape/std/feature.fs (defineFeature)
   
Part Studio 1 (Dove Tail 1)
   
Part Studio 1
debug: { "tAngle" : ValueWithUnits : { "unit" : UnitSpec : { "radian" : 1 } , "value" : 1.3089969389957472 } , "tBase" : ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0.0105 } , "tDepth" : ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0.008 } , "tHeight" : ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0.016 } , "tOriginPoint" : Vector : [ ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0.05 } , ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0 } , ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0.01666666666666667 } ] } debug: { "tAngle" : ValueWithUnits : { "unit" : UnitSpec : { "radian" : 1 } , "value" : 1.3089969389957472 } , "tBase" : ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0.0105 } , "tDepth" : ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0.008 } , "tHeight" : ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0.016 } , "tOriginPoint" : Vector : [ ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0.05 } , ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0 } , ValueWithUnits : { "unit" : UnitSpec : { "meter" : 1 } , "value" : 0.008333333333333335 } ] } Result: Regeneration complete


Code

//
//  Dove Tail
//
annotation { "Feature Type Name" : "Dove Tail" }
export const doveTail = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Edges", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
        definition.edges is Query;
            
        annotation { "Name" : "Number of cuts" }
        isInteger(definition.cutNumber, POSITIVE_COUNT_BOUNDS);
   
    }
    {
            
        var spacing = 1.0/(definition.cutNumber + 1); 
        var parameterizedCutPoints is array = makeArray(definition.cutNumber);
        
        for (var i = 0; i < definition.cutNumber; i += 1)
        {
            parameterizedCutPoints[i] = (i + 1) * spacing;
        }
        
        var cutLines = evEdgeTangentLines(context, {
                "edge" : definition.edges,
                "arcLengthParameterization" : true,
                "parameters" : parameterizedCutPoints
        });
        
            
        for (var pt in cutLines)
        {

            opTrapezoid(context, id + "trapezoid1", {                                
                "tHeight" : 16 * millimeter,
                "tBase" : 10.5  * millimeter,
                "tAngle" : 75 * degree,
                "tDepth" : 8  * millimeter,
                "tOriginPoint" : pt.origin

                });
        }  
                
    });    

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

        debug(context, definition, DebugColor.RED);
        
/*        
        var tOriginPoint;
        if (definition.originPoint is Query)
        {
            var myPoints is Query = qEntityFilter(definition.originPoint, EntityType.VERTEX);
          
            tOriginPoint = evVertexPoint(context, {
                    "vertex" : myPoints
            });
                    

        }
        else
        {

            tOriginPoint = definition.tOriginPoint;
//            debug(context, tOriginPoint);
        }

  */          
            const sketch = newSketchOnPlane(context, id + "sketch1", {
                    "sketchPlane" : plane(definition.tOriginPoint, vector(0, 1, 0))
            });
            var xWing = definition.tHeight / tan(definition.tAngle);
            
            var tOrigin is Vector = vector(-definition.tBase/2 , -definition.tDepth);
            var point1 is Vector = vector(definition.tBase,0 * millimeter) + tOrigin; 
            var point2 is Vector = vector(definition.tBase - xWing, definition.tHeight) + tOrigin;
            var point3 is Vector = vector (xWing, definition.tHeight) + tOrigin ;
            
            
            skLineSegment(sketch, "base", {
                    "start" : tOrigin,
                    "end" : point1
            });
            skLineSegment(sketch, "side1", {
                    "start" : point1,
                    "end" : point2
            });
            skLineSegment(sketch, "top", {
                    "start" : point2,
                    "end" : point3
            });
            skLineSegment(sketch, "side2", {
                    "start" : point3,
                    "end" : tOrigin
            });
    
            skSolve(sketch);
            });
   

Comments

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,714
    The id must be different for each call to opTrapezoid like id + “trapezoid” + i (where i is a counter in the for loop). 
    Senior Director, Technical Services, EMEAI
  • daniel_cravensdaniel_cravens Member Posts: 29
    Thank you for your help! It works now.
Sign In or Register to comment.