Create a query from a Z_AXIS

monroe_weber_shirk
monroe_weber_shirk Member Posts: 103 EDU
I am using circularPattern in FeatureScript. It requires the axis of rotation as a query. I want to rotate around the Z_AXIS. How do I convert the Z_AXIS into a query?

Comments

  • antlu65
    antlu65 Member Posts: 61 EDU
    edited August 2022
    I was wondering the same awhile back. I don't know if this helps, but you might consider using 'opPattern' with 'rotationAround' instead of 'circularPattern'. That's what I ended up doing.

    Example here:
    const axis = Z_AXIS;
    var Ta = [];   // Array of transforms to apply.
    var names = [];   // Array of instance names.
    for (var i = 1; i < n; i += 1)
    {
       Ta = append(Ta, rotationAround(axis, i*360*degree / n));
       names = append(names, toString(i));
    }
    opPattern(context, patternId, {
       "entities" : qEntity,
       "transforms" : Ta,
       "instanceNames" : names
    });
    For patterning bodies and faces, this should produce the same result as using 'circularPattern'. A benefit is you aren't restricted to rotations about an axis.

  • monroe_weber_shirk
    monroe_weber_shirk Member Posts: 103 EDU
    Thank you! This side steps the problem and is a great general solution.
  • EvanReese
    EvanReese Member, Mentor Posts: 3,105 PRO
    edited August 2022
    The circularPattern feature is looking for a query, as you found. opPattern just uses transforms and is the better solution like you said. If you ever needed to get a query of a line for an axis you have to create the actual geometry and then delete it. You could make a sketch line on the front or right plane; a sketch circle on the top plane; a mate connector at the origin; or a 2-point fit spline. There may be others too, but generally opPattern will be easier to code (though less like actual modeling), and faster to regenerate.
    Evan Reese
    The Onsherpa | Reach peak Onshape productivity
    www.theonsherpa.com
  • Jacob_Corder
    Jacob_Corder Member Posts: 141 PRO
    if you want the Top plane to get the z axis from, you can simply call qCreatedBy(makeId("Top"),EntityType.FACE)

    annotation { "Feature Type Name" : "top plane axis" }
    export const topPlaneAxis = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
           
        }
        {
           var topPlane = qCreatedBy(makeId("Top"),EntityType.FACE);
           addDebugEntities(context, topPlane, DebugColor.RED);
           var tPlane = evPlane(context, {
                   "face" : topPlane
           });
           addDebugArrow(context, tPlane.origin, (tPlane.normal*25*millimeter) + tPlane.origin, 5 * millimeter, DebugColor.RED);
        });

    default features should always exist.  I am not saying this is the way to do it, but it is a way to do it.
  • monroe_weber_shirk
    monroe_weber_shirk Member Posts: 103 EDU
    Jacob, this is a long overdue response that got lost in my drafts! Thank you! This code is great. I think one of my challenges in writing FS code is that it is hard to know how to search for these code examples.
  • Jacob_Corder
    Jacob_Corder Member Posts: 141 PRO
    I just noticed this also. you can just call  

    qTopPlane(EntityType.FACE);  

    but you can also simply do this.

    plane(vector(0,0,0)*meter,vector(0,0,1));
    or
    plane( WORLD_ORIGIN,Z_AXIS);
    or even faster
    plane( WORLD_ORIGIN,Z_AXIS,X_AXIS);
    and even faster yet
     {"origin":WORLD_ORIGIN,"normal": Z_AXIS,"x": X_AXIS} as Plane;// this i believe bypasses the plane function to normalize already normalized vectors.