How the fusion 360 API gets the bounding box of the parameter space

How the fusion 360 API gets the bounding box of the parameter space

2544173825
Enthusiast Enthusiast
1,275 Views
8 Replies
Message 1 of 9

How the fusion 360 API gets the bounding box of the parameter space

2544173825
Enthusiast
Enthusiast

I want to use the Fusion 360 API to get a parameter space bounding box, UV bounding, for a face, but I didn't find the relevant method.

0 Likes
Accepted solutions (2)
1,276 Views
8 Replies
Replies (8)
Message 2 of 9

kandennti
Mentor
Mentor

Hi @2544173825 .

 

It can be obtained with the SurfaceEvaluator object.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-GUID-31dad9b2-ee1d-4216-8100-09ea44f9967a 

 

We have created a script that displays the parameter range of the selected surface.

# 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

        msg: str = 'Select'
        selFilter: str = 'Faces'
        sel: adsk.core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        selectFace: adsk.fusion.BRepFace = sel.entity

        eva: adsk.core.SurfaceEvaluator = selectFace.evaluator
        bBox: adsk.core.BoundingBox2D = eva.parametricRange()

        _, pointMin = eva.getPointAtParameter(bBox.minPoint)
        _, pointMax = eva.getPointAtParameter(bBox.maxPoint)

        msglst = ['-- Parameter --']
        msglst.append(f'min:{bBox.minPoint.asArray()}')
        msglst.append(f'min:{bBox.maxPoint.asArray()}')
        msglst.append('-- Position --')
        msglst.append(f'min:{pointMin.asArray()}')
        msglst.append(f'min:{pointMax.asArray()}')
        ui.messageBox('\n'.join(msglst))

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

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

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

 

Note that "face.evaluator" and "face.geometry.evaluator" give different results.

 

0 Likes
Message 3 of 9

2544173825
Enthusiast
Enthusiast

Thanks for your prompt reply!
This method looks very nice, but I don't quite understand statements like msg: str = 'select' which doesn't seem to be very common in python, he seems to be declaring a string type variable, but isn't the variable declaration in python possible to use msg = 'select' directly? Are the two equivalent? Also, is there any difference between select here and the entity I get via body.faces(edges)?

0 Likes
Message 4 of 9

kandennti
Mentor
Mentor
Accepted solution

@2544173825 .

 

As for ": str", it is a python type hints.
It has no effect on execution.


If you get it with body.faces(edges), elements in the root component are fine, but for elements in the occurrence (GUI component), you will have a problem.

You need to consider about proxies here.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A 

0 Likes
Message 5 of 9

2544173825
Enthusiast
Enthusiast

I found a bug with parametricRange. When I debug a program, the first time I get a 2D bounding box through this method, it seems to be fine, but when I break the debug and start it again, there are some problems with the 2D wraparound box I get. This is reflected in the returned maxpoint, which may appear as maxpoint=minpoint, or maxpoint.y=minpoint.y. When I restart VScode and Fusion 360, it returns to normal.

 

for face in tem_body.faces:
    face_id = face.tempId
    face_type = face.geometry.objectType
    face_normal = face.geometry.normal
    face_reversed = face.isParamReversed
    face_are = face.area
    centroid_point = face.centroid
    point_on_face = face.pointOnFace
    uvgrid(face=face, method='point')

def uvgrid(face, num_u = 10, num_v = 10, method=None, reverse = True):
    assert num_u >= 2
    assert num_v >= 2
    eval = face.evaluator
    face_para_bounding = eval.parametricRange()
    point_max = face_para_bounding.maxPoint
    point_min = face_para_bounding.minPoint

 

 

0 Likes
Message 6 of 9

kandennti
Mentor
Mentor
Accepted solution

@2544173825 .

 

I have not tried many, but I have no such experience.
Is there an f3d file that can be attached?

Message 7 of 9

2544173825
Enthusiast
Enthusiast

I have not .f3d file. I get part information from .smt file, but, I cannot upload .smt file. I had upload .step file.

0 Likes
Message 8 of 9

kandennti
Mentor
Mentor

@2544173825 .

 

Thanks for the data. smt file can be attached to the forum if you zip it.

 

I have seen the data. Perhaps the two sides here will be the problem.

1.png

I think it is due to the fact that they are periodic.


The periodicity can be checked by using the getParamAnomaly method.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-d6b7d30a-972b-4117-9292-c0a87be8ba62 

I have checked and U is periodic.

0 Likes
Message 9 of 9

2544173825
Enthusiast
Enthusiast

Thanks

0 Likes