Skip to content

Commit 1bec3d0

Browse files
committed
feat: reworked PR #87 ading cutouts on magnet socket sides to allow easier extraction of the magnets
1 parent 017dd53 commit 1bec3d0

File tree

2 files changed

+113
-11
lines changed

2 files changed

+113
-11
lines changed

commands/commandCreateBin/entry.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
BIN_GENERATE_BODY_INPUT_ID = 'bin_generate_body'
8686
BIN_SCREW_HOLES_INPUT_ID = 'bin_screw_holes'
8787
BIN_MAGNET_CUTOUTS_INPUT_ID = 'bin_magnet_cutouts'
88+
BIN_MAGNET_CUTOUTS_TABS_INPUT_ID = 'bin_magnet_cutouts_tabs'
8889
BIN_SCREW_DIAMETER_INPUT = 'screw_diameter'
8990
BIN_MAGNET_DIAMETER_INPUT = 'magnet_diameter'
9091
BIN_MAGNET_HEIGHT_INPUT = 'magnet_height'
@@ -186,6 +187,7 @@ def initDefaultUiState():
186187
commandUIState.initValue(BIN_SCREW_DIAMETER_INPUT, const.DIMENSION_SCREW_HOLE_DIAMETER, adsk.core.ValueCommandInput.classType())
187188
commandUIState.initValue(BIN_SCREW_DIAMETER_INPUT, const.DIMENSION_SCREW_HOLE_DIAMETER, adsk.core.ValueCommandInput.classType())
188189
commandUIState.initValue(BIN_MAGNET_CUTOUTS_INPUT_ID, False, adsk.core.BoolValueCommandInput.classType())
190+
commandUIState.initValue(BIN_MAGNET_CUTOUTS_TABS_INPUT_ID, False, adsk.core.BoolValueCommandInput.classType())
189191
commandUIState.initValue(BIN_MAGNET_DIAMETER_INPUT, const.DIMENSION_MAGNET_CUTOUT_DIAMETER, adsk.core.ValueCommandInput.classType())
190192
commandUIState.initValue(BIN_MAGNET_HEIGHT_INPUT, const.DIMENSION_MAGNET_CUTOUT_DEPTH, adsk.core.ValueCommandInput.classType())
191193

@@ -632,6 +634,8 @@ def command_created(args: adsk.core.CommandCreatedEventArgs):
632634
commandUIState.registerCommandInput(screwSizeInput)
633635
generateMagnetSocketCheckboxInput = baseFeaturesGroup.children.addBoolValueInput(BIN_MAGNET_CUTOUTS_INPUT_ID, 'Add magnet sockets', True, '', commandUIState.getState(BIN_MAGNET_CUTOUTS_INPUT_ID))
634636
commandUIState.registerCommandInput(generateMagnetSocketCheckboxInput)
637+
generateMagnetsTabCheckboxInput = baseFeaturesGroup.children.addBoolValueInput(BIN_MAGNET_CUTOUTS_TABS_INPUT_ID, 'Add tabs to magnet sockets', True, '', commandUIState.getState(BIN_MAGNET_CUTOUTS_TABS_INPUT_ID))
638+
commandUIState.registerCommandInput(generateMagnetsTabCheckboxInput)
635639
magnetSizeInput = baseFeaturesGroup.children.addValueInput(BIN_MAGNET_DIAMETER_INPUT, 'Magnet cutout diameter', defaultLengthUnits, adsk.core.ValueInput.createByReal(commandUIState.getState(BIN_MAGNET_DIAMETER_INPUT)))
636640
magnetSizeInput.minimumValue = 0.1
637641
magnetSizeInput.isMinimumInclusive = True
@@ -794,6 +798,7 @@ def onChangeValidate():
794798
generateBase: bool = commandUIState.getState(BIN_GENERATE_BASE_INPUT_ID)
795799
commandUIState.getInput(BIN_SCREW_HOLES_INPUT_ID).isEnabled = generateBase
796800
commandUIState.getInput(BIN_MAGNET_CUTOUTS_INPUT_ID).isEnabled = generateBase
801+
commandUIState.getInput(BIN_MAGNET_CUTOUTS_TABS_INPUT_ID).isEnabled = generateBase
797802
commandUIState.getInput(BIN_MAGNET_DIAMETER_INPUT).isEnabled = generateBase
798803
commandUIState.getInput(BIN_MAGNET_HEIGHT_INPUT).isEnabled = generateBase
799804
commandUIState.getInput(BIN_SCREW_DIAMETER_INPUT).isEnabled = generateBase
@@ -853,6 +858,7 @@ def generateBin(args: adsk.core.CommandEventArgs):
853858
bin_generate_body: adsk.core.BoolValueCommandInput = inputs.itemById(BIN_GENERATE_BODY_INPUT_ID)
854859
bin_magnet_cutouts: adsk.core.BoolValueCommandInput = inputs.itemById(BIN_MAGNET_CUTOUTS_INPUT_ID)
855860
bin_screw_hole_diameter: adsk.core.ValueCommandInput = inputs.itemById(BIN_SCREW_DIAMETER_INPUT)
861+
bin_magnet_cutouts_tabs: adsk.core.BoolValueCommandInput = inputs.itemById(BIN_MAGNET_CUTOUTS_TABS_INPUT_ID)
856862
bin_magnet_cutout_diameter: adsk.core.ValueCommandInput = inputs.itemById(BIN_MAGNET_DIAMETER_INPUT)
857863
bin_magnet_cutout_depth: adsk.core.ValueCommandInput = inputs.itemById(BIN_MAGNET_HEIGHT_INPUT)
858864
with_lip: adsk.core.BoolValueCommandInput = inputs.itemById(BIN_WITH_LIP_INPUT_ID)
@@ -901,6 +907,7 @@ def generateBin(args: adsk.core.CommandEventArgs):
901907
baseGeneratorInput.xyClearance = xyClearance
902908
baseGeneratorInput.hasScrewHoles = bin_screw_holes.value and not isShelled
903909
baseGeneratorInput.hasMagnetCutouts = bin_magnet_cutouts.value and not isShelled
910+
baseGeneratorInput.hasMagnetCutoutsTabs = bin_magnet_cutouts_tabs.value and not isShelled
904911
baseGeneratorInput.screwHolesDiameter = bin_screw_hole_diameter.value
905912
baseGeneratorInput.magnetCutoutsDiameter = bin_magnet_cutout_diameter.value
906913
baseGeneratorInput.magnetCutoutsDepth = bin_magnet_cutout_depth.value

