Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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_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.
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
0
Comments
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.
https://cad.onshape.com/documents/f1a8ef47a7624f874d0e07ab/w/0b375ed6f9452e936eb73f20/e/f908b7a6816575518888532e
Mate Connector Pattern