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?
Solved! Go to Solution.
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?
Solved! Go to Solution.
Solved by kandennti. Go to Solution.
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.
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.
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.
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.
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,.
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,.
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
s
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
s
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()))
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()))
Wow! it is what I was looking for.
Thank you
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.