lib/gridfinityUtils/baseGenerator.py

Lines changed: 106 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,67 @@ def createCircleAtPointSketch(
4646
)
4747

4848
return (circleSketch, circle)
49+
50+
def createTabAtCircleEdgeSketch(
51+
plane: adsk.core.Base,
52+
radius: float,
53+
circleCenterPoint: adsk.core.Point3D,
54+
targetComponent: adsk.fusion.Component,
55+
):
56+
circleSketch, circle = createCircleAtPointSketch(
57+
plane,
58+
radius,
59+
circleCenterPoint,
60+
targetComponent,
61+
)
62+
circleCenterOnSketch = geometryUtils.pointToXY(circleSketch.modelToSketchSpace(circleCenterPoint))
63+
angularPointOnSketch = geometryUtils.pointToXY(circleSketch.modelToSketchSpace(
64+
adsk.core.Point3D.create(circleCenterPoint.x + radius, circleCenterPoint.y + radius, circleCenterPoint.z)
65+
))
66+
dimensions: adsk.fusion.SketchDimensions = circleSketch.sketchDimensions
67+
constraints: adsk.fusion.GeometricConstraints = circleSketch.geometricConstraints
68+
sketchUtils.convertToConstruction(circleSketch.sketchCurves)
69+
verticalConstructionLine = circleSketch.sketchCurves.sketchLines.addByTwoPoints(
70+
circleCenterOnSketch,
71+
adsk.core.Point3D.create(circleCenterOnSketch.x, circleCenterOnSketch.y + radius, circleCenterOnSketch.z)
72+
)
73+
verticalConstructionLine.isConstruction = True
74+
diagonalConstructionLine = circleSketch.sketchCurves.sketchLines.addByTwoPoints(
75+
circleCenterOnSketch,
76+
angularPointOnSketch,
77+
)
78+
diagonalConstructionLine.isConstruction = True
79+
constraints.addVertical(verticalConstructionLine)
80+
dimensions.addAngularDimension(
81+
diagonalConstructionLine,
82+
verticalConstructionLine,
83+
angularPointOnSketch,
84+
)
85+
constraints.addCoincident(
86+
verticalConstructionLine.startSketchPoint,
87+
circle.centerSketchPoint,
88+
)
89+
constraints.addCoincident(
90+
verticalConstructionLine.endSketchPoint,
91+
circle,
92+
)
93+
constraints.addCoincident(
94+
diagonalConstructionLine.startSketchPoint,
95+
circle.centerSketchPoint,
96+
)
97+
constraints.addCoincident(
98+
diagonalConstructionLine.endSketchPoint,
99+
circle,
100+
)
101+
circle = circleSketch.sketchCurves.sketchCircles.addByCenterRadius(
102+
diagonalConstructionLine.endSketchPoint,
103+
radius / 2,
104+
)
105+
dimensions.addRadialDimension(
106+
circle,
107+
circleCenterOnSketch,
108+
)
109+
49110
return circleSketch
50111

