Message 1 of 6
Scaling a Body in a Component
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Just wanted to preface this by saying I am very new to writing scripts and python, so my mistake could be a very obvious one.
import adsk.core, adsk.fusion, traceback def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface # Create a document. # doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType) design = adsk.fusion.Design.cast(app.activeProduct) # Get root component in this design rootComp = design.rootComponent # Create sketch # sketches = rootComp.sketches # sketch = sketches.add(rootComp.xZConstructionPlane) # sketchCircles = sketch.sketchCurves.sketchCircles # centerPoint = adsk.core.Point3D.create(0, 0, 0) # circle = sketchCircles.addByCenterRadius(centerPoint, 5.0) # Get the profile defined by the circle # prof = sketch.profiles.item(0) # Create an extrusion input # extrudes = rootComp.features.extrudeFeatures # extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation) # Define that the extent is a distance extent of 5 cm # distance = adsk.core.ValueInput.createByReal(5) # extInput.setDistanceExtent(False, distance) # Create the extrusion # ext = extrudes.add(extInput) # Get the first component occs = rootComp.occurrences subComp1 =occs.item(0).component # Get the first body in sub component 1 body = subComp1.bRepBodies.item(0) # Create a scale input inputColl = adsk.core.ObjectCollection.create() inputColl.add(body) basePt = adsk.core.Point3D.create(0, 0, 0) scaleFactor = adsk.core.ValueInput.createByReal(2) scales = rootComp.features.scaleFeatures scaleInput = scales.createInput(inputColl, basePt, scaleFactor) # Set the scale to be non-uniform xScale = adsk.core.ValueInput.createByReal(2) yScale = adsk.core.ValueInput.createByReal(1) zScale = adsk.core.ValueInput.createByReal(2) scaleInput.setToNonUniform(xScale, yScale, zScale) scale = scales.add(scaleInput) # Create another sketch # sketchVertical = sketches.add(rootComp.yZConstructionPlane) # sketchCirclesVertical = sketchVertical.sketchCurves.sketchCircles # centerPointVertical = adsk.core.Point3D.create(0, 10, 0) # cicleVertical = sketchCirclesVertical.addByCenterRadius(centerPointVertical, 5) # # Create an uniformed input for scale feature input # inputUniformColl = adsk.core.ObjectCollection.create() # inputUniformColl.add(sketchVertical) # scaleUniformInput = scales.createInput(inputUniformColl, basePt, scaleFactor) # scaleUniform = scales.add(scaleUniformInput) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
I've by trying to scale up a body that is inside of a component, but every time I run this script (based off of this example) I receive the error below.
What am I doing wrong? I used the "Get the first component" and "Get the first body in sub component 1" for the moveFeature, but this does not appear to work for the scaleFeature.