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.

question about feature script sketch merge and constrain when using circular pattern

Jeffrey42Jeffrey42 Member Posts: 5 EDU
edited June 29 in General
Hi, I have two questions about my 2D sketches project at school.
first, when I use the circular pattern, the sketch will not fully constrain. I try to use skconstrain tool but realize that I need to skslove the sketch to be able to use the circular pattern tool. I do not know how to use the skconstrain when the sketch was already solved.

the second question is also about the constraint. Since I sketch my circles and arcs in different sketches so they do not recognize each other, which make perfect sense. However, Is there a way to merge different sketches?




using a circular pattern with multiple sketches
https://cad.onshape.com/documents/13fd38394d33485d50d1541d/w/7bb55977ab2fa287378daae6/e/afef66410945473a7c0073c3

end up hardcoding everything in the second version on below works but not pretty:
https://cad.onshape.com/documents/7bd52314a96f9a14b24e8ca8/w/290640dd845c1e9488e4008d/e/4a2a3650ac6f9bad46b17163

Thank you in advance

Best Answers

  • paul_chastellpaul_chastell Posts: 115
    Accepted Answer
    And I've added a simple example of what I mean here: https://cad.onshape.com/documents/8e940365ff5576f2d5947b66/w/87fa8e9e372ccba0ab8f9bc0/e/943f06a64756586adae6da37

    annotation { "Feature Type Name" : "Patterned sketch" }
    export const patterned = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Count" }
            isInteger(definition.count, POSITIVE_COUNT_BOUNDS);
        }
        {
            // Make the sketch
            const sketch = newSketchOnPlane(context, id + "sketch", {
                        "sketchPlane" : plane(vector(0, 0, 0) * meter, vector(0, 0, 1))
                    });
    
            // Define the position of the geometry for the 'seed' position
            const mm = millimeter;
            const start = vector(100, 10, 0) * mm;
            const mid = vector(130, 0, 0) * mm;
            const end = vector(100, -10, 0) * mm;
    
            const axis = line(vector(0, 0, 0) * meter, vector(0, 0, 1));
            const full = PI * 2 * radian;
    
            // Loop through the required number of instances, transform the points and create the geometry
             for (var i = 0; i < definition.count; i += 1)
            {
                const lineId = "line" ~ i;
                const arcId = "arc" ~ i;
    
                const rotation = rotationAround(axis, (i / definition.count) * full);
                const start3d = rotation * start;
                const mid3d = rotation * mid;
                const end3d = rotation * end;
    
                const start2d = vector(start3d[0], start3d[1]);
                const mid2d = vector(mid3d[0], mid3d[1]);
                const end2d = vector(end3d[0], end3d[1]);
                
                skLineSegment(sketch, lineId, {
                            "start" : start2d,
                            "end" : end2d 
                        });
    
                skArc(sketch, arcId, {
                            "start" : start2d,
                            "mid" : mid2d,
                            "end" : end2d
                        });
            }
            skSolve(sketch);
        });
    


    Paul Chastell / VP of R&D / Onshape Inc.

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 2,282
    Hi @jeffrey_chaing I’ve not heard of projects requiring FeatureScript before? What is the project end goal? It is likely you can save yourself a lot of effort just using the available built-in tools. 
    Neil Cooke, Director of Technical Marketing, Onshape Inc.
  • Jeffrey42Jeffrey42 Member Posts: 5 EDU
    Hi, @NeilCooke our school wants us to draw sketches from FeatureScript. We basically learning the FeatureScript tools, so we could use it on generative designed later on. We did draw it using the built-in tools as well. Just want to know is there ways to actually merge sketches or constrain a circular pattern in the FeatureScript?

    Thank you for the reply
  • Jeffrey42Jeffrey42 Member Posts: 5 EDU
    Hi, @paul_chastell. Thank you for the clarification.
  • paul_chastellpaul_chastell Onshape Employees Posts: 115
    Accepted Answer
    And I've added a simple example of what I mean here: https://cad.onshape.com/documents/8e940365ff5576f2d5947b66/w/87fa8e9e372ccba0ab8f9bc0/e/943f06a64756586adae6da37

    annotation { "Feature Type Name" : "Patterned sketch" }
    export const patterned = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Count" }
            isInteger(definition.count, POSITIVE_COUNT_BOUNDS);
        }
        {
            // Make the sketch
            const sketch = newSketchOnPlane(context, id + "sketch", {
                        "sketchPlane" : plane(vector(0, 0, 0) * meter, vector(0, 0, 1))
                    });
    
            // Define the position of the geometry for the 'seed' position
            const mm = millimeter;
            const start = vector(100, 10, 0) * mm;
            const mid = vector(130, 0, 0) * mm;
            const end = vector(100, -10, 0) * mm;
    
            const axis = line(vector(0, 0, 0) * meter, vector(0, 0, 1));
            const full = PI * 2 * radian;
    
            // Loop through the required number of instances, transform the points and create the geometry
             for (var i = 0; i < definition.count; i += 1)
            {
                const lineId = "line" ~ i;
                const arcId = "arc" ~ i;
    
                const rotation = rotationAround(axis, (i / definition.count) * full);
                const start3d = rotation * start;
                const mid3d = rotation * mid;
                const end3d = rotation * end;
    
                const start2d = vector(start3d[0], start3d[1]);
                const mid2d = vector(mid3d[0], mid3d[1]);
                const end2d = vector(end3d[0], end3d[1]);
                
                skLineSegment(sketch, lineId, {
                            "start" : start2d,
                            "end" : end2d 
                        });
    
                skArc(sketch, arcId, {
                            "start" : start2d,
                            "mid" : mid2d,
                            "end" : end2d
                        });
            }
            skSolve(sketch);
        });
    


    Paul Chastell / VP of R&D / Onshape Inc.
  • Jeffrey42Jeffrey42 Member Posts: 5 EDU
    Thank you  @paul_chastell. The rotationAround function is really helpful!! 
  • Jeffrey42Jeffrey42 Member Posts: 5 EDU
    Hello, @paul_chastell. Thank you for helping me with my school projects. I was able to make it work!
    If you have want to take a look below is my github. We able to play with the 3D as well
    github: https://github.com/JCTGY/2D_FeatureScript

    Onshape: https://cad.onshape.com/documents/7bd52314a96f9a14b24e8ca8/w/290640dd845c1e9488e4008d/e/a40c1ed49153c80a4acac5b6
  • paul_chastellpaul_chastell Onshape Employees Posts: 115
    Excellent! Happy to help.
    Paul Chastell / VP of R&D / Onshape Inc.
Sign In or Register to comment.