Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Python: Using Scale Features at originConstructionPoint moves bodies.

Message 1 of 3
197 Views, 2 Replies

Python: Using Scale Features at originConstructionPoint moves bodies.

Hello everyone,

I have a small problem when using the ScaleFeature. I want to iterate through all the bodies and then scale them non-uniformly. The point from which I want to scale should always be the origin of the component of the body. However, I have the problem that the bodies are scaled as I want but as soon as the ScaleFeature is executed the bodies move. I think it is either because of my declaration of the origin or because the scaleFeuture.add(...) does more than it should.🤔 But unfortunately, I'm not getting any smarter from this.


I am very grateful for any help and advice!


I have attached the culprit, maybe someone has the time and inclination to look over it!


Kind regards from Leipzig, Germany😊


import adsk.core           
import adsk.fusion
import traceback

def run(context):
    ui = None
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface

        design: adsk.fusion.Design = app.activeProduct
        design.designType = adsk.fusion.DesignTypes.ParametricDesignType
        rootComp: adsk.fusion.Component = design.rootComponent

        for i in range(0, rootComp.allOccurrences.count):
            occ = rootComp.allOccurrences.item(i)   
            # Get the associated component.
            comp = occ.component
            # iterate over bodies
            for j in range(0, comp.bRepBodies.count):
                bodies: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()
                body = comp.bRepBodies.item(j)
                body = body.createForAssemblyContext(occ)

                scalePoint = comp.originConstructionPoint.createForAssemblyContext(occ)
                scaleFactor = adsk.core.ValueInput.createByReal(0.5)
                scaleFeatures = rootComp.features.scaleFeatures
                xScale = adsk.core.ValueInput.createByReal(float(1.55))
                yScale = adsk.core.ValueInput.createByReal(float(1.45))
                zScale = adsk.core.ValueInput.createByReal(float(1.35))
                input = scaleFeatures.createInput(bodies, scalePoint, scaleFactor)
                input.setToNonUniform(xScale, yScale, zScale)
                scaleFeature = scaleFeatures.add(input)



Labels (3)
Message 2 of 3

Hi @Mehrab.Nasrabadi .


You may not have finalized the position of the component after it has been moved. 


How about modifying it like this?

        design: adsk.fusion.Design = app.activeProduct
        design.designType = adsk.fusion.DesignTypes.ParametricDesignType
        rootComp: adsk.fusion.Component = design.rootComponent


        for i in range(0, rootComp.allOccurrences.count):



Message 3 of 3

at first this wasn't a solution for me because i also move the bodies in my script and that doesn't work with the line. but then i just changed my script a bit so that i first move and then scale. and that worked perfectly!

Thank you for your great help and your commitment to the community!

I have another small question, for which it's probably not really worth creating a new post.
It's about the creation of matrices, the setting of their rotation and translation is documented here : But why is there no scaling? I mean I could get the individual positions from the transformation matrix and then multiply them by a scaling factor and then set them back to their position in the matrix (which unfortunately didn't work :D). But in my opinion, the methods of a transformation matrix also include scaling. It feels particularly problematic because fusion or many or possibly all CAD programs make a minimal error in the calculation or creation of transformation matrices and as soon as there is a small error in the input, this information is not accepted and the transformation matrix does not work.
But it is not that important because i have now my way to solve that problem!

Thank you and much love for you ❤️

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th

Autodesk Design & Make Report