Message 1 of 3
Flipping Joint
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
# Copyright (c) 2023 Brad Bylls
# Used to create multiple simple rigid joints
import adsk.core
import adsk.fusion
import adsk.cam
# Import the entire apper package
from ..apper import apper
# Globals
_app = adsk.core.Application.get()
_ui = _app.userInterface
tools = adsk.core.ObjectCollection.create()
targets = adsk.core.ObjectCollection.create()
class QuickJoints(apper.Fusion360CommandBase):
def validate_inputs(self, command, inputs, args, input_values) -> bool:
global tools, targets
if tools.count == targets.count:
return True
else:
return False
# =========================================================================== #
def on_input_changed(self, command, inputs, changed_input, input_values):
global tools, targets
if changed_input.id == 'component':
toolSelectionInput = inputs.itemById('component')
tool = tools.add(toolSelectionInput)
inputs.itemById('target').isEnabled = True
elif changed_input.id == 'target':
targetSelectionInput = inputs.itemById('target')
target = targets.add(targetSelectionInput)
inputs.itemById('component').isEnabled = True
# =========================================================================== #
def on_create(self, command, inputs):
global root, comp
design = _app.activeProduct
root = design.rootComponent
comp = design.activeComponent
# Verify that a Fusion design is active.
if not design:
_ui.messageBox('A Fusion design must be active when invoking this command.')
return()
command.okButtonText = ("Create the Joints") # text in "OK" button
command.isExecutedWhenPreEmpted = False
# Create the command dialog
_inputSelectTargets = inputs.addSelectionInput('component', 'Component Snap', 'Select the First Component Edge')
_inputSelectTargets.addSelectionFilter(adsk.core.SelectionCommandInput.Edges)
_inputSelectTargets.setSelectionLimits(0)
_inputSelectTools = inputs.addSelectionInput('target', 'Target Snap', 'Select the Second Component Target')
_inputSelectTools.addSelectionFilter(adsk.core.SelectionCommandInput.SketchPoints)
_inputSelectTools.addSelectionFilter(adsk.core.SelectionCommandInput.CircularEdges)
_inputSelectTools.setSelectionLimits(0)
_inputErrMessage = inputs.addTextBoxCommandInput('errMessage', '', 'Component and Target\nMust be equal count.', 2, True)
_inputErrMessage.isFullWidth = True
# =========================================================================== #
def on_execute(self, command, inputs, args, input_values):
componentList = []
component_input: adsk.core.SelectionCommandInput = inputs.itemById('component')
for idx in range(0, component_input.selectionCount):
componentList.append(component_input.selection(idx).entity)
target_input: adsk.core.SelectionCommandInput = inputs.itemById('target')
for idx in range(0, target_input.selectionCount):
targets = target_input.selection(idx).entity
components = componentList[idx]
if targets.objectType == 'adsk::fusion::BRepEdge':
component = adsk.fusion.JointGeometry.createByCurve(components, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)
target = adsk.fusion.JointGeometry.createByCurve(targets, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)
joints = comp.joints
jointInput = joints.createInput(component, target)
joint = joints.add(jointInput)
else:
component = adsk.fusion.JointGeometry.createByCurve(components, adsk.fusion.JointKeyPointTypes.CenterKeyPoint)
target = adsk.fusion.JointGeometry.createByPoint(targets)
joints = comp.joints
jointInput = joints.createInput(component, target)
joint = joints.add(jointInput)
comp.isJointsFolderLightBulbOn = False
# =========================================================================== #
# This function will be called when the user completes the command.
def command_destroy(args: adsk.core.CommandEventArgs):
global local_handlers
local_handlers = []
# =========================================================================== #
Brad Bylls