Odd bug of Decal API

Odd bug of Decal API

hajime2MRG3
Enthusiast Enthusiast
299 Views
0 Replies
Message 1 of 1

Odd bug of Decal API

hajime2MRG3
Enthusiast
Enthusiast

Hello,

I was trying to put decals on extruded cuboids, and I found an odd bug.

Depending on the extrude length, DecalInput.tranform is ignored.

As shown in the picture below, 0.6, 0.8, 1.2 mm height are ignored.

1.0 and 1.4 mm height are correctly transformed.

Untitled.png

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)

 

0 Likes
300 Views
0 Replies
Replies (0)