Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to make a script to scale a body using a custom axis.
The idea is to align the body to one of the 3 axes, scale it and then return it to its proper position.
Now since the align tool isn't accessible through the API object model, I used this method below that I saw @BrianEkins used in this post : API access to Align Components Function - Autodesk Community - Fusion 360
ui.activeSelections.clear
ui.activeSelections.add(alignment_edge)
ui.activeSelections.add(rootComp.xConstructionAxis)
alignCommand = ui.commandDefinitions.itemById('AlignGeometryCmd')
alignCommand.execute()
It works like a charm when it's alone, but the moment I make something else it gets ignored, for example, when I try to scale after the alignment, the script only applies the scale in the original position of the body, without the alignment even showing in the timeline ...
I even tried to just create a sketch on the xy plane from the root component, as a completely separate action after the alignment, and the same thing happened, the sketch was created but the alignment was ignored.
Moreover, I even tried the "transaction.Commit" after the alignment to force Fusion to apply it, but no use ...
Any ideas why this is happening???
Thanks in advance.
Here is my code :
import tempfile
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = adsk.fusion.Design.cast(app.activeProduct)
rootComp = design.rootComponent
features = rootComp.features
scales = features.scaleFeatures
alignment_edge_sele = ui.selectEntity('Select BRepEdge entities of any shape', 'Edges')
alignment_edge = alignment_edge_sele.entity
ui.activeSelections.clear
ui.activeSelections.add(alignment_edge)
ui.activeSelections.add(rootComp.xConstructionAxis)
app.executeTextCommand('Transaction.Start Saeed')
alignCommand = ui.commandDefinitions.itemById('AlignGeometryCmd')
alignCommand.execute()
app.executeTextCommand('Transaction.Commit')
xScale = adsk.core.ValueInput.createByReal(0.5)
yScale = adsk.core.ValueInput.createByReal(1.00)
zScale = adsk.core.ValueInput.createByReal(1.00)
point = alignment_edge.startVertex
objcol = adsk.core.ObjectCollection.create()
objcol.add(alignment_edge.body)
factor = adsk.core.ValueInput.createByReal(1.00)
scale_input = scales.createInput(objcol, point, factor)
scale_input.setToNonUniform(xScale, yScale, zScale)
scales.add(scale_input)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Saeed Hamza
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Solved! Go to Solution.