<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Odd bug of Decal API in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/odd-bug-of-decal-api/m-p/13268922#M345</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I was trying to put decals on extruded cuboids, and I found an odd bug.&lt;/P&gt;&lt;P&gt;Depending on the&amp;nbsp;extrude length, DecalInput.tranform is ignored.&lt;/P&gt;&lt;P&gt;As shown in the picture below, 0.6, 0.8, 1.2 mm height are ignored.&lt;/P&gt;&lt;P&gt;1.0 and 1.4 mm height are correctly transformed.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1456442iEA02B318AF4955BE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;LI-CODE lang="python"&gt;import traceback
import sys
import pathlib
import adsk.core as ac
import adsk.fusion as af

IMG_PATH = pathlib.Path(sys.base_prefix).absolute() / 'Python/AddInSamples/CommandSample/commands/Basic/resources/32x32.png'


def run(context):
    app: ac.Application = ac.Application.get()
    try:
        ui = app.userInterface
        test_decal(app)

    except Exception:
        msg = traceback.format_exc()
        print(msg)
        if ui is not None:
            ui.messageBox('Failed:\n{}'.format(msg))


def should_true(x):
    if not x:
        raise Exception()


def create_rectangle_profile(comp: af.Component, x: float, y: float):
    s = comp.sketches.add(comp.xYConstructionPlane)
    should_true(s.sketchCurves.sketchLines.addTwoPointRectangle(
        ac.Point3D.create(-1. + x, -2. + y, 0.),
        ac.Point3D.create(2. + x, 1. + y, 0.)
    ))
    return s.profiles.item(0)


def create_cuboid_body(comp: af.Component, x: float, y: float, h: float):
    profile = create_rectangle_profile(comp, x, y)
    efs = comp.features.extrudeFeatures
    e_in = efs.createInput(profile, af.FeatureOperations.NewBodyFeatureOperation)
    e_in.setOneSideExtent(
        af.DistanceExtentDefinition.create(
            ac.ValueInput.createByReal(h)
        ),
        af.ExtentDirections.PositiveExtentDirection)
    ef = efs.add(e_in)
    return ef.bodies[0]


def test_decal(app: ac.Application):
    # create new doc for testing
    _ = app.documents.add(ac.DocumentTypes.FusionDesignDocumentType)

    # Decal API doesn't work in DirectDesignType
    app.activeProduct.designType = af.DesignTypes.ParametricDesignType

    comp: af.Component = app.activeProduct.rootComponent

    mi = ac.Matrix3D.create()
    mi.setToIdentity()
    z_axis = ac.Vector3D.create(0, 0, 1)

    for iy in range(5):
        y = iy * 4
        for ix in range(1, 7):
            ex_height = (iy + 3) * 0.2
            x = ix * 4

            body = create_cuboid_body(comp, x, y, ex_height)
            face = body.faces[4]  # Upper side of cuboid
            o = ac.Point3D.create(x, y, ex_height)
            base_feature = comp.features.baseFeatures.add()
            should_true(base_feature.startEdit())
            di = comp.decals.createInput(str(IMG_PATH), [face], o)
            trf = di.transform.copy()
            mr = ac.Matrix3D.create()
            mr.setToRotation(1, z_axis, o)
            trf.transformBy(mr)
            di.transform = trf
            di.targetBaseFeature = base_feature
            should_true(base_feature.finishEdit())
            _ = comp.decals.add(di)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 18 Jan 2025 10:22:25 GMT</pubDate>
    <dc:creator>hajime2MRG3</dc:creator>
    <dc:date>2025-01-18T10:22:25Z</dc:date>
    <item>
      <title>Odd bug of Decal API</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/odd-bug-of-decal-api/m-p/13268922#M345</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I was trying to put decals on extruded cuboids, and I found an odd bug.&lt;/P&gt;&lt;P&gt;Depending on the&amp;nbsp;extrude length, DecalInput.tranform is ignored.&lt;/P&gt;&lt;P&gt;As shown in the picture below, 0.6, 0.8, 1.2 mm height are ignored.&lt;/P&gt;&lt;P&gt;1.0 and 1.4 mm height are correctly transformed.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1456442iEA02B318AF4955BE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;LI-CODE lang="python"&gt;import traceback
import sys
import pathlib
import adsk.core as ac
import adsk.fusion as af

IMG_PATH = pathlib.Path(sys.base_prefix).absolute() / 'Python/AddInSamples/CommandSample/commands/Basic/resources/32x32.png'


def run(context):
    app: ac.Application = ac.Application.get()
    try:
        ui = app.userInterface
        test_decal(app)

    except Exception:
        msg = traceback.format_exc()
        print(msg)
        if ui is not None:
            ui.messageBox('Failed:\n{}'.format(msg))


def should_true(x):
    if not x:
        raise Exception()


def create_rectangle_profile(comp: af.Component, x: float, y: float):
    s = comp.sketches.add(comp.xYConstructionPlane)
    should_true(s.sketchCurves.sketchLines.addTwoPointRectangle(
        ac.Point3D.create(-1. + x, -2. + y, 0.),
        ac.Point3D.create(2. + x, 1. + y, 0.)
    ))
    return s.profiles.item(0)


def create_cuboid_body(comp: af.Component, x: float, y: float, h: float):
    profile = create_rectangle_profile(comp, x, y)
    efs = comp.features.extrudeFeatures
    e_in = efs.createInput(profile, af.FeatureOperations.NewBodyFeatureOperation)
    e_in.setOneSideExtent(
        af.DistanceExtentDefinition.create(
            ac.ValueInput.createByReal(h)
        ),
        af.ExtentDirections.PositiveExtentDirection)
    ef = efs.add(e_in)
    return ef.bodies[0]


def test_decal(app: ac.Application):
    # create new doc for testing
    _ = app.documents.add(ac.DocumentTypes.FusionDesignDocumentType)

    # Decal API doesn't work in DirectDesignType
    app.activeProduct.designType = af.DesignTypes.ParametricDesignType

    comp: af.Component = app.activeProduct.rootComponent

    mi = ac.Matrix3D.create()
    mi.setToIdentity()
    z_axis = ac.Vector3D.create(0, 0, 1)

    for iy in range(5):
        y = iy * 4
        for ix in range(1, 7):
            ex_height = (iy + 3) * 0.2
            x = ix * 4

            body = create_cuboid_body(comp, x, y, ex_height)
            face = body.faces[4]  # Upper side of cuboid
            o = ac.Point3D.create(x, y, ex_height)
            base_feature = comp.features.baseFeatures.add()
            should_true(base_feature.startEdit())
            di = comp.decals.createInput(str(IMG_PATH), [face], o)
            trf = di.transform.copy()
            mr = ac.Matrix3D.create()
            mr.setToRotation(1, z_axis, o)
            trf.transformBy(mr)
            di.transform = trf
            di.targetBaseFeature = base_feature
            should_true(base_feature.finishEdit())
            _ = comp.decals.add(di)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jan 2025 10:22:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/odd-bug-of-decal-api/m-p/13268922#M345</guid>
      <dc:creator>hajime2MRG3</dc:creator>
      <dc:date>2025-01-18T10:22:25Z</dc:date>
    </item>
  </channel>
</rss>

