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.

Crash Course on opMateConnectors

Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
Hello everyone, I've got another question for you all. 

I am trying to get the hang of the opMateConnector function... What I am trying to do is to create a sketch and then place 2 mate connectors on the sketch. One on the top left side and one on the top right side. 

The code I have thus far, obviously doesn't work, but maybe one of you could help me out.

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

annotation { "Feature Type Name" : "Mate Connector" }
export const mateConnectorTest = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Width" }
        isLength(definition.width, LENGTH_BOUNDS);
        annotation { "Name" : "Height" }
        isLength(definition.height, LENGTH_BOUNDS);
    }
    {
        var width = definition.width;
        var height = definition.height;
        var verticies = [
            vector(0 * inch, 0 * inch),
            vector(0 * inch, height),
            vector(width, height),
            vector(width, 0 * inch)
        ];
        var sketch1 = newSketch(context, id + "sketch1", {
                "sketchPlane" : qCreatedBy(makeId("Front"), EntityType.FACE)
            });
        skLineSegment(sketch1, "line1", {
                    "start" : verticies[0],
                    "end" : verticies[1]
                });
        skLineSegment(sketch1, "line2", {
                    "start" : verticies[1],
                    "end" : verticies[2]
                });
        skLineSegment(sketch1, "line3", {
                    "start" : verticies[2],
                    "end" : verticies[3]
                });
        skLineSegment(sketch1, "line4", {
                    "start" : verticies[3],
                    "end" : verticies[0]
                });
        skSolve(sketch1);
        var origin = vector(0, 0, 0) * inch;
        var leftxaxis = vector(0, -1, 0) * inch;
        var leftzaxis = vector(1, 0, 0) * inch;
        var leftskplane = plane(origin, leftxaxis, leftzaxis);
        opMateConnector(context, id + "leftMateConnector1", {
                    "coordSystem" : leftskplane,
                    "owner" : qCreatedBy(id + "sketch1", EntityType.FACE)
                });
        var rightxaxis = vector(0, 1, 0) * inch;
        var rightzaxis = vector(1, 0, 0) * inch;
        var rightskplane = plane(origin, rightxaxis, rightzaxis);
        opMateConnector(context, id + "rightMateConnector1", {
                    "coordSystem" : rightskplane,
                    "owner" : qCreatedBy(id + "sketch1", EntityType.FACE)
                });

    });
Digital Engineering

