To measure the minimum distance between the top face and its opposite face without manual selection, you can use the following modified code. This code will automatically select the top face and its opposite face and then measure the minimum distance between them.
```python
import adsk.core
import adsk.fusion
import os
import traceback
def run(context):
ui: adsk.core.UserInterface = adsk.core.UserInterface.cast(None)
try:
stpFileName = r'C:/Test_step/350B1350.stp'
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
des: adsk.fusion.Design = app.activeProduct
root: adsk.fusion.Component = des.rootComponent
importManager: adsk.core.ImportManager = app.importManager
stpOptions: adsk.core.STEPImportOptions = importManager.createSTEPImportOptions(stpFileName)
importManager.importToTarget(stpOptions, root)
# Find the top face
topFace = None
for comp in root.allComponents:
for face in comp.bRepFaces:
if topFace is None or face.boundingBox.maxPoint.z > topFace.boundingBox.maxPoint.z:
topFace = face
if topFace is None:
ui.messageBox('No top face found.')
return
# Find the opposite face (lowest face)
oppositeFace = None
for comp in root.allComponents:
for face in comp.bRepFaces:
if oppositeFace is None or face.boundingBox.minPoint.z < oppositeFace.boundingBox.minPoint.z:
oppositeFace = face
if oppositeFace is None:
ui.messageBox('No opposite face found.')
return
measMgr: adsk.core.MeasureManager = app.measureManager
res: adsk.core.MeasureResults = measMgr.measureMinimumDistance(
topFace,
oppositeFace,
)
unitsMgr: adsk.core.UnitsManager = des.unitsManager
ui.messageBox('Minimum Distance: {}'.format(unitsMgr.formatInternalValue(res.value)))
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
```
i wrote this code for automate but is showing error if you can help me please help