Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

[Bug] Wrong translation of plane using plane.transform in base feature

JeromeBriot
Mentor

[Bug] Wrong translation of plane using plane.transform in base feature

JeromeBriot
Mentor
Mentor

Hello,

 

I think that this bug is the same as the one reported 5 years ago in this discussion: Creating sketch from baseFeature - aka not parametric - fail to update transform


The following code try to translate a plane according to a direction:

  • If direction is set to X => translation of the plane YZ
  • If direction is set to Y => translation of the plane XZ
  • If direction is set to Z => translation of the plane XY

But if direction is set to 'X' or 'Y', the translation of the plane is incorrect.

 

  • For 'X', instead of translating the YZ plane in the X direction, it translates the XY plane in the X direction
  • For 'Y', instead of translating the XZ plane in the Y direction, it translates the XY plane in the Y direction

 

import adsk.core, adsk.fusion, traceback

def run(context):

    try:

        direction = 'X'

        app = adsk.core.Application.get()

        ui = app.userInterface

        design = adsk.fusion.Design.cast(app.activeProduct)

        rootComponent = design.rootComponent

        baseFeats = rootComponent.features.baseFeatures
        baseFeat = baseFeats.add()
        baseFeat.startEdit()

        planes = rootComponent.constructionPlanes
        planeInput = planes.createInput()

        planeInput.targetBaseOrFormFeature = baseFeat

        offset = adsk.core.ValueInput.createByReal(0.0)

        if direction.lower() == 'x':
            refPlane = rootComponent.yZConstructionPlane
        elif direction.lower() == 'y':
            refPlane = rootComponent.xZConstructionPlane
        elif direction.lower() == 'z':
            refPlane = rootComponent.xYConstructionPlane

        planeInput.setByOffset(refPlane, offset)

        plane = planes.add(planeInput)

        transform = adsk.core.Matrix3D.create()
        vector = adsk.core.Vector3D.create(0.0, 0.0, 0.0)

        if direction.lower() == 'x':
            vector.x = 10
        elif direction.lower() == 'y':
            vector.y = 10
        elif direction.lower() == 'z':
            vector.z = 10

        transform.translation = vector
        plane.transform = transform

        baseFeat.finishEdit()

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 Thank you

 

0 Likes
Reply
Accepted solutions (1)
721 Views
4 Replies
Replies (4)

kandennti
Mentor
Mentor

Hi @JeromeBriot .

 

The "transform" works correctly if you get it from plane.transform instead of Matrix3D.create method.

・・・
        plane = planes.add(planeInput)

        # transform = adsk.core.Matrix3D.create()
        transform = plane.transform # <- here

        vector = adsk.core.Vector3D.create(0.0, 0.0, 0.0)

        if direction.lower() == 'x':
            vector.x = 10
・・・
1 Like

JeromeBriot
Mentor
Mentor

@kandennti  a écrit :

The "transform" works correctly if you get it from plane.transform instead of Matrix3D.create method.


Thank you @kandennti

Your workaround works perfectly. Bravo ! 👏

 

 The bug still exists. Or at least a lack of information in the documentation. @BrianEkins : any ideas ?

 

 

1 Like

BrianEkins
Mentor
Mentor
Accepted solution

This was a good question and caused me to learn something.

 

You can think of a construction plane as a coordinate system.  The face of the plane is its X-Y plane and Z is normal to the plane. The transform returned by the plane's transform property is defining the current position and orientation of the plane.  Setting this property redefines the transform.

 

If you create a new construction plane parallel to the root Y-Z plane and a zero offset, it is the special case where its current position and orientation are defined by an identity matrix.  A plane on the Y-Z has a transformation matrix like this:

 

0.0 0.0 1.0 0.0

1.0 0.0 0.0 0.0

0.0 1.0 0.0 0.0

0.0 0.0 0.0 1.0

 

You can see it's X direction is in (0, 1, 0), it's Y direction is in (0, 0, 1), it's Z direction is in (1, 0, 0), and it's translation is zero.

 

In the initial sample, code it's starting with an identity matrix, which is what's created when you create a new Matrix3D object, and then it's setting the translation part of the matrix. This has the effect of reorienting any plane to lie on the model X-Y plane.  To do what you were originally doing, you need to get the original transform and then apply the desired translation.  For this to work in a general case where there might already be some translation to the plane you would do something like this to translate it 5 cm in the X direction:

 

# Define the transform to apply.
transMatrix = adsk.core.Matrix3D.create()
transMatrix.translation = adsk.core.Vector3D.create(5.0, 0.0, 0.0)

# Get the current transform that defines the plane's position and orientation.
planeTransform = constPlane.transform

# Multiply the current transform with the desired change.
planeTransform.transformBy(transMatrix)

# Apply the new transform to the plane.
constPlane.transform = planeTransform

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
2 Likes

JeromeBriot
Mentor
Mentor

Thank you @BrianEkins. It's cristal clear now.

 

0 Likes