The result of setByDistanceOnPath varies depending on the mode

The result of setByDistanceOnPath varies depending on the mode

kandennti
Mentor Mentor
412 Views
3 Replies
Message 1 of 4

The result of setByDistanceOnPath varies depending on the mode

kandennti
Mentor
Mentor

Hi there.

 

I created a plane using the "ConstructionPlaneInput.setByDistanceOnPath" method and noticed that the planes created in parametric mode and direct mode are different.

 

I created a script like this to test it.

# 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 Edge'
        selFilter: str = 'Edges'
        sel: adsk.core.Selection = selectEnt(msg, selFilter)
        if not sel:
            return

        edge: adsk.fusion.BRepEdge = sel.entity

        comp: adsk.fusion.Component = edge.body.parentComponent

        valueIpts = [
            adsk.core.ValueInput.createByReal(0),
            adsk.core.ValueInput.createByReal(0.5),
            adsk.core.ValueInput.createByReal(1),
        ]

        constPlanes: adsk.fusion.ConstructionPlanes = comp.constructionPlanes
        for valueIpt in valueIpts:
            planeIpt: adsk.fusion.ConstructionPlaneInput = constPlanes.createInput()
            planeIpt.setByDistanceOnPath(edge, valueIpt)
            constPlanes.add(planeIpt)


    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

Creates three planes with ratios of 0, 0.5, and 1 for the selected edge.

 

Prepare a body, which can be anything, run the script and select an edge.

1.png

If you select the red arrow in the left image, a plane is created in parametric mode, as shown in the middle image. This is the desired state, no problem.

 

In direct mode, however, the image on the right shows the situation.
The same is true for the parametric mode BaseFeature edit.

 

 

In direct mode, I think the "distance" argument is treated as a numerical value of a parameter on the curve.
However, when I try to set the value of a parameter to the "distance" argument, I sometimes get an error because of the limitation of 0 to 1.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-46dd5f0a-e384-4707-b431-37c0e596f328 

 

In any case, there is no way to create the desired plane in direct mode.

Accepted solutions (1)
413 Views
3 Replies
Replies (3)
Message 2 of 4

BrianEkins
Mentor
Mentor

I can reproduce the behavior and will see that a bug is logged.

 

I see that in the UI, the command supports specifying the distance by "Proportional" or "Distance". I think the "Distance" option is new since this API was implemented. I was guessing that the API was using the distance in direct modeling, but that doesn't appear to be the case.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 4

kandennti
Mentor
Mentor

@BrianEkins Thanks for the reply.
As for the direct mode, it is not used very often, so there may be something else.

0 Likes
Message 4 of 4

kandennti
Mentor
Mentor
Accepted solution

I came up with a workaround.

When in direct mode, I found that I could temporarily switch to parametric mode to create a plane at the desired position.

 

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

DESIGN_TYPES = adsk.fusion.DesignTypes

def run(context):
    ui = adsk.core.UserInterface.cast(None)
    try:
        app: adsk.core.Application = adsk.core.Application.get()
        ui = app.userInterface

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

        edge: adsk.fusion.BRepEdge = sel.entity

        comp: adsk.fusion.Component = edge.body.parentComponent

        valueIpts = [
            adsk.core.ValueInput.createByReal(0),
            adsk.core.ValueInput.createByReal(0.5),
            adsk.core.ValueInput.createByReal(1),
        ]

        des: adsk.fusion.Design = app.activeProduct
        returnDesignType = False
        if des.designType == DESIGN_TYPES.DirectDesignType:
            returnDesignType = True
            token = edge.entityToken
            des.designType = DESIGN_TYPES.ParametricDesignType
            edge = des.findEntityByToken(token)[0]

        constPlanes: adsk.fusion.ConstructionPlanes = comp.constructionPlanes
        for valueIpt in valueIpts:
            planeIpt: adsk.fusion.ConstructionPlaneInput = constPlanes.createInput()
            planeIpt.setByDistanceOnPath(edge, valueIpt)
            constPlanes.add(planeIpt)

        if returnDesignType:
            des.designType = DESIGN_TYPES.DirectDesignType

    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


I think parametric -> direct -> parametric would be a problem, but I don't think direct -> parametric -> direct would be a problem.