Adding STL mesh via API moves mesh

Adding STL mesh via API moves mesh

lorang
Explorer Explorer
1,125 Views
4 Replies
Message 1 of 5

Adding STL mesh via API moves mesh

lorang
Explorer
Explorer

Hi-

 

I'm trying to use the API to do something that I think should be pretty simple -- just insert an STL, replicating the "Insert Mesh" button.

 

Taking as an example an STL of a 40 mm cube (attached) that goes from X-20 to X+20, Y-20 to Y+20, and Z0 to Z+40, you'd expect it to be placed such that if you go inspect the corners, you'll get (0,-20,-20), (0, 20, -20), etc. If you insert that cube via the UI, that's exactly what you'll get.

 

If you instead try to do it via the API using the code below, you'll see that inspecting the cube via API gets you those boundaries as well, but if you then go an inspect it in the UI, it's placed somewhere else (and not an even increment, as far as I can tell).

 

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        docs = app.documents
        doc = docs.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        doc.activate()
        design = adsk.fusion.Design.cast(app.activeProduct)
        feature = design.rootComponent.features.baseFeatures.add()
        feature.startEdit()

        meshList = feature.parentComponent.meshBodies.add("C:/40mmcube.stl", adsk.fusion.MeshUnits.MillimeterMeshUnit)
        feature.finishEdit()
        mesh = meshList.item(0)
        coords = mesh.mesh.nodeCoordinatesAsDouble
        xmin = coords[0]       
        ymin = coords[1]
        zmin = coords[2]
        i = 3
        while i < len(coords):
            if xmin > coords[i]:
                xmin = coords[i]
            i += 1
            if ymin > coords[i]:
                ymin = coords[i]
            i += 1
            if zmin > coords[i]:
                zmin = coords[i]
            i += 1
        ui.messageBox('xmin: {}, ymin: {}, zmin: {}'.format(xmin, ymin, zmin))

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

I've tried a million variations on this, and never come up with anything different -- the mesh placed via the API doesn't match to what's placed in the UI, and as far as I can tell I can't identify where it is from the API, so I can't translate it to where it should be.

 

Am I missing something, or should this work?

0 Likes
1,126 Views
4 Replies
Replies (4)
Message 2 of 5

marshaltu
Autodesk
Autodesk

Hello,

 

Thank you for reporting the issue to us. It looked a bug of API and I logged it as UP-37174 in our internal system.

 

The difference between API and UI was the mesh body is scaled to its center in API, while it is scaled to the origin of coordinate system in UI. We will fix the issue in future updates.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
Message 3 of 5

Anonymous
Not applicable

Any updates on this? Is there a workaround?

0 Likes
Message 4 of 5

Anonymous
Not applicable

Hi,

 

Is there an update on this bug? With internal bug number:  UP-37174.

 

Thanks,

 

Gideon

0 Likes
Message 5 of 5

marshaltu
Autodesk
Autodesk

Hello,

 

We have fixed the issue and the fix will be available in mid June update.

 

Thanks,

Marshal 



Marshal Tu
Fusion Developer
>
0 Likes