Message 1 of 3
Problem extruding multiple faces in a row
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to make a box smaller by extruding each of its faces inwards (cutting) by different amounts. I let the user select each face first (can hopefully automate most of this selection work later) and the do the extrudes on the faces. The problem is that after one or a few extrudes I get an error:
RuntimeError: 2 : InternalValidationError : input
The strange thing is that it varies how many extrudes that succeeds, even for the same input values and selections.
Any ideas?
Here is the code:
#Author-
#Description-
import adsk.core, adsk.fusion, adsk.cam, traceback
def extrude_face(
face: adsk.fusion.BRepFace,
distanceExpression: str,
name: str = ''
) -> adsk.fusion.ExtrudeFeature:
"""
Make a box smaller by extruding the sides inwards.
"""
app = adsk.core.Application.get()
design = app.activeProduct
rootComp = design.rootComponent
distance = adsk.core.ValueInput.createByString(distanceExpression)
# Create the extrusion.
extrudes: adsk.fusion.ExtrudeFeatures = rootComp.features.extrudeFeatures
ext = extrudes.addSimple(
face, distance, adsk.fusion.FeatureOperations.CutFeatureOperation
)
ext.name = name
return ext
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
faces = []
faces.append(
ui.selectEntity('Select the front face', 'PlanarFaces').entity
)
faces.append(
ui.selectEntity('Select the top face', 'PlanarFaces').entity
)
faces.append(
ui.selectEntity('Select the back face', 'PlanarFaces').entity
)
faces.append(
ui.selectEntity('Select the bottom face', 'PlanarFaces').entity
)
faces.append(
ui.selectEntity('Select the left face', 'PlanarFaces').entity
)
faces.append(
ui.selectEntity('Select the right face', 'PlanarFaces').entity
)
extrude_face(
faces[0], '-10 mm', name='Front'
)
extrude_face(faces[1], '-10 mm', name='Top')
extrude_face(faces[2], '-20 mm', name='Back')
extrude_face(
faces[3], '-10 mm', name='Bottom'
)
extrude_face(faces[4], '-15 mm', name='Left')
extrude_face(
faces[5], '-5 mm', name='Right'
)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))