-17 Removals
+58 Additions
/* /*
T-Slot Joint T-Slot Joint
This custom feature adds a bolted T-slot connection between two planar parts. This custom feature adds a bolted T-slot connection between two planar parts.
Version 1.0 - July 6, 2016 - Arul Suresh - Initial development and validation. Version 1.0 - July 6, 2016 - Arul Suresh - Initial development and validation.
Version 2.0 - July 20, 2016 - Arul Suresh - Added some utility functions, lookup tables. Version 2.0 - July 20, 2016 - Arul Suresh - Added some utility functions, lookup tables.
Initial forum release. Initial forum release.
Version 2.1 - Sept 18, 2016 - Arul Suresh - Update to newest FS, published release. Version 2.1 - Sept 18, 2016 - Arul Suresh - Update to newest FS, published release.
Version 2.1.1 - Sept 18, 2016 - Arul Suresh - Document description. Version 2.1.1 - Sept 18, 2016 - Arul Suresh - Document description.
Version 2.2 - April 7, 2017 - Eric Miller - Added single-hole centered spacing and multiple plane selection, and fixed handling of angled surfaces.
*/ */
FeatureScript 422;FeatureScript 422;
import(path : "onshape/std/geometry.fs", version : "422.0");import(path : "onshape/std/geometry.fs", version : "422.0");
import(path : "4dfdd9c6856db10dd896e29b", version : "c92857bc5898d90ad6f21cc3");import(path : "5695a84e0bdf321f1d91df84", version : "90245e5cbffb04b2d7c533ad");
import(path : "f4e7238da5afaf5a3f1498c0/962c2d4fc4ca0f12fa54d8f4/22d17eb94c85900576fbf53e", version : "130b19167f35ae1dc291873b");import(path : "f4e7238da5afaf5a3f1498c0/962c2d4fc4ca0f12fa54d8f4/22d17eb94c85900576fbf53e", version : "130b19167f35ae1dc291873b");
annotation { "Feature Type Name" : "T-Slot Joint", "Editing Logic Function" : "tsEditLogic" }annotation { "Feature Type Name" : "T-Slot Joint", "Editing Logic Function" : "tsEditLogic" }
export const tSlotJoint = defineFeature(function(context is Context, id is Id, definition is map)export const tSlotJoint = defineFeature(function(context is Context, id is Id, definition is map)
precondition precondition
{ {
annotation { "Name" : "Choose edge face", "Filter" : EntityType.FACE && SketchObject.NO, "MaxNumberOfPicks" : 1 } annotation { "Name" : "Choose edge face", "Filter" : EntityType.FACE && SketchObject.NO }
definition.base is Query; definition.base is Query;
annotation { "Name" : "Standard", "Lookup Table" : tSlotTable, "UIHint" : "REMEMBER_PREVIOUS_VALUE" } annotation { "Name" : "Standard", "Lookup Table" : tSlotTable, "UIHint" : "REMEMBER_PREVIOUS_VALUE" }
definition.connectorStandard is LookupTablePath; definition.connectorStandard is LookupTablePath;
annotation { "Name" : "Clearance diameter", "UIHint" : "REMEMBER_PREVIOUS_VALUE" } annotation { "Name" : "Clearance diameter", "UIHint" : "REMEMBER_PREVIOUS_VALUE" }
isLength(definition.holeD, TSLOT_DIAMETER_LENGTH_BOUNDS); isLength(definition.holeD, TSLOT_DIAMETER_LENGTH_BOUNDS);
annotation { "Name" : "Nut width", "UIHint" : "REMEMBER_PREVIOUS_VALUE" } annotation { "Name" : "Nut width", "UIHint" : "REMEMBER_PREVIOUS_VALUE" }
isLength(definition.nutW, TSLOT_NUT_W_LENGTH_BOUNDS); isLength(definition.nutW, TSLOT_NUT_W_LENGTH_BOUNDS);
annotation { "Name" : "Nut thickness", "UIHint" : "REMEMBER_PREVIOUS_VALUE" } annotation { "Name" : "Nut thickness", "UIHint" : "REMEMBER_PREVIOUS_VALUE" }
isLength(definition.nutT, TSLOT_NUT_T_LENGTH_BOUNDS); isLength(definition.nutT, TSLOT_NUT_T_LENGTH_BOUNDS);
annotation { "Name" : "Show nut allowance", "UIHint" : "ALWAYS_HIDDEN" } annotation { "Name" : "Show nut allowance", "UIHint" : "ALWAYS_HIDDEN" }
definition.showNutA is boolean; definition.showNutA is boolean;
if (definition.showNutA) if (definition.showNutA)
{ {
annotation { "Name" : "Nut allowance" } annotation { "Name" : "Nut allowance" }
isLength(definition.nutA, LENGTH_BOUNDS); isLength(definition.nutA, LENGTH_BOUNDS);
} }
annotation { "Name" : "Screw length", "UIHint" : "REMEMBER_PREVIOUS_VALUE" } annotation { "Name" : "Screw length", "UIHint" : "REMEMBER_PREVIOUS_VALUE" }
isLength(definition.screwLen, TSLOT_SCREWLEN_LENGTH_BOUNDS); isLength(definition.screwLen, TSLOT_SCREWLEN_LENGTH_BOUNDS);
annotation { "Name" : "Hole termination face", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 } annotation { "Name" : "Hole termination face", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 }
definition.terminationFace is Query; definition.terminationFace is Query;
annotation { "Name" : "Switch start side" } annotation { "Name" : "Switch start side" }
definition.switchStart is boolean; definition.switchStart is boolean;
annotation { "Name" : "Space from edge", "UIHint" : "REMEMBER_PREVIOUS_VALUE" } annotation { "Name" : "Space from edge", "UIHint" : "REMEMBER_PREVIOUS_VALUE" }
isLength(definition.edgeSpace, TSLOT_EDGE_LENGTH_BOUNDS); isLength(definition.edgeSpace, TSLOT_EDGE_LENGTH_BOUNDS);
annotation { "Name" : "# of connectors" } annotation { "Name" : "# of connectors" }
isInteger(definition.numConnectors, NUM_CONN_BOUNDS); isInteger(definition.numConnectors, NUM_CONN_BOUNDS);
annotation { "Name" : "Equal spacing" } annotation { "Name" : "Equal spacing", "Default": true }
definition.equalSpacing is boolean; definition.equalSpacing is boolean;
if (!definition.equalSpacing) if (!definition.equalSpacing)
{ {
annotation { "Name" : "Spacing", "UIHint" : "REMEMBER_PREVIOUS_VALUE" } annotation { "Name" : "Spacing", "UIHint" : "REMEMBER_PREVIOUS_VALUE" }
isLength(definition.spacing, TSLOT_SPACING_LENGTH_BOUNDS); isLength(definition.spacing, TSLOT_SPACING_LENGTH_BOUNDS);
annotation { "Name" : "Symmetric" } annotation { "Name" : "Symmetric" }
definition.symmetric is boolean; definition.symmetric is boolean;
} }
} }
{ {
var faceInfo = getFaceInfo(context, definition); var bases = evaluateQuery(context, definition.base);
var faceInfo;
var i = 0;
for (var base in bases)
{
i += 1;
faceInfo = getFaceInfo(context, definition, base);
var connectionPoints is array = getConnectionPoints(context, definition, faceInfo); var connectionPoints is array = getConnectionPoints(context, definition, faceInfo);
var connectionCount = 0; var connectionCount = 0;
for (var connPoint in connectionPoints) for (var connPoint in connectionPoints)
{ {
connectionCount += 1; connectionCount += 1;
createTSlotJoint(context, id + ("tsj" ~ connectionCount), definition, connPoint); createTSlotJoint(context, id + ("tsj" ~ i ~ connectionCount), definition, connPoint, base);
}
} }
}); });
/*/*
* Creates geometry for a single T-Slot at the provided coordinate frame. * Creates geometry for a single T-Slot at the provided coordinate frame.
*/ */
function createTSlotJoint(context is Context, id is Id, definition is map, csys is CoordSystem)
function createTSlotJoint(context is Context, id is Id, definition is map, csys is CoordSystem, base is Query)
{{
var endClearance = 0.25 * definition.holeD; var endClearance = 0.25 * definition.holeD;
// hole through continuous material // hole through continuous material
var holeSketchPlane = plane(csys.origin, csys.zAxis, csys.xAxis); var holeSketchPlane = plane(csys.origin, csys.zAxis, csys.xAxis);
var depth = undefined; var depth = undefined;
if (evaluateQuery(context, definition.terminationFace) != []) if (evaluateQuery(context, definition.terminationFace) != [])
{ {
var faceCoords = evPlane(context, { var faceCoords = evPlane(context, {
"face" : definition.terminationFace "face" : definition.terminationFace
}).origin; }).origin;
depth = fromWorld(csys, faceCoords)[2]; depth = fromWorld(csys, faceCoords)[2];
} }
else else
{ {
depth = getContinuousDepth(context, id + "cd", { depth = getContinuousDepth(context, id + "cd", {
"csys" : csys, "csys" : csys,
"D" : definition.holeD "D" : definition.holeD
}); });
} }
if (definition.screwLen - depth - definition.nutT - endClearance < 0) if (definition.screwLen - depth - definition.nutT - endClearance < 0)
{ {
throw regenError("Screw length is too short for desired connection.", ["screwLen"]); throw regenError("Screw length is too short for desired connection.", ["screwLen"]);
} }
var sketch = newSketchOnPlane(context, id + "holeSketch", { var sketch = newSketchOnPlane(context, id + "holeSketch", {
"sketchPlane" : holeSketchPlane "sketchPlane" : holeSketchPlane
}); });
skCircle(sketch, "clearanceHole", { skCircle(sketch, "clearanceHole", {
"center" : vector(0, 0) * inch, "center" : vector(0, 0) * inch,
"radius" : 0.5 * definition.holeD "radius" : 0.5 * definition.holeD
}); });
skSolve(sketch); skSolve(sketch);
if (tolerantEquals(depth, 0 * meter)) if (tolerantEquals(depth, 0 * meter))
{ {
throw regenError("Edge connection does not intersect any clamped parts.", qCreatedBy(id + "holeSketch", EntityType.EDGE)); throw regenError("Edge connection does not intersect any clamped parts.", qCreatedBy(id + "holeSketch", EntityType.EDGE));
} }
extrude(context, id + "cutHole", { extrude(context, id + "cutHole", {
"entities" : qSketchRegion(id + "holeSketch"), "entities" : qSketchRegion(id + "holeSketch"),
"endBound" : BoundingType.BLIND, "endBound" : BoundingType.BLIND,
"depth" : depth, "depth" : depth,
"operationType" : NewBodyOperationType.REMOVE "operationType" : NewBodyOperationType.REMOVE
}); });
opDeleteBodies(context, id + "deleteHoleSketch", { opDeleteBodies(context, id + "deleteHoleSketch", {
"entities" : qCreatedBy(id + "holeSketch", EntityType.BODY) "entities" : qCreatedBy(id + "holeSketch", EntityType.BODY)
}); });
// At this point, hole is cut, and depth stores how much of the bolt is in clamped material // At this point, hole is cut, and depth stores how much of the bolt is in clamped material
// Generate a sketch and cut out the slot for the thread/nut // Generate a sketch and cut out the slot for the thread/nut
var threadSketchPlane = plane(csys.origin, yAxis(csys), csys.xAxis); var threadSketchPlane = plane(csys.origin, yAxis(csys), csys.xAxis);
var threadSketch = newSketchOnPlane(context, id + "threadsketch", { var threadSketch = newSketchOnPlane(context, id + "threadsketch", {
"sketchPlane" : threadSketchPlane "sketchPlane" : threadSketchPlane
}); });
skRectangle(threadSketch, "screwPocket", { skRectangle(threadSketch, "screwPocket", {
"firstCorner" : vector(-0.5 * definition.holeD, 0 * meter), "firstCorner" : vector(-0.5 * definition.holeD, 0 * meter),
"secondCorner" : vector(0.5 * definition.holeD, (definition.screwLen + 2 * definition.nutA) - depth) "secondCorner" : vector(0.5 * definition.holeD, (definition.screwLen + 2 * definition.nutA) - depth)
}); });
skRectangle(threadSketch, "nutPocket", { skRectangle(threadSketch, "nutPocket", {
"firstCorner" : vector(-0.5 * definition.nutW - definition.nutA, definition.screwLen - depth - endClearance - (definition.nutT + 2 * definition.nutA)), "firstCorner" : vector(-0.5 * definition.nutW - definition.nutA, definition.screwLen - depth - endClearance - (definition.nutT + 2 * definition.nutA)),
"secondCorner" : vector(0.5 * definition.nutW + definition.nutA, definition.screwLen - depth - endClearance) "secondCorner" : vector(0.5 * definition.nutW + definition.nutA, definition.screwLen - depth - endClearance)
}); });
skSolve(threadSketch); skSolve(threadSketch);
extrude(context, id + "threadExtrude", { extrude(context, id + "threadExtrude", {
"entities" : qSketchRegion(id + "threadsketch"), "entities" : qSketchRegion(id + "threadsketch"),
"endBound" : BoundingType.THROUGH_ALL, "endBound" : BoundingType.THROUGH_ALL,
"hasSecondDirection" : true, "hasSecondDirection" : true,
"secondDirectionBound" : SecondDirectionBoundingType.THROUGH_ALL, "secondDirectionBound" : SecondDirectionBoundingType.THROUGH_ALL,
"operationType" : NewBodyOperationType.REMOVE, "operationType" : NewBodyOperationType.REMOVE,
"defaultScope" : false, "defaultScope" : false,
"booleanScope" : qOwnerBody(definition.base) "booleanScope" : qOwnerBody(base)
}); });
opDeleteBodies(context, id + "deleteThreadSketch", { opDeleteBodies(context, id + "deleteThreadSketch", {
"entities" : qCreatedBy(id + "threadsketch", EntityType.BODY) "entities" : qCreatedBy(id + "threadsketch", EntityType.BODY)
}); });
}}
/*/*
* Returns a coordinate system and bounding box for the provided face * Returns a coordinate system and bounding box for the provided face
*/ */
function getFaceInfo(context is Context, definition is map) returns mapfunction getFaceInfo(context is Context, definition is map, base is Query) returns map
{{
if (size(evaluateQuery(context, definition.base)) != 1) if (size(evaluateQuery(context, base)) != 1)
{ {
throw regenError("Cannot generate without edge face selection", ["base"]); throw regenError("Cannot generate without edge face selection", ["base"]);
} }
var facePlane = evPlane(context, { var facePlane = evPlane(context, {
"face" : definition.base "face" : base
}); });
var defaultCSys = planeToCSys(facePlane); var defaultCSys = planeToCSys(facePlane) as CoordSystem;
try
{
var longEdge = qNthElement(qLargest(qGeometry(qEdgeAdjacent(base, EntityType.EDGE), GeometryType.LINE)), 0);
var axis = evAxis(context, {
"axis" : longEdge
}) as Line;
defaultCSys.xAxis = axis.direction;
}
var bbox = evBox3d(context, { var bbox = evBox3d(context, {
"topology" : definition.base, "topology" : base,
"cSys" : defaultCSys "cSys" : defaultCSys
}); });
var xrange = bbox.maxCorner[0] - bbox.minCorner[0]; var xrange = bbox.maxCorner[0] - bbox.minCorner[0];
var yrange = bbox.maxCorner[1] - bbox.minCorner[1]; var yrange = bbox.maxCorner[1] - bbox.minCorner[1];
// generate a coordinate system such that x is along the long dimension of the face // generate a coordinate system such that x is along the long dimension of the face
var csys is CoordSystem = coordSystem(facePlane.origin, var csys is CoordSystem = coordSystem(facePlane.origin,
(xrange > yrange) ? defaultCSys.xAxis : yAxis(defaultCSys), (xrange > yrange) ? defaultCSys.xAxis : yAxis(defaultCSys),
facePlane.normal); facePlane.normal);
bbox = evBox3d(context, { bbox = evBox3d(context, {
"topology" : definition.base, "topology" : base,
"cSys" : csys "cSys" : csys
}); });
return { "csys" : csys, "bbox" : bbox }; return { "csys" : csys, "bbox" : bbox };
}}
/*/*
* Given feature parameters and face selection, generates array of points at which T-Slots will be created * Given feature parameters and face selection, generates array of points at which T-Slots will be created
*/ */
function getConnectionPoints(context is Context, definition is map, faceInfo is map) returns arrayfunction getConnectionPoints(context is Context, definition is map, faceInfo is map) returns array
{{
if (definition.equalSpacing) if (definition.equalSpacing)
{ {
definition.symmetric = false; definition.symmetric = false;
var length = faceInfo.bbox.maxCorner[0] - faceInfo.bbox.minCorner[0]; var length = faceInfo.bbox.maxCorner[0] - faceInfo.bbox.minCorner[0];
definition.spacing = (length - 2 * definition.edgeSpace) / (definition.numConnectors - 1); if (definition.numConnectors > 1)
{
definition.spacing = (length - 2 * definition.edgeSpace) / (definition.numConnectors - 1);
}
else
{
definition.edgeSpace = length / 2;
}
} }
var coordList = makeCoordArray(context, definition, faceInfo); var coordList = makeCoordArray(context, definition, faceInfo);
if (definition.symmetric) if (definition.symmetric)
{ {
var localDefinition = definition; var localDefinition = definition;
localDefinition.switchStart = !localDefinition.switchStart; localDefinition.switchStart = !localDefinition.switchStart;
var symmetricCoordList = makeCoordArray(context, localDefinition, faceInfo); var symmetricCoordList = makeCoordArray(context, localDefinition, faceInfo);
coordList = concatenateArrays([coordList, symmetricCoordList]); coordList = concatenateArrays([coordList, symmetricCoordList]);
} }
return coordList; return coordList;
}}
function makeCoordArray(context is Context, definition is map, faceInfo is map) returns arrayfunction makeCoordArray(context is Context, definition is map, faceInfo is map) returns array
{{
var coordArray is array = makeArray(definition.numConnectors); var coordArray is array = makeArray(definition.numConnectors);
var sense = (definition.switchStart) ? -1 : 1; var sense = (definition.switchStart) ? -1 : 1;
var startx = ((definition.switchStart) ? faceInfo.bbox.maxCorner[0] : faceInfo.bbox.minCorner[0]) + sense * definition.edgeSpace; var startx = ((definition.switchStart) ? faceInfo.bbox.maxCorner[0] : faceInfo.bbox.minCorner[0]) + sense * definition.edgeSpace;
var dir = faceInfo.csys.xAxis; var dir = faceInfo.csys.xAxis;
var startOrigin = faceInfo.csys.origin + startx * dir; var startOrigin = faceInfo.csys.origin + startx * dir;
for (var i = 0; i < definition.numConnectors; i += 1) for (var i = 0; i < definition.numConnectors; i += 1)
{ {
coordArray[i] = coordSystem(startOrigin + sense * definition.spacing * dir * i, dir, faceInfo.csys.zAxis); coordArray[i] = coordSystem(startOrigin + sense * definition.spacing * dir * i, dir, faceInfo.csys.zAxis);
} }
return coordArray; return coordArray;
}}
export function tsEditLogic(context is Context, id is Id, oldDefinition is map, definition is map,export function tsEditLogic(context is Context, id is Id, oldDefinition is map, definition is map,
isCreating is boolean, specifiedParameters is map, hiddenBodies is Query) returns map isCreating is boolean, specifiedParameters is map, hiddenBodies is Query) returns map
{{
if (oldDefinition.connectorStandard != definition.connectorStandard) if (oldDefinition.connectorStandard != definition.connectorStandard)
{ {
definition = updateTSDefinitionWithStandard(oldDefinition, definition); definition = updateTSDefinitionWithStandard(oldDefinition, definition);
} }
definition = setToCustomIfStandardViolated(definition); definition = setToCustomIfStandardViolated(definition);
if (definition.equalSpacing) // if (definition.equalSpacing)
{ // {
definition.numConnectors = max(2, definition.numConnectors); // definition.numConnectors = max(2, definition.numConnectors);
} // }
return definition; return definition;
}}
export function updateTSDefinitionWithStandard(oldDefinition is map, definition is map) returns mapexport function updateTSDefinitionWithStandard(oldDefinition is map, definition is map) returns map
{{
var table = getLookupTable(tSlotTable, definition.connectorStandard); var table = getLookupTable(tSlotTable, definition.connectorStandard);
definition.showNutA = false; definition.showNutA = false;
for (var entry in table) for (var entry in table)
{ {
definition[entry.key] = lookupTableFixExpression(entry.value); definition[entry.key] = lookupTableFixExpression(entry.value);
} }
return definition; return definition;
}}
function setToCustomIfStandardViolated(definition is map) returns mapfunction setToCustomIfStandardViolated(definition is map) returns map
{{
var table = getLookupTable(tSlotTable, definition.connectorStandard); var table = getLookupTable(tSlotTable, definition.connectorStandard);
if (isLookupTableViolated(definition, table)) if (isLookupTableViolated(definition, table))
{ {
definition.connectorStandard = lookupTablePath({ "standard" : "Custom" }); definition.connectorStandard = lookupTablePath({ "standard" : "Custom" });
definition.showNutA = true; definition.showNutA = true;
} }
return definition; return definition;
}}
export const NUM_CONN_BOUNDS =export const NUM_CONN_BOUNDS =
{{
"min" : 1, "min" : 1,
"max" : 500, "max" : 500,
(unitless) : [1, 1, 500] (unitless) : [1, 1, 500]
} as IntegerBoundSpec; } as IntegerBoundSpec;
export const TSLOT_DIAMETER_LENGTH_BOUNDS =export const TSLOT_DIAMETER_LENGTH_BOUNDS =
{{
"min" : -TOLERANCE.zeroLength * meter, "min" : -TOLERANCE.zeroLength * meter,
"max" : 500 * meter, "max" : 500 * meter,
(inch) : [1e-4, 0.1285, 19685] (inch) : [1e-4, 0.1285, 19685]
} as LengthBoundSpec; } as LengthBoundSpec;
export const TSLOT_NUT_W_LENGTH_BOUNDS =export const TSLOT_NUT_W_LENGTH_BOUNDS =
{{
"min" : -TOLERANCE.zeroLength * meter, "min" : -TOLERANCE.zeroLength * meter,
"max" : 500 * meter, "max" : 500 * meter,
(inch) : [1e-4, 0.25, 19685] (inch) : [1e-4, 0.25, 19685]
} as LengthBoundSpec; } as LengthBoundSpec;
export const TSLOT_NUT_T_LENGTH_BOUNDS =export const TSLOT_NUT_T_LENGTH_BOUNDS =
{{
"min" : -TOLERANCE.zeroLength * meter, "min" : -TOLERANCE.zeroLength * meter,
"max" : 500 * meter, "max" : 500 * meter,
(inch) : [1e-4, 0.09375, 19685] (inch) : [1e-4, 0.09375, 19685]
} as LengthBoundSpec; } as LengthBoundSpec;
export const TSLOT_SCREWLEN_LENGTH_BOUNDS =export const TSLOT_SCREWLEN_LENGTH_BOUNDS =
{{
"min" : -TOLERANCE.zeroLength * meter, "min" : -TOLERANCE.zeroLength * meter,
"max" : 500 * meter, "max" : 500 * meter,
(inch) : [1e-4, 0.625, 19685], (inch) : [1e-4, 0.625, 19685],
(millimeter) : 15, (millimeter) : 15,
(centimeter) : 1.5 (centimeter) : 1.5
} as LengthBoundSpec; } as LengthBoundSpec;
export const TSLOT_EDGE_LENGTH_BOUNDS =export const TSLOT_EDGE_LENGTH_BOUNDS =
{{
"min" : -TOLERANCE.zeroLength * meter, "min" : -TOLERANCE.zeroLength * meter,
"max" : 500 * meter, "max" : 500 * meter,
(inch) : [1e-4, 0.5, 19685], (inch) : [1e-4, 0.5, 19685],
(millimeter) : 10, (millimeter) : 10,
(centimeter) : 1 (centimeter) : 1
} as LengthBoundSpec; } as LengthBoundSpec;
export const TSLOT_SPACING_LENGTH_BOUNDS =export const TSLOT_SPACING_LENGTH_BOUNDS =
{{
"min" : -TOLERANCE.zeroLength * meter, "min" : -TOLERANCE.zeroLength * meter,
"max" : 500 * meter, "max" : 500 * meter,
(inch) : [1e-4, 0.375, 19685], (inch) : [1e-4, 0.375, 19685],
(millimeter) : 10, (millimeter) : 10,
(centimeter) : 1 (centimeter) : 1
} as LengthBoundSpec; } as LengthBoundSpec;
Editor
Original Text
Changed Text