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.

circularPattern for Sketch Entities

Dario MangoniDario Mangoni Member, Developers Posts: 11 EDU
I'm trying to make a circular pattern of entities created into a Sketch.

Some questions:
In PartStudio there are two Circular Pattern tools:
1) the first is in the Default view: it aims to repeat Parts, Features or Faces: this does not replicate single entities inside a sketch
2) the secondi is in the Sketch view: it aims to replicate sketch entites
The FeatureScript circularPattern resembles more 1) than 2), right?

How can I replicate sketch entities then?
Should I use opPattern manually?

Thanks

Comments

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,419
    @Dario_Mangoni

    When you click on the "Circular pattern" button in the part studio, the code that is being executed is the 'circularPattern' function. (So, yes it is exactly 1, and not 2).

    It may be easier to advise you on what to do with a little more context.  Are you taking sketch entities as input to your feature, or are you creating sketch entities in your feature?  Maybe share a link to what you've written so far.  What are you trying to output?
    Jake Rosenfeld - Modeling Team
  • Dario MangoniDario Mangoni Member, Developers Posts: 11 EDU
    edited March 2018
    I'm creating entities in my feature.
    I can't find any useful minimal example with circularPattern, so here is my own:

    And few questions:
    - I don't know if the function is the same, but I'm sure that I want to replicate the behaviour of 2), not 1)
    - I need to replicate an entity within a Sketch: a Sketch Entity is not a Part|Feature|Face, right?
    - if so, circularPattern seems to indicate that it works with Part|Feature|Face, so how can it work with Sketch Entities?
    - since it is a Sketch Entity, I think that I should work between newSketch and skSolve, right? If so, it seems that I cannot get the Sketch Entities with queries before skSolve...
    - how can I (and why should I) get a query of an axis when I already have the axis itself?

    Anyway... if you can provide a working example similar to the one below, many doubts will be cleared!
    Here is the link to this (public) document
    https://cad.onshape.com/documents/6312a9a95643c93e12e2c33e/w/a0271dfb4e1295ea4d3a8254/e/473d22240641406feb72a798

    Thanks again

    -------------------------------------


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

    annotation { "Feature Type Name" : "circularPatternCustom" }
    export const circularPatternCustom = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Repetitions" }
            isInteger(definition.repetitions, POSITIVE_COUNT_BOUNDS);
            
        }
        {
            var sketchPlane = qCreatedBy(makeId("Top"), EntityType.FACE);
            var testSketch = newSketch(context, id + "sketch1", {
                    "sketchPlane" : sketchPlane
            });
            
            // create a circle
            skCircle(testSketch, "circle1", {
                    "center" : vector(1, 0) * meter,
                    "radius" : 0.1 * meter
            });
            
            
            // circularPattern goes here?
            
            
            skSolve(testSketch);
            
            
            var axis_vect is Vector = evOwnerSketchPlane(context, {"entity" : qCreatedBy(id + "sketch1")}).normal;
            var axis = line(vector(0,0,0)*meter, axis_vect);
            
            circularPattern(context, id + "circularPattern1", {
                "patternType" : PatternType.PART,
                "entities" : qCreatedBy(id + "sketch1", EntityType.EDGE),
                "axis" : axis_query, // how can I get a query, since I already have the axis? Why do I need a query!?
                "angle" : 360 * degree,
                "instanceCount" : 4
            });

            
        });

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,419
    Hi @Dario_Mangoni

    You're correct in thinking that circularPattern cannot be used on sketch entities.  Since sketches are constraint-based and need to be solved before existing in the system, the sketch entities don't actually exist until you call skSolve.  Here is some more reading on this:

    https://cad.onshape.com/FsDoc/library.html#module-sketch.fs

    There is not actually any FeatureScript you can call within your sketch to make that pattern.  If you make a sketch pattern and open the FeatureScript console of your part studio (Right click on the Part Studio tab and click Show code) you'll see that the sketch circular pattern actually just generates more calls to sk<WhateverPrimitiveIsBeingPatterned> rather than calling some specialized sketch pattern function:

    In this case you'll notice that I've patterned a circle using sketch circular pattern.  The resulting code just looks like 3 calls to skCircle (and an additional constraint).



    What you should do sort of depends on the goal of your feature.  If your feature is producing solids, you could just do the one sketch, then make it solid in whatever way you want (extrude, revolve, etc) and then part pattern the resulting solid.

    If you want your feature to deliver flat things, you could make the sketch, then use opExtractSurface to turn the sketch into a surface, and then part pattern the surface.

    If you need your feature to deliver sketches, you could either set up some kind of manual method to draw all the sketch entities (brute force drawing them all in a row, or a for loop over the number of instances you want), or draw the one sketch and then use Feature pattern option of circularPattern after the skSolve.  Feature pattern is pretty hard to set up manually and is mainly just meant to be used from the UI, but I can help you set it up if you want.
    Jake Rosenfeld - Modeling Team
  • Dario MangoniDario Mangoni Member, Developers Posts: 11 EDU
    edited March 2018
    Oh, now I got it!
    I didn't think of using "Show the code". It would have helped me a lot and it would have pointed me the solution!

    skConstraint with CIRCULAR_PATTERN is what I was looking for.
    Now I see what skSolve means!


    Thanks a lot!
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,419
    No problem @Dario_Mangoni

    Using constrains manually is a little tough, so let us know if you run into trouble.
    Jake Rosenfeld - Modeling Team
  • Dario MangoniDario Mangoni Member, Developers Posts: 11 EDU
    edited March 2018
    Well, you are probably right  :D


            skPoint(sketch, "point1",
                 {}
                // {"position" : vector(0, 10) * millimeter } // another option
            );
            
            var circularConstrInput is map = {
                "constraintType" : ConstraintType.CIRCULAR_PATTERN,
                "angle": 360/definition.repetitions*degree,
                "localRadius": definition.repRadius, // does not work
                "radius": definition.repRadius, // does not work
                "externalRadius": definition.repRadius, // does not work
                "length": definition.repRadius, // does not work
                "patterng" : 1, // number of elements to repeat
                "patternc1" : definition.repetitions, // number of repetitions
                "openPattern" : false,
                "localPivot" : "point1", // center of the pattern revolution
                "sketchToolType" : SketchToolType.PATTERN
            };
              
                          
            for (var i = 0; i < definition.repetitions; i+=1){
                skCircle(sketch, "circle"~i, {"radius": definition.circleRadius } );
                circularConstrInput["localInstance0,"~i] = "circle"~i;
            }
            
            // apply the circular pattern constraint
            skConstraint(sketch, "circularRepetition",
                circularConstrInput
            );
    


    The behaviour is the following:
    a) if I set localPivot that is in the origin, the replicated circles are overlapping and are placed in the origin
    b) if I set localPivot not in the origin, the replicated circles are actually distributed around, with a repetition radius of localPivot-origin
    c) I tried to do a) or b) plus a skConstraint-CONCENTRIC between point1 and a user-give point (that I see that is considered as external) like I saw it is done by OnShape, but it falls back to behaviour (a)

            // force the circular pattern constraint to be coincident to the user-given 'Repetition Center Point'
            skConstraint(sketch, "circularRepetitionPosition",
                {
                    "constraintType" : ConstraintType.CONCENTRIC,
                    "externalFirst" : definition.centerPoint,
                    "localSecond" : "point1"
                }
            );
    

    Now the questions:
    - which is the map field that tells the repetition radius? I didn't find anything in sketch.fs or anywhere else in std code.
    - how can I find, in general, this information myself? I don't strictly need a reference manual; even browsing the source code it will be perfectly fine!
    - I tried to put some initial guess positions for a circle using skSetInitialGuess, but it fails to solve the sketch; is the solution here?

    My document is here
    https://cad.onshape.com/documents/6312a9a95643c93e12e2c33e/w/a0271dfb4e1295ea4d3a8254/e/f17c11c7b69925eaa0b079f2
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,419
    @Dario_Mangoni

    I don't really recommend going down the rabbit hole of sketch constraints at all.  They're meant to be generated based of off UI use of interactive sketching, and we don't document them externally.  In fact, the sketch documentation says "When building sketches in FeatureScript, constraints may be added, but are almost always unnecessary, since you already have the ability to place the entities precisely where you intend them to be."
    https://cad.onshape.com/FsDoc/library.html#module-sketch.fs

    In the spirit of this, I'd still advise that you do that pattern manually, or do the pattern on solid bodies after the fact.
    I've put together an example for you of how to do the pattern manually:
    https://cad.onshape.com/documents/b48528990add590d06c0ca00/w/2be21080120e497fb0589233/e/92de68bf4324a07dedcdb27b

    Basically I just use a for loop to construct the necessary transform to the center of the circle, and draw the circle exactly where I want it to be.  The difference between the "simple" and "advanced" is that simple just projects everything on the Top plane, and advanced actually figures out a good sketch plane based on the selected seed and center.

    Hope this helps!
    Jake Rosenfeld - Modeling Team
  • Dario MangoniDario Mangoni Member, Developers Posts: 11 EDU
    Of course. I understand.
    This example was just to understand the possibilities: in my actual code I will just rotate the entities as you suggested.

    It's clear that, in general, one can solve the dependencies by hand and write down the code, however it may be a desirable to have this functions documented (since they are already implemented somewhere).

    Thanks again for the effort!
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,419
    Hi @Dario Mangoni

    I talked to a couple people and found another way of doing this that may interest you:
    https://cad.onshape.com/documents/d6e6613847aea9f290690788/w/fb641d78199ccd4112f3e9f9/e/cea4dfd05df30177f4b8cc0f

    Because sketches create sheet and wire bodies, you can just pattern them with circularPattern after the fact.  To answer an earlier question, circularPattern has to take a Query as an axis because the 'precondition' of that feature directly defines the UI of the Circular pattern feature.  You can easily make an axis with 'opFitSpline'.

    Jake Rosenfeld - Modeling Team
  • Dario MangoniDario Mangoni Member, Developers Posts: 11 EDU
    That's a really neat solution. Thanks again and also for the axis query problem.
Sign In or Register to comment.