Custom Feature Dependency Issues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've created a custom feature that makes box joint fingers. Essentialy, you pick a face, start point and end point and it will make fingers from the start point to the endpoint along the face. I make a temporary BRepBody as the cut tool (the fingers) and cut it from the param body (the BRepBody of the face). My issue arises when I try and save the points and face as dependencies of the feature. My selection inputs are configured like this:
_placementFaceSelectInput = placementGroup.children.addSelectionInput(Constants.COMMAND_INPUT_ID_PLACEMENT_FACE, 'Face', 'Select the face to cut finger joints from.')
_placementFaceSelectInput.tooltip = 'Select the face to cut finger joints from.'
_placementFaceSelectInput.addSelectionFilter('PlanarFaces')
_placementFaceSelectInput.setSelectionLimits(1,1)
_placementStartPointSelectInput = placementGroup.children.addSelectionInput(Constants.COMMAND_INPUT_ID_PLACEMENT_START_POINT, 'Start Point', 'Select the point to start the joint at.')
_placementStartPointSelectInput.tooltip = 'Select the point to start the joint at.'
_placementStartPointSelectInput.addSelectionFilter('Vertices')
_placementStartPointSelectInput.addSelectionFilter('SketchPoints')
_placementStartPointSelectInput.addSelectionFilter('ConstructionPoints')
_placementStartPointSelectInput.setSelectionLimits(1,1)
_placementEndPointSelectInput = placementGroup.children.addSelectionInput(Constants.COMMAND_INPUT_ID_PLACEMENT_END_POINT, 'End Point', 'Select the point to end the joint at.')
_placementEndPointSelectInput.tooltip = 'Select the point to end the joint at.'
_placementEndPointSelectInput.addSelectionFilter('Vertices')
_placementEndPointSelectInput.addSelectionFilter('SketchPoints')
_placementEndPointSelectInput.addSelectionFilter('ConstructionPoints')
_placementEndPointSelectInput.setSelectionLimits(1,1)
My Execution handler looks like this:
eventArgs = adsk.core.CommandEventArgs.cast(args)
# Get the settings from the inputs.
model = getFingerJointModelFromInputs()
# Create a base feature and add the body.
paramBody = model.face.body
component = paramBody.parentComponent
# Create the tool representing the fingers
fingerBody = CreateFingers(model)
# Execute the feature
baseFeat = component.features.baseFeatures.add()
baseFeat.startEdit()
component.bRepBodies.add(fingerBody, baseFeat)
baseFeat.finishEdit()
# Create a combine feature to subtract the fingerjoint body from the part.
combineFeature = None
toolBodies = adsk.core.ObjectCollection.create()
toolBodies.add(baseFeat.bodies.item(0))
combineInput = component.features.combineFeatures.createInput(paramBody, toolBodies)
combineInput.operation = adsk.fusion.FeatureOperations.CutFeatureOperation
combineFeature = component.features.combineFeatures.add(combineInput)
# Create the custom feature input.
des: adsk.fusion.Design = _app.activeProduct
lengthUnits = des.unitsManager.defaultLengthUnits
custFeatInput = component.features.customFeatures.createInput(_customFeatureDef)
# I add a whole heap of feature parameters here this has been cut out for brevity.
# ......
# Add dependencies
custFeatInput.addDependency(Constants.COMMAND_INPUT_ID_PLACEMENT_FACE, _placementFaceSelectInput.selection(0).entity)
custFeatInput.addDependency(Constants.COMMAND_INPUT_ID_PLACEMENT_START_POINT, _placementStartPointSelectInput.selection(0).entity)
custFeatInput.addDependency(Constants.COMMAND_INPUT_ID_PLACEMENT_END_POINT, _placementEndPointSelectInput.selection(0).entity)
custFeatInput.setStartAndEndFeatures(baseFeat, combineFeature)
component.features.customFeatures.add(custFeatInput)
By the time the script gets to the point of saving the dependencies they are no longer valid. I.e. the vertex used by start/endpoint have been removed by the cut operation... or the face Id has changed due to being altered by the cut opperation. For example, _placementFaceSelectInput.Selection count is still 1, but it's entity is None and the selection isValid is False. I've tried saving the dependencies before making the cut operation but I get an error about the dependencies being invalid when I add the custom feature to the component. I get a similar issue when the validation handler is called. My preview handler makes the cut using the toolbody. But then the Selection Inputs are no longer valid by the time the input validation handler is called. Any help with this would be great!