Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting Depth, Diameter, and TipAngle of a HoleFeature

0 REPLIES 0
Reply
Message 1 of 1
kandennti
99 Views, 0 Replies

Getting Depth, Diameter, and TipAngle of a HoleFeature

We received a question on how to get the Depth, Diameter, and TipAngle of a HoleFeature, so we created a sample.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        holeFeats: adsk.fusion.HoleFeatures = root.features.holeFeatures

        msgLst = []
        holeFeat: adsk.fusion.HoleFeature = None
        for holeFeat in holeFeats:
            msgLst.append('')
            msgLst.append(f'--Name-{holeFeat.name}------')
            msgLst.append('----Diameter------')
            msgLst.append(f'{holeFeat.holeDiameter.expression}')
            msgLst.append('----Depth------')
            msgLst.append(f'{holeFeat.extentDefinition.distance.expression}')
            msgLst.append('----TipAngle------')
            msgLst.append(f'{holeFeat.tipAngle.expression}')
            msgLst.append('----Direction------')
            msgLst.append(getCoordinate(holeFeat.direction))
            msgLst.append('----Position------')
            msgLst.append(getAllHoleCoordinate(holeFeat.holePositionDefinition))

        app.log('\n'.join(msgLst))

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

def getAllHoleCoordinate(holeDef: adsk.fusion.PointHolePositionDefinition) -> str:
    pass
    if hasattr(holeDef, 'point'):
        return getCoordinate(holeDef.point)

    if hasattr(holeDef, 'sketchPoints'):
        coords = [getCoordinate(p.worldGeometry) for p in holeDef.sketchPoints]
        return '\n'.join(coords)

    return ''

def getCoordinate(p) -> str:
    return f'{p.x},{p.y},{p.z}'

This is just a test with simple data, so there may be some errors.
If you attach the data with errors, we will correct them.

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report