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: 

how can get face' raduis?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
ho-kou
131 Views, 3 Replies

how can get face' raduis?

Hi everyone,

 

I want to get(measure) face' radius .

who know how can do it.

 

Thankyou for your help.

radius.png

3 REPLIES 3
Message 2 of 4
kandennti
in reply to: ho-kou

Hi @ho-kou -San.

 

A script was created to select a cylindrical surface and display its radius.

The radius is obtained within the get_radius function.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

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

        msg: str = "Select"
        selFilter: str = "CylindricalFaces"
        sel: core.Selection = select_ent(msg, selFilter)
        if not sel:
            return

        radius = get_radius(sel.entity)
        if not radius: return

        unitsMgr: core.UnitsManager = des.unitsManager

        ui.messageBox(
            f"{unitsMgr.formatInternalValue(radius)}",
            "Radius",
        )

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


def get_radius(
    face: fusion.BRepFace,
) -> float:

    geo = face.geometry
    if geo.classType() != core.Cylinder.classType(): return None

    cylinder: core.Cylinder = geo
    return cylinder.radius


def select_ent(
    msg: str,
    filterStr: str
) -> core.Selection:

    try:
        app: core.Application = core.Application.get()
        ui: core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None
Message 3 of 4
ho-kou
in reply to: ho-kou

hi @kandennti 

 

Thank you very much for your code.

But i want to measure the brepface which type is "adsk.core.NurbsSurface".

Do you give me other idea.

Thank you for your help.

 

Message 4 of 4
kandennti
in reply to: ho-kou

@ho-kou -San.

 

The following sample displays the radius at the clicked position of a face.
The curvature is the reciprocal of the radius.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

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

        # select face
        msg: str = 'Select Face'
        selFilter: str = 'Faces'
        sel: core.Selection = select_ent(msg, selFilter)
        if not sel: return

        # get curvature
        curvature = get_curvature(
            sel.entity,
            sel.point,
        )

        # get raduis
        unitsMgr: core.UnitsManager = des.unitsManager
        if curvature == 0:
            raduis = "-"
        else:
            raduis = unitsMgr.formatInternalValue(
                abs(1 / curvature)
            )

        ui.messageBox(raduis, "Raduis")

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


def get_curvature(
    face: fusion.BRepFace,
    point: core.Point3D,
) -> float:

    # https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-31dad9b2-ee1d-4216-8100-09ea44f9967a
    eva: core.SurfaceEvaluator = face.evaluator

    _, prm = eva.getParameterAtPoint(point)
    _, _, curvature, _ = eva.getCurvature(prm)

    return curvature


def select_ent(
    msg: str,
    filterStr: str
) -> core.Selection:

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

 

All add-ins here are in Japanese, but the same process is used to display the radius of the mouse cursor position in real time.

https://github.com/kantoku-code/Fusion360_OnTheFly/tree/master 

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