FeatureScript 2473; import(path : "onshape/std/common.fs", version : "2473.0"); //Icon Import featureicon::import(path : "0e75cac2d087d5d0b1330001", version : "c639220ef65bb13623f33263"); //Vendor Enum export enum vendorType { annotation { "Name" : "McMaster" } MCMASTER, annotation { "Name" : "CNC Kitchen" } CNCKITCHEN, annotation { "Name" : "Amazon" } AMAZON, annotation { "Name" : "Ruthex" } RUTHEX } //Vendor Lookup Tables export const mcMasterTable = { "name" : "insertSize", "displayName" : "Insert Size", "entries" : { "M2x2.5" : { "holeDiameter" : 3.3, "holeDepth" : 3.3 }, "M2x4" : { "holeDiameter" : 3.3, "holeDepth" : 4.8 }, "M2.5x5.9" : { "holeDiameter" : 4.1, "holeDepth" : 6.8 }, "M3x4.3" : { "holeDiameter" : 4, "holeDepth" : 5.3 }, "M3x5.7" : { "holeDiameter" : 4, "holeDepth" : 6.7 }, "M3.5x7.3" : { "holeDiameter" : 4.9, "holeDepth" : 8.5 }, "M4x4.7" : { "holeDiameter" : 5.6, "holeDepth" : 6.1 }, "M4x6.4" : { "holeDiameter" : 5.6, "holeDepth" : 7.8 }, "M4x8.1" : { "holeDiameter" : 5.6, "holeDepth" : 9.5 }, "M5x9.5" : { "holeDiameter" : 6.5, "holeDepth" : 11.1 }, "M6x7.9" : { "holeDiameter" : 8, "holeDepth" : 9.9 }, "M6x9.5" : { "holeDiameter" : 8, "holeDepth" : 11.5 }, "M6x12.7" : { "holeDiameter" : 8, "holeDepth" : 14.7 } } }; export const cncKitchenTable = { "name" : "insertSize", "displayName" : "Insert Size", "entries" : { "M2x3" : { "holeDiameter" : 3.2, "holeDepth" : 3 }, "M2.5x4" : { "holeDiameter" : 4, "holeDepth" : 5 }, "M3x3" : { "holeDiameter" : 4, "holeDepth" : 4 }, "M3x4 Voron" : { "holeDiameter" : 4.4, "holeDepth" : 5 }, "M3x5.7" : { "holeDiameter" : 4, "holeDepth" : 6.7 }, "M4x4" : { "holeDiameter" : 5.6, "holeDepth" : 5 }, "M4x8.1" : { "holeDiameter" : 5.6, "holeDepth" : 9.1 }, "M5x5.8" : { "holeDiameter" : 6.4, "holeDepth" : 7.4 }, "M5x8" : { "holeDiameter" : 6.2, "holeDepth" : 6.8 }, "M5x9.5" : { "holeDiameter" : 6.4, "holeDepth" : 11 }, "M6x12.7" : { "holeDiameter" : 8, "holeDepth" : 14.7 }, "M8x12.7" : { "holeDiameter" : 9.7, "holeDepth" : 14.7 }, "1/4-20x12.7" : { "holeDiameter" : 8, "holeDepth" : 14.7 } } }; export const amazonTable = { "name" : "insertSize", "displayName" : "Insert Size", "entries" : { "M2x2" : { "holeDiameter" : 2.8, "holeDepth" : 2.8 }, "M2x4" : { "holeDiameter" : 2.8, "holeDepth" : 4.8 }, "M2.5x2.5" : { "holeDiameter" : 3.2, "holeDepth" : 3.4 }, "M2.5x4" : { "holeDiameter" : 3.2, "holeDepth" : 4.9 }, "M3x4" : { "holeDiameter" : 4.3, "holeDepth" : 5 }, "M3x6" : { "holeDiameter" : 4.3, "holeDepth" : 7 }, "M3x8" : { "holeDiameter" : 4, "holeDepth" : 9 }, "M4x4" : { "holeDiameter" : 5.5, "holeDepth" : 5.4 }, "M4x6" : { "holeDiameter" : 5.5, "holeDepth" : 7.4 }, "M4x8" : { "holeDiameter" : 5.3, "holeDepth" : 9.4 }, "M5x6" : { "holeDiameter" : 6.2, "holeDepth" : 7.6 }, "M5x8" : { "holeDiameter" : 6.2, "holeDepth" : 9.6 }, "M5x10" : { "holeDiameter" : 6.2, "holeDepth" : 11.6 }, "M6x8" : { "holeDiameter" : 7.2, "holeDepth" : 10 }, "M6x10" : { "holeDiameter" : 7.2, "holeDepth" : 12 }, } }; export const ruthexTable = { "name" : "insertSize", "displayName" : "Insert Size", "entries" : { "M2" : { "holeDiameter" : 3.2, "holeDepth" : 5.0 }, "M2.5" : { "holeDiameter" : 4.0, "holeDepth" : 6.7 }, "M3 Short" : { "holeDiameter" : 4.0, "holeDepth" : 5.0 }, "M3x5x4 Voron" : { "holeDiameter" : 4.4, "holeDepth" : 5.0 }, "M3" : { "holeDiameter" : 4.0, "holeDepth" : 6.7 }, "M4 Short" : { "holeDiameter" : 5.6, "holeDepth" : 5.0 }, "M4" : { "holeDiameter" : 5.6, "holeDepth" : 9.1 }, "M5 Short" : { "holeDiameter" : 6.4, "holeDepth" : 6.8 }, "M5" : { "holeDiameter" : 6.4, "holeDepth" : 10.5 }, "M6" : { "holeDiameter" : 8.0, "holeDepth" : 13.7 }, "M6 Short" : { "holeDiameter" : 8.0, "holeDepth" : 7.8 }, "M8" : { "holeDiameter" : 9.6, "holeDepth" : 13.7 }, "M10" : { "holeDiameter" : 11.9, "holeDepth" : 13.7 } } }; //Functions //Creates a plane from the location point or mate connector function getHolePlane(context is Context, location is Query) { var holePlane; //plane from location sketch point try silent { var sketchPlane; sketchPlane = evOwnerSketchPlane(context, { "entity" : location }); var normal = sketchPlane.normal; var x = sketchPlane.x; var origin = evVertexPoint(context, { "vertex" : location }); holePlane = plane(origin, normal, x); } //plane from mate connector try silent { var mateCoord = evMateConnector(context, { "mateConnector" : location }); holePlane = plane(mateCoord); } return holePlane; } function displayInsert(context is Context, id is Id, holePlane is Plane, diameter is ValueWithUnits, depth is ValueWithUnits) { // sketch circle var debugSketchId = id + "debugSketch"; var debugSketch = newSketchOnPlane(context, debugSketchId, { "sketchPlane" : holePlane }); skCircle(debugSketch, "circle1", { "center" : vector(0, 0) * inch, "radius" : diameter / 2 }); skSolve(debugSketch); //extrude cylinder var debugExtrudeId = id + "DebugExtrude"; opExtrude(context, debugExtrudeId, { "entities" : qSketchRegion(debugSketchId), "direction" : -1 * holePlane.normal, "endBound" : BoundingType.BLIND, "endDepth" : depth }); var insertBody = qCreatedBy(debugExtrudeId, EntityType.BODY); var insertEdges = qOwnedByBody(insertBody, EntityType.EDGE); //add edges because bodies can't be seen through other bodes var debugInsert = qUnion([insertBody, insertEdges]); addDebugEntities(context, debugInsert, DebugColor.YELLOW); opDeleteBodies(context, id + "deleteBodies1", { "entities" : qUnion([qCreatedBy(debugSketchId), insertBody]) }); } annotation { "Feature Type Name" : "Heat Set Insert", "Feature Type Description" : "Creates a Hole for Heat Set Inserts", "Icon" : featureicon::BLOB_DATA, "Feature Name Template" : "#test" } export const heatSetInsert = defineFeature(function(context is Context, id is Id, definition is map) precondition { //create dropdown based on vendor annotation { "Name" : "Vendor", "UIHint" : [UIHint.HORIZONTAL_ENUM, UIHint.REMEMBER_PREVIOUS_VALUE] } definition.vendor is vendorType; if (definition.vendor == vendorType.MCMASTER) { annotation { "Name" : "Insert Size", "Lookup Table" : mcMasterTable, "UIHint" : UIHint.REMEMBER_PREVIOUS_VALUE } definition.mcMasterSize is LookupTablePath; } else if (definition.vendor == vendorType.CNCKITCHEN) { annotation { "Name" : "Insert Size", "Lookup Table" : cncKitchenTable, "UIHint" : UIHint.REMEMBER_PREVIOUS_VALUE } definition.cncKitchenSize is LookupTablePath; } else if (definition.vendor == vendorType.RUTHEX) { annotation { "Name" : "Insert Size", "Lookup Table" : ruthexTable, "UIHint" : UIHint.REMEMBER_PREVIOUS_VALUE } definition.ruthexSize is LookupTablePath; } else { annotation { "Name" : "Insert Size", "Lookup Table" : amazonTable, "UIHint" : UIHint.REMEMBER_PREVIOUS_VALUE } definition.amazonSize is LookupTablePath; } //select points/mate connectors annotation { "Name" : "Locations", "Filter" : EntityType.VERTEX && SketchObject.YES || BodyType.MATE_CONNECTOR } definition.locations is Query; //toggle for holes to go through all annotation { "Name" : "Up to Surface" } definition.upToSurface is boolean; if (definition.upToSurface) { annotation { "Name" : "Surface", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 } definition.surfaceQuery is Query; } //select merge scope annotation { "Name" : "Merge Scope", "Filter" : EntityType.BODY && BodyType.SOLID } definition.mergeScope is Query; } { //initialize variables var tableVals; var insertSize; if (definition.vendor == vendorType.MCMASTER) { tableVals = getLookupTable(mcMasterTable, definition.mcMasterSize); insertSize = definition.mcMasterSize.insertSize; } else if (definition.vendor == vendorType.CNCKITCHEN) { tableVals = getLookupTable(cncKitchenTable, definition.cncKitchenSize); insertSize = definition.cncKitchenSize.insertSize; } else if (definition.vendor == vendorType.RUTHEX) { tableVals = getLookupTable(ruthexTable, definition.ruthexSize); insertSize = definition.ruthexSize.insertSize; } else { tableVals = getLookupTable(amazonTable, definition.amazonSize); insertSize = definition.amazonSize.insertSize; } const locations = definition.locations; const upToSurface = definition.upToSurface; const diameter = tableVals["holeDiameter"] * millimeter; const depth = tableVals["holeDepth"] * millimeter; const mergeScope = definition.mergeScope; const surfaceQuery = definition.surfaceQuery; //set feature name println(insertSize); setFeatureComputedParameter(context, id, { "name" : "test", "value" : insertSize }); forEachEntity(context, id + "createHoles", locations, function(location is Query, id is Id) { var holePlane = getHolePlane(context, location); displayInsert(context, id, holePlane, diameter, depth); //sketch circle var holeSketchId = id + "holeSketch"; var holeSketch = newSketchOnPlane(context, holeSketchId, { "sketchPlane" : holePlane }); skCircle(holeSketch, "circle1", { "center" : vector(0, 0) * inch, "radius" : diameter / 2 }); skSolve(holeSketch); //extrude cylinder var extrudeId = id + "extrude"; if (upToSurface) { opExtrude(context, extrudeId, { "entities" : qSketchRegion(holeSketchId), "direction" : -1 * holePlane.normal, "endBound" : BoundingType.UP_TO_SURFACE, "endBoundEntity" : surfaceQuery, }); } else { opExtrude(context, extrudeId, { "entities" : qSketchRegion(holeSketchId), "direction" : -1 * holePlane.normal, "endBound" : BoundingType.BLIND, "endDepth" : depth }); } //color the cylinder // setProperty(context, { // "entities" : qCreatedBy(extrudeId, EntityType.BODY), // "propertyType" : PropertyType.APPEARANCE, // "value" : color(1, 0, 0) // }); //cut cylinders from target body var booleanId = id + "boolean"; opBoolean(context, booleanId, { "tools" : qCreatedBy(extrudeId, EntityType.BODY), "targets" : mergeScope, "operationType" : BooleanOperationType.SUBTRACTION }); //set color of hole setProperty(context, { "entities" : qCreatedBy(booleanId, EntityType.FACE), "propertyType" : PropertyType.APPEARANCE, "value" : color((250/255), (182/255), 0) }); //delete sketch opDeleteBodies(context, id + "deleteBodies2", { "entities" : qCreatedBy(holeSketchId) }); }); });