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.

Is the MateConnector.fs code the only way to do in-context inference in a script?

joshtargojoshtargo Member Posts: 610 EDU

The only way I've ever been able to use inferred MC's as inputs while modeling in-context is with this exact code, even the requirement of naming the function "mateConnector".

Do I need to use this exact code as the basis for these types of scripts, or is there a more universal/normal way to do it?

FeatureScript 2960;
import(path : "onshape/std/common.fs", version : "2960.0");
export import(path : "onshape/std/origincreationtype.gen.fs", version : "2960.0");
export import(path : "onshape/std/entityinferencetype.gen.fs", version : "2960.0");

annotation {
    "Feature Type Name" : "Context MC Test",
    "Feature Type Description" : "Minimal in-context mate connector from a single entity pick."
}
export const mateConnector = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Origin type", "UIHint" : UIHint.ALWAYS_HIDDEN }
        definition.originType is OriginCreationType;

        annotation { "UIHint" : UIHint.ALWAYS_HIDDEN }
        definition.entityInferenceType is EntityInferenceType;

        annotation { "UIHint" : UIHint.ALWAYS_HIDDEN }
        definition.secondaryOriginQuery is Query;

        annotation { "UIHint" : UIHint.ALWAYS_HIDDEN }
        definition.originAdditionalQuery is Query;

        annotation { "Name" : "Specify normal", "UIHint" : UIHint.ALWAYS_HIDDEN }
        definition.specifyNormal is boolean;

        annotation { "Name" : "Normal x", "UIHint" : UIHint.ALWAYS_HIDDEN }
        isReal(definition.nx, { (unitless) : [ -1, 1, 1 ] } as RealBoundSpec);

        annotation { "Name" : "Normal y", "UIHint" : UIHint.ALWAYS_HIDDEN }
        isReal(definition.ny, { (unitless) : [ -1, 1, 1 ] } as RealBoundSpec);

        annotation { "Name" : "Normal z", "UIHint" : UIHint.ALWAYS_HIDDEN }
        isReal(definition.nz, { (unitless) : [ -1, 1, 1 ] } as RealBoundSpec);

        annotation { "Name" : "Location",
             "Filter" : (EntityType.EDGE || EntityType.VERTEX || EntityType.FACE) && AllowMeshGeometry.YES,
             "MaxNumberOfPicks" : 1 }
        definition.originQuery is Query;
    }
    {
        const csys = evMateConnectorCoordSystem(context, definition);

        opMateConnector(context, id + "mc1", {
            "owner" : qNothing(),
            "coordSystem" : csys
        });
    },
    {
        "originType" : OriginCreationType.ON_ENTITY,
        "entityInferenceType" : EntityInferenceType.POINT,
        "secondaryOriginQuery" : qNothing(),
        "originAdditionalQuery" : qNothing(),
        "specifyNormal" : false,
        "nx" : 0.0,
        "ny" : 0.0,
        "nz" : 0.0
    });

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.