Extruding text fails with: RuntimeError: 3 : Some input argument is invalid.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to create different bodies for text embossed in a surface in order to 3d print with multi material.
The following code breaks when using the inward type (outward = False).
The idea is that when I can print multi-material, the text should be on the same surface (not outward). Therefore I want to carve the extrusion out first to avoid any glitches on the top surface, then create a second extrusion that creates new bodies. ex3 ends up in the runtime error.
If I stop at ex2, I can pretty well create this extrusion manually in the design, going downwards and creating 2 new bodies (one for T, one for X).
I can't figure out what is wrong and how to fix it.
import adsk.core, adsk.fusion, adsk.cam, traceback
import os
app: adsk.core.Application = adsk.core.Application.get()
def run(context):
ui = None
try:
for document in app.documents:
if document.name == os.path.basename(__file__):
document.close(False)
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
doc.name = os.path.basename(__file__)
doc.activate()
design: adsk.core.Product = app.activeProduct
targetComponent: adsk.fusion.Component = design.rootComponent
extrudes: adsk.fusion.ExtrudeFeatures = targetComponent.features.extrudeFeatures
fillets: adsk.fusion.FilletFeatures = targetComponent.features.filletFeatures
planes: adsk.fusion.ConstructionPlanes = targetComponent.constructionPlanes
constructionPlane: adsk.fusion.ConstructionPlane = targetComponent.xYConstructionPlane
sketches: adsk.fusion.Sketches = targetComponent.sketches
sketch: adsk.fusion.Sketch = sketches.add(constructionPlane)
baseOrigin: adsk.core.Point3D = sketch.modelToSketchSpace(adsk.core.Point3D.create(0, 0, 0))
print(f"base origin: {dumpPoint3D(baseOrigin)}")
length = LABEL_WIDTH
depth = LABEL_DEPTH
tolerance = 0.000001
sketch.isComputeDeferred = True
lines: adsk.fusion.SketchLines = sketch.sketchCurves.sketchLines
lowerLeft = adsk.core.Point3D.create(0,0,0)
upperRight = adsk.core.Point3D.create(5,1,0)
rectLines = sketch.sketchCurves.sketchLines.addTwoPointRectangle(lowerLeft, upperRight)
profiles1 = adsk.core.ObjectCollection.create()
profiles1.add(sketch.profiles.item(0))
extrudeHeight = 0.4
extrudeHeightValue = adsk.core.ValueInput.createByReal(extrudeHeight)
ex1 = extrudes.addSimple(profiles1, extrudeHeightValue, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
topFace = [face for face in ex1.faces if abs(face.centroid.z - extrudeHeight) <= tolerance][0]
planeInput = planes.createInput()
planeInput.setByOffset(topFace, adsk.core.ValueInput.createByReal(0.0))
textPlane = planes.add(planeInput)
textSketch: adsk.fusion.Sketch = sketches.add(textPlane)
texts = adsk.core.ObjectCollection.create()
textInput = textSketch.sketchTexts.createInput2(f"TX", 0.6)
p1 = textSketch.sketchPoints.add(lowerLeft)
p2 = textSketch.sketchPoints.add(upperRight)
textInput.setAsMultiLine(p1, p2,
adsk.core.HorizontalAlignments.CenterHorizontalAlignment,
adsk.core.VerticalAlignments.MiddleVerticalAlignment, 0)
text: adsk.fusion.SketchText = textSketch.sketchTexts.add(textInput)
texts.add(text)
outward = False
if outward: # works
textHeight = 0.4
textHeightValue = adsk.core.ValueInput.createByReal(textHeight)
ex2 = extrudes.addSimple(texts, textHeightValue, adsk.fusion.FeatureOperations.JoinFeatureOperation)
else:
textHeight = 0.2
textHeightValue = adsk.core.ValueInput.createByReal(-textHeight)
ex2 = extrudes.addSimple(texts, textHeightValue, adsk.fusion.FeatureOperations.CutFeatureOperation)
ex3 = extrudes.addSimple(texts, textHeightValue, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
else:
print('Failed:\n{}'.format(traceback.format_exc()))
I also tried replacing ex3 line with
ex3Input = extrudes.createInput(texts, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
ex3Distance = adsk.fusion.DistanceExtentDefinition.create(textHeightValue)
ex3Input.setOneSideExtent(ex3Distance, adsk.fusion.ExtentDirections.PositiveExtentDirection)
print(ex3Distance.isValid)
print(ex3Input.isValid)
ex3 = extrudes.add(ex3Input)
While this shows True for both isValid prints, the result is the same.
EDITED:
I also tried to switch the extrusions around i.e. first create the new bodies, then try to cut out, setting participantBodies to the bodiy created by ex1, but I'm getting the same error.
I also get the same error when I simply duplicate the ex3 line - what ever this is (Cut or NewBody). The second extrusion with the same profile always fails.
If this is an API bug, what would be a good option to work around this?
Thanks