simple manipulator tutorial?

adamohern
adamohern Member, OS Professional Posts: 216 PRO
Is there a simple 3D manipulator tutorial or example anywhere? The extrude tool, for example, clearly implements manipulators, but it's an extremely complex tool, so it's hard to tell what a simpler example might look like. If not, is that something that could be created fairly quickly? I just want to haul simple length values around.

Comments

  • kevin_o_toole_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    Here a quick example of a manipulator (coming soon to a documentation page near you!)

    annotation { "Feature Type Name" : "Fake extrude",
            "Manipulator Change Function" : "fakeExtrudeManipulatorChange" }
    export const fakeExtrude = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Faces to extrude", "Filter" : EntityType.FACE }
            definition.faces is Query;
            annotation { "Name" : "My Length" }
            isLength(definition.depth, LENGTH_BOUNDS);
            annotation { "Name" : "Opposite direction", "UIHint" : "OPPOSITE_DIRECTION" }
            definition.shouldFlip is boolean;
        }
        {
            var extrudePlane is Plane = evFaceTangentPlane(context, {
                    "face" : definition.faces,
                    "parameter" : vector(0.5, 0.5)
            });
            var extrudeManipulator is Manipulator = linearManipulator(
                    extrudePlane.origin,
                    extrudePlane.normal,
                    definition.shouldFlip ? definition.depth : -definition.depth
            );
            addManipulators(context, id, {
                    "myManipulator" : extrudeManipulator
            });
            opExtrude(context, id + "extrude1", {
                    "entities" : definition.faces,
                    "direction" : definition.shouldFlip ? extrudePlane.normal : -extrudePlane.normal,
                    "endBound" : BoundingType.BLIND,
                    "endDepth" : definition.depth
            });
        }, {});
    export function fakeExtrudeManipulatorChange(context is Context, definition is map, newManipulators is map) returns map
    {
        var newDepth is ValueWithUnits = newManipulators["myManipulator"].offset;
        definition.depth = abs(newDepth);
        definition.shouldFlip = newDepth > 0;
        return definition;
    }
  • adamohern
    adamohern Member, OS Professional Posts: 216 PRO
    You are a true hero, Kevin. Thank you.
  • kevin_o_toole_1
    kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565 image
    Full documentation for the manipulator change function can now be found here.