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.

Rotating a line around an axis with FeatureScript

aleksi_hermonenaleksi_hermonen Member Posts: 5

I am trying to make a circular slide rule, where there are tics on a circle with uneven spacing. I have done this before on TinkerCad, where I did the tic placements with GeoGebra, saved that as a picture, imported the picture to TinkerCad and made a hole object out of it. It worked and I'm happy with the end result, but now, some time later, I have gotten to know OnShape and I'm so happy that I switched. It's so much more efficient and versatile.

And now I started to think about practicing by making the same (or almost the same) desing in OnShape.

But I have a problem: The Circular Pattern tool (both in Sketch view and in default view) allows only even spacing, and the pattern on slide rule is uneven, determined by logarithmic function.

So I started to get to know FeatureScript, I knew a little java programming before, so many things were familiar already. Also the ready-made buttons in Feature Studio view were really helpful. But now I'm stuck. At this point, I am trying just to rotate a copy of a given line by given angle around given line as an axis. When I get this to work, later I can put this command inside a loop and make more rotated copies at once. I have made a single horizontal line and a perpendicular rotation axis to a sketch and I have made following simple FeatureScript code (it already felt really nice to get the precondition to work properly). You can see the whole project at here:

https://cad.onshape.com/documents/badb8f11d26945aec3ce9ef4/w/fd641e36e3eb9ad62d2080b6/e/77c1d6e463b1c58924c05949?renderMode=0&uiState=66eef47a71fa000941fa5fb8


FeatureScript 2455;
import(path : "onshape/std/common.fs", version : "2455.0");

annotation { "Feature Type Name" : "Tics", "Feature Type Description" : "" }
export const myTics = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Line", "Filter" : GeometryType.LINE, "MaxNumberOfPicks" : 1 }
definition.ticLine is Query;

    annotation { "Name" : "Axis", "Filter" : GeometryType.LINE, "MaxNumberOfPicks" : 1 }
    definition.axis is Query;
    annotation { "Name" : "step:" }
    isReal(definition.step, POSITIVE_REAL_BOUNDS);
}
{
    var rotation = rotationAround(definition.axis, -45 * degree);
    opPattern(context, id + "pattern1", {
            "entities" : definition.ticLine,
            "transforms" : [rotation],
            "instanceNames" : [id + "instance1"]
    });

});

[end of code]

Here is an image of the earlier circular slide tule I made with TinkerCad. Tics are painted and numbers are printed with labelling machine:

Comments

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,695

    rotationAround needs a Line object not a Query - use evAxis to convert.

    Senior Director, Technical Services, EMEAI
  • aleksi_hermonenaleksi_hermonen Member Posts: 5

    Thank you for advice. I converted the axis to line object with evAxis command and used that on rotationAround, but unfortunately it still doesn't work. At the moment my code looks like this:

    FeatureScript 2455;
    import(path : "onshape/std/common.fs", version : "2455.0");

    annotation { "Feature Type Name" : "Tics", "Feature Type Description" : "" }
    export const myTics = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {

        annotation { "Name" : "Line", "Filter" : GeometryType.LINE, "MaxNumberOfPicks" : 1 }
    definition.ticLine is Query;

    annotation { "Name" : "Axis", "Filter" : GeometryType.LINE, "MaxNumberOfPicks" : 1 }
    definition.axis is Query;

    annotation { "Name" : "step:" }
    isReal(definition.step, POSITIVE_REAL_BOUNDS);

    }
    {

    var axisLine = evAxis(context, {"axis" : definition.axis});

    var rotation = rotationAround(axisLine, -45 * degree);

    opPattern(context, id + "pattern1", {
    "entities" : definition.ticLine,
    "transforms" : [rotation],
    "instanceNames" : [id + "instance1"]
    });
    });

  • aleksi_hermonenaleksi_hermonen Member Posts: 5

    Thank you for your answer. I converted the axis to a line with evAxis and used that on rotationAround, but unfortunately it still doesn't work. So this is my code now:

    FeatureScript 2455;
    import(path : "onshape/std/common.fs", version : "2455.0");
    annotation { "Feature Type Name" : "Tics", "Feature Type Description" : "" }
    export const myTics = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Line", "Filter" : GeometryType.LINE, "MaxNumberOfPicks" : 1 }
        definition.ticLine is Query;
        
        annotation { "Name" : "Axis", "Filter" : GeometryType.LINE, "MaxNumberOfPicks" : 1 }
        definition.axis is Query;
    
    
        annotation { "Name" : "step:" }
        isReal(definition.step, POSITIVE_REAL_BOUNDS);
    
    
    }
    {
    
    
        var lineAxis = evAxis(context, {"axis" : definition.axis});
    
    
        var rotation = rotationAround(lineAxis, -45 * degree);
    
    
        opPattern(context, id + "pattern1", {
                "entities" : definition.ticLine,
                "transforms" : [rotation],
                "instanceNames" : [id + "instance1"]
        });
    });
    
    

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,695

    take the id out of the instanceNames array should be just a string

    Senior Director, Technical Services, EMEAI
  • jelte_steur814jelte_steur814 Member Posts: 208 PRO

    Hi Aleksi,

    Good luck with your FS. there is another way though, leveraging Variables in feature patterns. read this and adapt accordingly.

    https://www.onshape.com/en/resource-center/tech-tips/tech-tip-how-to-use-variables-in-patterns-to-vary-features

    There's a custom feature to make this simpler, but I'm not sure it'll work for your logarithmic function.

    https://cad.onshape.com/documents/b48de632f33db2e4ec9ffacd/w/33301ef2e5423da1a2dbda12/e/78553bdfcca3eb9f40c3e229?renderMode=0&uiState=66f3cb17b8d0b13781551dd2

  • jelte_steur814jelte_steur814 Member Posts: 208 PRO
    edited September 25

    @aleksi_hermonen.
    Couldn't help myself but test it. this function ends up working exponentially and gets away from you rather quickly in the higher values.

    circular pattern 2 is reapplied each and every time within Circular pattern 1 so it keeps adding a new line at a new angle, but measured from the original top line. (not from the line next to it)

  • jelte_steur814jelte_steur814 Member Posts: 208 PRO

    https://cad.onshape.com/documents/2c9655258e3035ca1e88e8b7/w/69535d4d989a936765ab897e/e/101ed463e2646a893e4f9fbf?renderMode=0&rightPanel=variableTablePanel&uiState=66f3d154662cd1376e8e28da

Sign In or Register to comment.