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: 

Get Sketch Circle Diameters Using Python

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
isocam
288 Views, 3 Replies

Get Sketch Circle Diameters Using Python

Can anybody help?

 

Is it possible, using a Python script, to extract the diameters of two circles in a sketch?

 

For example, If I create a hollow cylinder consisting of two circles extruded to a particular length, can I show the circle diameters in a message box?

 

Many thanks in advance!

 

Darren

3 REPLIES 3
Message 2 of 4
kandennti
in reply to: isocam

Hi @isocam .

 

I took up the challenge.

Select a Feature.

# Fusion360API Python script
import adsk.core, adsk.fusion, traceback

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

        # Select Feature
        msg :str = 'Select'
        selFiltter :str = 'Features'
        sel :adsk.core.Selection = selectEnt(msg ,selFiltter)
        if not sel: return

        # Get Profile Circle Diameter
        feat: adsk.fusion.Feature = sel.entity
        diameterLst = getProfileCircleDiameterList(feat)

        # Convert Unit
        unitsMgr = des.unitsManager
        defLenUnit = unitsMgr.defaultLengthUnits
        retio = unitsMgr.convert(1, unitsMgr.internalUnits, defLenUnit)
        msg = '\n'.join([str(d * retio ) + defLenUnit for d in diameterLst])

        # Finish
        ui.messageBox('-- Diameter List --\n' + msg)

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

def getProfileCircleDiameterList(
    feat: adsk.fusion.Feature) -> list:

    diameterLst = []
    for proloop in feat.profile.profileLoops:
        for proCrv in proloop.profileCurves:
            sktEnt = proCrv.sketchEntity
            if sktEnt.objectType == 'adsk::fusion::SketchCircle':
                diameterLst.append(sktEnt.radius * 2)

    list(set(diameterLst)).sort()

    return diameterLst

def selectEnt(
        msg :str, 
        filtterStr :str) -> adsk.core.Selection :

    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        sel = ui.selectEntity(msg, filtterStr)
        return sel
    except:
        return None

1.png

Message 3 of 4
isocam
in reply to: kandennti

Many thanks!!!

 

Is it possible to automatically always use Sketch1 rather than manually selecting the part?

 

Kind Regards

 

Darren

Message 4 of 4
kandennti
in reply to: isocam

@isocam .

 

If there are multiple extrusions, can you determine which profile is meant?

You need to provide more specific examples, images, files, etc. I can't make a decision based on words alone.

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report