Comments

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,308
    opMateConnector "owner" needs to be a solid body
    Senior Director, Technical Services, EMEAI
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    And you're passing a Plane into opMateConnector where it expects a CoordSystem.  You can construct a CoordSystem by using either coordSystem(somePlane) or coordSystem(origin, xaxis, zaxis).
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    Awesome!!! I'm another step closer. Here is what I have so far... Now just how to place the mate connectors where I want them? 

    FeatureScript 422;
    import(path : "onshape/std/geometry.fs", version : "422.0");
    PROFILE::import(path : "52bad43b4d807a71d217f4c8", version : "3294fd4185a5bf53e878e646");
    export enum profile
    {
        annotation { "Name" : "1" }
        F3en76Q1MqYHM44_0
    }
    annotation { "Feature Type Name" : "Mate Connector" }
    export const mateConnectorTest = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Width" }
            isLength(definition.width, LENGTH_BOUNDS);
            annotation { "Name" : "Height" }
            isLength(definition.height, LENGTH_BOUNDS);
            annotation { "Name" : "Square" }
            definition.squareProfile is profile;
        }
        {
            var width = definition.width;
            var height = definition.height;
            var verticies = [
                vector(0 * inch, 0 * inch),
                vector(0 * inch, height),
                vector(width, height),
                vector(width, 0 * inch)
            ];
            
            var contextWithProfiles is Context = PROFILE::build();
            opMergeContexts(context, id + "add_profile", {
                    "contextFrom" : contextWithProfiles
            });
            const profile = qCreatedBy(id + "add_profile" + (definition.squareProfile as string), EntityType.BODY);
            definition.entities = qSketchRegion(id + "add_profile" + (definition.squareProfile as string));
            var ownerPlane = evOwnerSketchPlane(context, {
                    "entity" : definition.entities
                });
                
            var sketch1 = newSketch(context, id + "sketch1", {
                    "sketchPlane" : qCreatedBy(makeId("Front"), EntityType.FACE)
                });
            skLineSegment(sketch1, "line1", {
                        "start" : verticies[0],
                        "end" : verticies[1]
                    });
            skLineSegment(sketch1, "line2", {
                        "start" : verticies[1],
                        "end" : verticies[2]
                    });
            skLineSegment(sketch1, "line3", {
                        "start" : verticies[2],
                        "end" : verticies[3]
                    });
            skLineSegment(sketch1, "line4", {
                        "start" : verticies[3],
                        "end" : verticies[0]
                    });
            skSolve(sketch1);
            var line2 = sketchEntityQuery(id + "sketch1", EntityType.EDGE, "line2");
            var lineWidth = evLength(context, {
                    "entities" : line2
            });
            var midpoint = evEdgeTangentLine(context, {
                    "edge" : line2,
                    "parameter" : .5
            }).origin;
            var lineAxis = evAxis(context, {
                    "axis" : line2
            });
            var linePlane = plane(midpoint, lineAxis.direction);
            opTransform(context, id + ("TopTransform"), {
                        "bodies" : profile,
                        "transform" : transform(ownerPlane, linePlane)
                    });
            extrude(context, id + "TopExtrude", {
                        "entities" : definition.entities,
                        "endBound" : BoundingType.SYMMETRIC,
                        "depth" : lineWidth
                    });
            var origin = vector(0, 0, 0) * inch;
            var leftxaxis = vector(0, -1, 0) * inch;
            var leftzaxis = vector(1, 0, 0) * inch;
            var leftskplane = plane(origin, leftxaxis, leftzaxis);
            
            opMateConnector(context, id + "leftMateConnector1", {
                        "coordSystem" : coordSystem(origin, leftxaxis, leftzaxis),
                        "owner" : qCreatedBy(id + "TopExtrude", EntityType.BODY)
                    });
            var rightxaxis = vector(0, 1, 0) * inch;
            var rightzaxis = vector(1, 0, 0) * inch;
            var rightskplane = plane(origin, rightxaxis, rightzaxis);
            opMateConnector(context, id + "rightMateConnector1", {
                        "coordSystem" : coordSystem(origin, rightxaxis, rightzaxis),
                        "owner" : qCreatedBy(id + "TopExtrude", EntityType.BODY)
                    });
    
        });

    The profile is just a cube.
    Digital Engineering
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    The coordinate system origin is what controls the world-space location of the mate connector.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    Okay, so I've tried placing different parameters in the coordSystem() and nothing seems to be changing the location of the mate... Is there an example or could you please show me how to change the location of the opMateConnector?? 
    Digital Engineering
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    Where would you like your mate connector to go?  Vertices 0 and 2?
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    Yes, just anything to get them in to a new location would much appreciated.
    Digital Engineering
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,173
    Ok, I changed the right mate connector to appear in a different place (on linePlane at vertices[2] in the local plane's coordinates).  The new addition is rightPosition.

    https://cad.onshape.com/documents/f1a8ef47a7624f874d0e07ab/w/0b375ed6f9452e936eb73f20/e/f908b7a6816575518888532e
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • cody_armstrongcody_armstrong Moderator, Onshape Employees, Developers, csevp Posts: 213
    @Dylan_Stewart The link below is an example I put together for patterning mate connectors at vertices.  It uses the vertex location and opMateConnector to create them.  It's a good example of placing mate connectors.

    Mate Connector Pattern
Sign In or Register to comment.