Script - Discrepancy in the precision length, height and width
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I've recently begun experimenting with scripting for Fusion 360, focusing on simple tasks like extracting component or body dimensions such as Length, Height, and Width. I think I've successfully retrieved these dimensions, but I've noticed a discrepancy in the precision of the values displayed by the script (see attached image) compared to when they are inspected directly within the Fusion 360 design.
Here are the body dimensions (in Design):
- Length: 200.0 mm
- Width: 150.00 mm
- Height: 300.00 mm
import traceback
import adsk.fusion
import adsk.core
def run(context):
ui = adsk.core.UserInterface.cast(None)
try:
app: adsk.fusion.Application = adsk.core.Application.get()
ui = app.userInterface
des: adsk.fusion.Design = app.activeProduct
comp: adsk.fusion.Component = des.activeComponent
mMgr:adsk.core.MeasureManager = app.measureManager
OBBox: adsk.core.OrientedBoundingBox3D = mMgr.getOrientedBoundingBox(
comp.bRepBodies[0],
comp.yConstructionAxis.geometry.direction,
comp.xConstructionAxis.geometry.direction)
unitsMgr: adsk.core.UnitsManager = des.unitsManager
defLenUnit = unitsMgr.defaultLengthUnits
ratio = unitsMgr.convert(1, unitsMgr.internalUnits, defLenUnit)
msg = [
f'length : {OBBox.length * ratio} {defLenUnit}',
f'width : {OBBox.width * ratio} {defLenUnit}',
f'height : {OBBox.height * ratio} {defLenUnit}',
]
ui.messageBox('\n'.join(msg))
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))