51112
def createSingleGridfinityBaseBody(
@@ -151,6 +212,26 @@ def createSingleGridfinityBaseBody(
151212
targetComponent,
152213
)
153214
cutoutBodies.add(magnetSocketBody)
215+
216+
# magnet tab cutouts
217+
if input.hasMagnetCutoutsTabs:
218+
magnetTabCutoutSketch = createTabAtCircleEdgeSketch(
219+
baseBottomPlane,
220+
input.magnetCutoutsDiameter / 2,
221+
cutoutCenterPoint,
222+
targetComponent,
223+
)
224+
magnetTabCutoutSketch.name = "Cutout tab sketch"
225+
226+
magnetTabCutoutExtrude = extrudeUtils.simpleDistanceExtrude(
227+
magnetTabCutoutSketch.profiles.item(0),
228+
adsk.fusion.FeatureOperations.NewBodyFeatureOperation,
229+
input.magnetCutoutsDepth,
230+
adsk.fusion.ExtentDirections.NegativeExtentDirection,
231+
[],
232+
targetComponent,
233+
)
234+
cutoutBodies.add(magnetTabCutoutExtrude.bodies.item(0))
154235

155236
if input.hasScrewHoles and (const.BIN_BASE_HEIGHT - input.magnetCutoutsDepth) > const.BIN_MAGNET_HOLE_GROOVE_DEPTH:
156237
grooveBody = shapeUtils.simpleCylinder(
@@ -199,17 +280,31 @@ def createSingleGridfinityBaseBody(
199280
if cutoutBodies.count > 1:
200281
joinFeature = combineUtils.joinBodies(cutoutBodies.item(0), commonUtils.objectCollectionFromList(list(cutoutBodies)[1:]), targetComponent)
201282
cutoutBodies = commonUtils.objectCollectionFromList(joinFeature.bodies)
202-
patternSpacingX = input.baseWidth - const.DIMENSION_SCREW_HOLES_OFFSET * 2
203-
patternSpacingY = input.baseLength - const.DIMENSION_SCREW_HOLES_OFFSET * 2
204-
patternInput = rectangularPatternFeatures.createInput(cutoutBodies,
205-
targetComponent.xConstructionAxis,
206-
adsk.core.ValueInput.createByReal(2),
207-
adsk.core.ValueInput.createByReal(patternSpacingX),
208-
adsk.fusion.PatternDistanceType.SpacingPatternDistanceType)
209-
patternInput.directionTwoEntity = targetComponent.yConstructionAxis
210-
patternInput.quantityTwo = adsk.core.ValueInput.createByReal(2)
211-
patternInput.distanceTwo = adsk.core.ValueInput.createByReal(patternSpacingY)
212-
patternFeature = rectangularPatternFeatures.add(patternInput)
283+
284+
baseXZMidPlaneInput = targetComponent.constructionPlanes.createInput()
285+
baseXZMidPlaneInput.setByOffset(targetComponent.xZConstructionPlane, adsk.core.ValueInput.createByReal(input.baseLength / 2 - input.xyClearance))
286+
baseXZMidPlane = targetComponent.constructionPlanes.add(baseXZMidPlaneInput)
287+
baseXZMidPlane.name = "Base XZ mid plane"
288+
baseXZMidPlane.isLightBulbOn = False
289+
baseYZMidPlaneInput = targetComponent.constructionPlanes.createInput()
290+
baseYZMidPlaneInput.setByOffset(targetComponent.yZConstructionPlane, adsk.core.ValueInput.createByReal(input.baseWidth / 2 - input.xyClearance))
291+
baseYZMidPlane = targetComponent.constructionPlanes.add(baseYZMidPlaneInput)
292+
baseYZMidPlane.name = "Base YZ mid plane"
293+
baseYZMidPlane.isLightBulbOn = False
294+
patternAxisInput = targetComponent.constructionAxes.createInput()
295+
patternAxisInput.setByTwoPlanes(
296+
baseXZMidPlane,
297+
baseYZMidPlane
298+
)
299+
baseCenterAxis = targetComponent.constructionAxes.add(patternAxisInput)
300+
baseCenterAxis.name = "Base center axis"
301+
baseCenterAxis.isLightBulbOn = False
302+
patternInput = circularPatternFeatures.createInput(
303+
cutoutBodies,
304+
baseCenterAxis,
305+
)
306+
patternInput.quantity = adsk.core.ValueInput.createByString("4")
307+
patternFeature = circularPatternFeatures.add(patternInput)
213308
combineUtils.cutBody(baseBody, commonUtils.objectCollectionFromList(list(cutoutBodies) + list(patternFeature.bodies)), targetComponent)
214309

215310
return baseBody

0 commit comments

Comments
 (0)