Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 44 additions & 22 deletions commands/commandCreateBin/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
BIN_SCREW_DIAMETER_INPUT = 'screw_diameter'
BIN_MAGNET_DIAMETER_INPUT = 'magnet_diameter'
BIN_MAGNET_HEIGHT_INPUT = 'magnet_height'
BIN_MAGNET_CHAMFER_XY_INPUT = 'magnet_chamfer_xy'
BIN_MAGNET_CHAMFER_Z_INPUT = 'magnet_chamfer_z'
BIN_HAS_SCOOP_INPUT_ID = 'bin_has_scoop'
BIN_SCOOP_MAX_RADIUS_INPUT_ID = 'bin_scoop_max_radius'
BIN_HAS_TAB_INPUT_ID = 'bin_has_tab'
Expand Down Expand Up @@ -144,6 +146,30 @@ def initDefaultUiState():
global commandUIState
global actualDimensionsTableUiState
global commandCompartmentsTableUIState

commandCompartmentsTableUIState = []
recordedDefaults = configUtils.readJsonConfig(UI_INPUT_DEFAULTS_CONFIG_PATH)
if recordedDefaults is not None and 'static_ui' in recordedDefaults and 'compartments_table' in recordedDefaults:
staticUiState = recordedDefaults['static_ui']
compartmentsTableState = recordedDefaults['compartments_table']
if staticUiState is not None:
futil.log(f'{CMD_NAME} Found previously saved default values, restoring {staticUiState}')

try:
commandUIState.initValues(staticUiState)
futil.log(f'{CMD_NAME} Successfully restored default values')
except Exception as err:
futil.log(f'{CMD_NAME} Failed to restore default values, err: {err}')
if compartmentsTableState is not None and isinstance(compartmentsTableState, list):
futil.log(f'{CMD_NAME} Found previously saving default values for compartments table, restoring {compartmentsTableState}')
try:
for row in compartmentsTableState:
commandCompartmentsTableUIState.append(CommandUiState(CMD_NAME))
commandCompartmentsTableUIState[-1].initValues(row)
futil.log(f'{CMD_NAME} Successfully restored compartments table default values')
except Exception as err:
futil.log(f'{CMD_NAME} Failed to restore default values, err: {err}')

commandUIState.initValue(INFO_GROUP, True, adsk.core.GroupCommandInput.classType())
commandUIState.initValue(BIN_BASIC_SIZES_GROUP, True, adsk.core.GroupCommandInput.classType())
commandUIState.initValue(BIN_DIMENSIONS_GROUP, True, adsk.core.GroupCommandInput.classType())
Expand Down Expand Up @@ -190,29 +216,9 @@ def initDefaultUiState():
commandUIState.initValue(BIN_MAGNET_CUTOUTS_TABS_INPUT_ID, False, adsk.core.BoolValueCommandInput.classType())
commandUIState.initValue(BIN_MAGNET_DIAMETER_INPUT, const.DIMENSION_MAGNET_CUTOUT_DIAMETER, adsk.core.ValueCommandInput.classType())
commandUIState.initValue(BIN_MAGNET_HEIGHT_INPUT, const.DIMENSION_MAGNET_CUTOUT_DEPTH, adsk.core.ValueCommandInput.classType())
commandUIState.initValue(BIN_MAGNET_CHAMFER_XY_INPUT, const.DIMENSION_MAGNET_CUTOUT_CHAMFER_XY, adsk.core.ValueCommandInput.classType())
commandUIState.initValue(BIN_MAGNET_CHAMFER_Z_INPUT, const.DIMENSION_MAGNET_CUTOUT_CHAMFER_Z, adsk.core.ValueCommandInput.classType())

commandCompartmentsTableUIState = []
recordedDefaults = configUtils.readJsonConfig(UI_INPUT_DEFAULTS_CONFIG_PATH)
if recordedDefaults is not None and 'static_ui' in recordedDefaults and 'compartments_table' in recordedDefaults:
staticUiState = recordedDefaults['static_ui']
compartmentsTableState = recordedDefaults['compartments_table']
if staticUiState is not None:
futil.log(f'{CMD_NAME} Found previously saved default values, restoring {staticUiState}')

