Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Applying JPEG image to a face and programmatically change image orientation

sophiadoan
Contributor

Applying JPEG image to a face and programmatically change image orientation

sophiadoan
Contributor
Contributor

Is there a way we can add JPEG image to a face and programmatically change image orientation?

The image will take on the shape of the face. With respect to the face, can we move and rotate the image?

0 Likes
Reply
Accepted solutions (1)
487 Views
8 Replies
Replies (8)

wmhazzard
Advisor
Advisor

I assume that you are talking about a decal. As far as I know neither decal or canvas are parametric so your answer is no. 

0 Likes

BrianEkins
Mentor
Mentor

Unfortunately, the decal functionality is not currently supported by the API. It is a known limitation but has been a low priority because there haven't been any requests for it. I think yours is the first.

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

sophiadoan
Contributor
Contributor
BrianEkins
<> on
this post
https://forums.autodesk.com/t5/fusion-360-api-and-scripts/fusion-c-appearance-rotation/m-p/11497005#...
stated that we can now change the applied appearance's orientation so I am
looking at creating a custom material using a JPEG image and apply to a
face then change the position (Offset and Rotation) of that material.
Although, I am not sure if we can do this without changing the position
settings of the material in the library, but just change the instance of
that material that is already a part of the face appearance.
Thank you so much for your help, I love this forum, so responsive!
0 Likes

BrianEkins
Mentor
Mentor

Applying a JPEG to a face uses the "Decal" command in Fusion. This is different than applying an appearance. Appearances are supported by the API but decals are not. If you can figure out how to do what you want with appearances, you should be able to automate it. I suggest working with Fusion interactively to better understand how it behaves with appearances and decals,.

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

sophiadoan
Contributor
Contributor
I played with Fusion Texture Editor last night and was able to achieve
what I wanted. Three things I changed:
1. The scale of the image to retain the actual size of the image since it
represents a real material such as wood veneer that has been scanned into
JPEG image.
2. The position of the image
3. Setting Horizontal and Vertical Repeat to none in order to show the
image only on one surface.

According to
https://forums.autodesk.com/t5/fusion-360-api-and-scripts/fusion-c-appearance-rotation/m-p/11497005#...

Brian points me to an API that I will try to see if all three tasks can be
done.

0 Likes

sophiadoan
Contributor
Contributor

Using the Material Browser, I created a material with some JPEG image and then in code, I applied that material to a face as follow (this works):

    # Get the currently selected entity.
    selObj = ui.activeSelections.item(0)
    # Check to see if it's a face.
    if selObj.entity.objectType == fus.BRepFace.classType():
        fav = app.favoriteAppearances
        wood = fav.itemByName('MyWoodAppearance')
        face = fus.BRepFace.cast(selObj.entity)
        face.appearance = wood

 Now that a selected face has an appearance applied, I use the following to move the appearance 1 cm in the Y direction, but the last line caused an exception. What did I do wrong?

if selObj.entity.objectType == fus.BRepFace.classType():
        face = fus.BRepFace.cast(selObj.entity)
        texture = face.body.textureMapControl
        if texture.objectType == adsk.core.ProjectedTextureMapControl.classType():
            texture3D: adsk.core.ProjectedTextureMapControl = texture
            # Define a matrix that will move the body 1 cm in the Y direction.
            vector = adsk.core.Vector3D.create(0.0, 1.0, 0.0)
            transform = adsk.core.Matrix3D.create()
            transform.translation = vector
            texture3D.transform = transform

0 Likes

kandennti
Mentor
Mentor
Accepted solution

Hi @sophiadoan .

 

I tried a few things.
It looks like the projectedTextureMapType needs to be BoxTextureMapProjection.

Also, I have a feeling that Matrix3D.translation is not working, though I am not sure myself.

 

Every time I ran the following script, the attached f3d file texture moved.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core


def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        body: adsk.fusion.BRepBody = root.bRepBodies[0]

        textureMapControl: adsk.core.ProjectedTextureMapControl = body.textureMapControl

        textureMapControl.projectedTextureMapType = adsk.core.ProjectedTextureMapTypes.BoxTextureMapProjection

        mat: adsk.core.Matrix3D = textureMapControl.transform
        origin, xAxis, yAxis, zAxis = mat.getAsCoordinateSystem()
        vec: adsk.core.Vector3D = adsk.core.Vector3D.create(0.0, 1.0, 0.0)
        origin.translateBy(vec)
        mat.setWithCoordinateSystem(origin, xAxis, yAxis, zAxis)
        textureMapControl.transform = mat
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes

sophiadoan
Contributor
Contributor

Wow! it is what I was looking for. 

Thank you

1 Like