Community
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.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Applying JPEG image to a face and programmatically change image orientation

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
sophiadoan
168 Views, 8 Replies

Applying JPEG image to a face and programmatically change image orientation

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?

8 REPLIES 8
Message 2 of 9
wmhazzard
in reply to: sophiadoan

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. 

Message 3 of 9
BrianEkins
in reply to: sophiadoan

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
Message 4 of 9
sophiadoan
in reply to: wmhazzard

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!
Message 5 of 9
BrianEkins
in reply to: sophiadoan

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
Message 6 of 9
sophiadoan
in reply to: BrianEkins

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.

Message 7 of 9
sophiadoan
in reply to: BrianEkins

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

Message 8 of 9
kandennti
in reply to: sophiadoan

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()))
Message 9 of 9
sophiadoan
in reply to: kandennti

Wow! it is what I was looking for. 

Thank 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