try:
commandUIState.initValues(staticUiState)
futil.log(f'{CMD_NAME} Successfully restored default values')
except Exception as err:
futil.log(f'{CMD_NAME} Failed to restore default values, err: {err}')
if compartmentsTableState is not None and isinstance(compartmentsTableState, list):
futil.log(f'{CMD_NAME} Found previously saving default values for compartments table, restoring {compartmentsTableState}')
try:
for row in compartmentsTableState:
commandCompartmentsTableUIState.append(CommandUiState(CMD_NAME))
commandCompartmentsTableUIState[-1].initValues(row)
futil.log(f'{CMD_NAME} Successfully restored compartments table default values')
except Exception as err:
futil.log(f'{CMD_NAME} Failed to restore default values, err: {err}')
futil.log(f'{CMD_NAME} UI state initialized')

def getErrorMessage(text = "An unknown error occurred, please validate your inputs and try again"):
Expand Down Expand Up @@ -449,6 +455,8 @@ def is_all_input_valid(inputs: adsk.core.CommandInputs):
bin_screw_hole_diameter: adsk.core.ValueCommandInput = inputs.itemById(BIN_SCREW_DIAMETER_INPUT)
bin_magnet_cutout_diameter: adsk.core.ValueCommandInput = inputs.itemById(BIN_MAGNET_DIAMETER_INPUT)
bin_magnet_cutout_depth: adsk.core.ValueCommandInput = inputs.itemById(BIN_MAGNET_HEIGHT_INPUT)
bin_magnet_cutout_chamfer_xy: adsk.core.ValueCommandInput = inputs.itemById(BIN_MAGNET_CHAMFER_XY_INPUT)
bin_magnet_cutout_chamfer_z: adsk.core.ValueCommandInput = inputs.itemById(BIN_MAGNET_CHAMFER_Z_INPUT)
with_lip: adsk.core.BoolValueCommandInput = inputs.itemById(BIN_WITH_LIP_INPUT_ID)
with_lip_notches: adsk.core.BoolValueCommandInput = inputs.itemById(BIN_WITH_LIP_NOTCHES_INPUT_ID)
has_scoop: adsk.core.BoolValueCommandInput = inputs.itemById(BIN_HAS_SCOOP_INPUT_ID)
Expand Down Expand Up @@ -654,6 +662,14 @@ def command_created(args: adsk.core.CommandCreatedEventArgs):
magnetHeightInput.minimumValue = 0.1
magnetHeightInput.isMinimumInclusive = True
commandUIState.registerCommandInput(magnetHeightInput)
magnetChamferXYInput = baseFeaturesGroup.children.addValueInput(BIN_MAGNET_CHAMFER_XY_INPUT, 'Magnet cutout chamfer XY', defaultLengthUnits, adsk.core.ValueInput.createByReal(commandUIState.getState(BIN_MAGNET_CHAMFER_XY_INPUT)))
magnetChamferXYInput.minimumValue = 0.0
magnetChamferXYInput.isMinimumInclusive = True
commandUIState.registerCommandInput(magnetChamferXYInput)
magnetChamferZInput = baseFeaturesGroup.children.addValueInput(BIN_MAGNET_CHAMFER_Z_INPUT, 'Magnet cutout chamfer Z', defaultLengthUnits, adsk.core.ValueInput.createByReal(commandUIState.getState(BIN_MAGNET_CHAMFER_Z_INPUT)))
magnetChamferZInput.minimumValue = 0.0
magnetChamferZInput.isMinimumInclusive = True
commandUIState.registerCommandInput(magnetChamferZInput)

userChangesGroup = inputs.addGroupCommandInput(USER_CHANGES_GROUP_ID, 'Changes')
userChangesGroup.isExpanded = commandUIState.getState(USER_CHANGES_GROUP_ID)
Expand Down Expand Up @@ -809,6 +825,8 @@ def onChangeValidate():
commandUIState.getInput(BIN_MAGNET_CUTOUTS_TABS_INPUT_ID).isEnabled = generateBase
commandUIState.getInput(BIN_MAGNET_DIAMETER_INPUT).isEnabled = generateBase
commandUIState.getInput(BIN_MAGNET_HEIGHT_INPUT).isEnabled = generateBase
commandUIState.getInput(BIN_MAGNET_CHAMFER_XY_INPUT).isEnabled = generateBase
commandUIState.getInput(BIN_MAGNET_CHAMFER_Z_INPUT).isEnabled = generateBase
commandUIState.getInput(BIN_SCREW_DIAMETER_INPUT).isEnabled = generateBase

