Adding STL mesh via API moves mesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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?