Reproducible crash when adding attribute to face in direct edit mode

Reproducible crash when adding attribute to face in direct edit mode

JesusFreke
Advocate Advocate
286 Views
1 Reply
Message 1 of 2

Reproducible crash when adding attribute to face in direct edit mode

JesusFreke
Advocate
Advocate

The below script seems like it should be fine, but it causes fusion 360 to hang for a couple of seconds and then crash.

 

import adsk.core
import adsk.fusion
import traceback

app = adsk.core.Application.get()
root = adsk.core.Application.get().activeProduct.rootComponent

def _create_component(parent_component, *bodies, name):
    new_occurrence = parent_component.occurrences.addNewComponent(adsk.core.Matrix3D.create())
    new_occurrence.component.name = name
    for body in bodies:
        new_occurrence.component.bRepBodies.add(body)
    return new_occurrence


def box(x, y, z, *, name="Box") -> adsk.fusion.Occurrence:
    box_body = adsk.fusion.TemporaryBRepManager.get().createBox(adsk.core.OrientedBoundingBox3D.create(
        adsk.core.Point3D.create(x/2, y/2, z/2),
        adsk.core.Vector3D.create(1, 0, 0),
        adsk.core.Vector3D.create(0, 1, 0),
        x, y, z))
    occurrence = _create_component(root, box_body, name=name)
    return occurrence


def run(context):
    try:
        app.activeProduct.designType = adsk.fusion.DesignTypes.DirectDesignType
        first = box(1, 1, 1, name="first")
        first.bRepBodies[0].faces[0].attributes.add("namespace", "name", "value")
    except:
        traceback.print_exc()

The crash occurs at the last line of run(), where it tries to add an attribute to a face. The crash doesn't happen in parametric mode (with _create_component using a base feature to add the body to the new component, of course).

 

0 Likes
287 Views
1 Reply
Reply (1)
Message 2 of 2

JesusFreke
Advocate
Advocate

I played around with this a bit more, and it seems like this only occurs for bodies that were created with the TemporaryBRepManager and then added to a component.

 

 

I did find a workaround at least. You can temporarily go into parametric mode just before adding the temporary body to the component, add the body in the context of a base feature, and then go back into direct mode immediately afterward. Afterwards, you can set an attribute on one of the body's faces without triggering the crash.

 

def _create_component(parent_component, *bodies, name):
    app.activeProduct.designType = adsk.fusion.DesignTypes.ParametricDesignType
    new_occurrence = parent_component.occurrences.addNewComponent(adsk.core.Matrix3D.create())
    base_feature = new_occurrence.component.features.baseFeatures.add()
    base_feature.startEdit()
    new_occurrence.component.name = name
    for body in bodies:
        new_occurrence.component.bRepBodies.add(body, base_feature)
    base_feature.finishEdit()
    app.activeProduct.designType = adsk.fusion.DesignTypes.DirectDesignType
    return new_occurrence
0 Likes