generateBody: bool = commandUIState.getState(BIN_GENERATE_BODY_INPUT_ID)
Expand Down Expand Up @@ -869,6 +887,8 @@ def generateBin(args: adsk.core.CommandEventArgs):
bin_magnet_cutouts_tabs: adsk.core.BoolValueCommandInput = inputs.itemById(BIN_MAGNET_CUTOUTS_TABS_INPUT_ID)
bin_magnet_cutout_diameter: adsk.core.ValueCommandInput = inputs.itemById(BIN_MAGNET_DIAMETER_INPUT)
bin_magnet_cutout_depth: adsk.core.ValueCommandInput = inputs.itemById(BIN_MAGNET_HEIGHT_INPUT)
bin_magnet_cutout_chamfer_xy: adsk.core.ValueCommandInput = inputs.itemById(BIN_MAGNET_CHAMFER_XY_INPUT)
bin_magnet_cutout_chamfer_z: adsk.core.ValueCommandInput = inputs.itemById(BIN_MAGNET_CHAMFER_Z_INPUT)
with_lip: adsk.core.BoolValueCommandInput = inputs.itemById(BIN_WITH_LIP_INPUT_ID)
with_lip_notches: adsk.core.BoolValueCommandInput = inputs.itemById(BIN_WITH_LIP_NOTCHES_INPUT_ID)
has_scoop: adsk.core.BoolValueCommandInput = inputs.itemById(BIN_HAS_SCOOP_INPUT_ID)
Expand Down Expand Up @@ -919,6 +939,8 @@ def generateBin(args: adsk.core.CommandEventArgs):
baseGeneratorInput.screwHolesDiameter = bin_screw_hole_diameter.value
baseGeneratorInput.magnetCutoutsDiameter = bin_magnet_cutout_diameter.value
baseGeneratorInput.magnetCutoutsDepth = bin_magnet_cutout_depth.value
baseGeneratorInput.magnetCutoutsChamferXY = bin_magnet_cutout_chamfer_xy.value
baseGeneratorInput.magnetCutoutsChamferZ = bin_magnet_cutout_chamfer_z.value

baseBodies: list[adsk.fusion.BRepBody]
if bin_generate_base.value:
Expand Down
12 changes: 12 additions & 0 deletions lib/gridfinityUtils/baseGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ def createSingleGridfinityBaseBody(
)
cutoutBodies.add(magnetSocketBody)

if input.magnetCutoutsChamferXY > 0 and input.magnetCutoutsChamferZ > 0:
magnetChamferExtrude = extrudeUtils.simpleDistanceExtrude(
faceUtils.getBottomFace(magnetSocketBody),
adsk.fusion.FeatureOperations.JoinFeatureOperation,
input.magnetCutoutsChamferZ,
adsk.fusion.ExtentDirections.PositiveExtentDirection,
[magnetSocketBody],
targetComponent,
-input.magnetCutoutsChamferZ,
math.atan(input.magnetCutoutsChamferXY/input.magnetCutoutsChamferZ),
)

