Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi guys, total beginner writing scripts here.
I'm trying to copy, move and rotate a body and then scale the new body in its new position. I didn't have much trobule moving it a few inches in the x axis and rotating it 90 degrees (see screenshot) but I've been stuck for hours trying to scale it. I get RuntimeError: 2 : InternalValidationError : Utils::getObjectPath(obj.get(), objPath, nullptr, path) (line 80). I'm totally lost here, I'd really appreciate some input.
Thanks!
import adsk.core, adsk.fusion, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
if not design:
ui.messageBox('No active Fusion design', 'No Design')
return
# Get the root component of the active design.
rootComp = design.rootComponent
features = rootComp.features
# Get the first sub component
occs = rootComp.occurrences
subComp1 = occs.item(0).component
# Create sketch
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xYConstructionPlane)
sketchCircles = sketch.sketchCurves.sketchCircles
centerPoint = adsk.core.Point3D.create(0, 0, 0)
circle = sketchCircles.addByCenterRadius(centerPoint, 1.5)
# Get the first body in sub component 1
baseBody = subComp1.bRepBodies.item(0)
# Copy/paste bodies
subComp1.features.copyPasteBodies.add(baseBody)
# Rename Body
baseBodyCopy = subComp1.bRepBodies.item(1)
# Create a collection of entities for move
bodies = adsk.core.ObjectCollection.create()
bodies.add(baseBodyCopy)
# Create a transform to do move
vector = adsk.core.Vector3D.create(5, 0, 0)
transform = adsk.core.Matrix3D.create()
transform.translation = vector
# Create a move feature
# moveFeats = features.moveFeatures
moveFeats = subComp1.features.moveFeatures
moveFeatureInput = moveFeats.createInput(bodies, transform)
moveFeats.add(moveFeatureInput)
# Create a transform to do rotation
transform = adsk.core.Matrix3D.create()
rotPoint= adsk.core.Point3D.create()
rotPoint = adsk.core.Point3D.create(5, 0, 0)
transform.setToRotation(3.1416,(rootComp.zConstructionAxis.geometry.getData()[2]),rotPoint)
# Create a move feature
moveFeats = subComp1.features.moveFeatures
moveFeatureInput = moveFeats.createInput(bodies, transform)
moveFeats.add(moveFeatureInput)
inputColl = adsk.core.ObjectCollection.create()
inputColl.add(baseBody)
basePt = sketch.sketchPoints.item(0)
scaleFactor = adsk.core.ValueInput.createByReal(1)
scales = rootComp.features.scaleFeatures
scaleInput = scales.createInput(bodies, basePt, scaleFactor)
#Set the scale to be non-uniform
xScale = adsk.core.ValueInput.createByReal(1.5)
yScale = adsk.core.ValueInput.createByReal(3)
zScale = adsk.core.ValueInput.createByReal(2)
scaleInput.setToNonUniform(xScale, yScale, zScale)
scale = scales.add(scaleInput)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.