# magnet tab cutouts
if input.hasMagnetCutoutsTabs:
magnetTabCutoutSketch = createTabAtCircleEdgeSketch(
Expand Down
22 changes: 20 additions & 2 deletions lib/gridfinityUtils/baseGeneratorInput.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import adsk.core, adsk.fusion, traceback

from .const import DIMENSION_MAGNET_CUTOUT_DEPTH, DIMENSION_MAGNET_CUTOUT_DIAMETER, DIMENSION_SCREW_HOLE_DIAMETER, BIN_CORNER_FILLET_RADIUS
from .const import DIMENSION_MAGNET_CUTOUT_DEPTH, DIMENSION_MAGNET_CUTOUT_DIAMETER, DIMENSION_SCREW_HOLE_DIAMETER, DIMENSION_MAGNET_CUTOUT_CHAMFER_XY, DIMENSION_MAGNET_CUTOUT_CHAMFER_Z, BIN_CORNER_FILLET_RADIUS

class BaseGeneratorInput():
def __init__(self):
Expand All @@ -10,6 +10,8 @@ def __init__(self):
self.screwHolesDiameter = DIMENSION_SCREW_HOLE_DIAMETER
self.magnetCutoutsDiameter = DIMENSION_MAGNET_CUTOUT_DIAMETER
self.magnetCutoutsDepth = DIMENSION_MAGNET_CUTOUT_DEPTH
self.magnetCutoutsChamferXY = DIMENSION_MAGNET_CUTOUT_CHAMFER_XY
self.magnetCutoutsChamferZ = DIMENSION_MAGNET_CUTOUT_CHAMFER_Z
self.cornerFilletRadius = BIN_CORNER_FILLET_RADIUS

@property
Expand Down Expand Up @@ -98,4 +100,20 @@ def magnetCutoutsDepth(self) -> float:

@magnetCutoutsDepth.setter
def magnetCutoutsDepth(self, value: float):
self._magnetCutoutsDepth = value
self._magnetCutoutsDepth = value

@property
def magnetCutoutsChamferXY(self) -> float:
return self._magnetCutoutsChamferXY

@magnetCutoutsChamferXY.setter
def magnetCutoutsChamferXY(self, value: float):
self._magnetCutoutsChamferXY = value

@property
def magnetCutoutsChamferZ(self) -> float:
return self._magnetCutoutsChamferZ

@magnetCutoutsChamferZ.setter
def magnetCutoutsChamferZ(self, value: float):
self._magnetCutoutsChamferZ = value
2 changes: 2 additions & 0 deletions lib/gridfinityUtils/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
DIMENSION_SCREW_HEAD_CUTOUT_OFFSET_HEIGHT = 0.05
DIMENSION_MAGNET_CUTOUT_DIAMETER = 0.65
DIMENSION_MAGNET_CUTOUT_DEPTH = 0.24
DIMENSION_MAGNET_CUTOUT_CHAMFER_XY = 0.0
DIMENSION_MAGNET_CUTOUT_CHAMFER_Z = 0.0
DIMENSION_PRINT_HELPER_GROOVE_DEPTH = 0.03


Expand Down
7 changes: 6 additions & 1 deletion lib/gridfinityUtils/extrudeUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ def simpleDistanceExtrude(
direction: adsk.fusion.ExtentDirections,
participantBodies: list[adsk.fusion.BRepBody],
targetComponent: adsk.fusion.Component,
offset: float = 0.0,
taperAngle: float = 0.0,
):
features: adsk.fusion.Features = targetComponent.features
extrudeFeatures: adsk.fusion.ExtrudeFeatures = features.extrudeFeatures
extrudeInput = extrudeFeatures.createInput(profile, operation)
extrudeInput.participantBodies = participantBodies
if offset != 0:
startExtent = adsk.fusion.OffsetStartDefinition.create(adsk.core.ValueInput.createByReal(offset))
extrudeInput.startExtent = startExtent
extrudeExtent = adsk.fusion.DistanceExtentDefinition.create(adsk.core.ValueInput.createByReal(distance))
extrudeInput.setOneSideExtent(
extrudeExtent,
direction,
adsk.core.ValueInput.createByReal(0),
adsk.core.ValueInput.createByReal(taperAngle),
)
extrudeFeature = extrudeFeatures.add(extrudeInput)
return extrudeFeature
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/commandUiState.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def removeValue(self, inputId: str):
del self.commandInputs[inputId]

def initValue(self, inputId: str, inputValue: any, inputType: str):
self.inputState[inputId] = SingleInputState(inputId, inputValue, inputType)
if inputId not in self.inputState:
self.inputState[inputId] = SingleInputState(inputId, inputValue, inputType)

def updateValue(self, inputId: str, inputValue: any):
if inputId in self.inputState:
Expand Down