Marginal condition causes a bug in ConstructionPlaneInput.setByDistanceOnPath

Marginal condition causes a bug in ConstructionPlaneInput.setByDistanceOnPath

nnikbin
Collaborator Collaborator
897 Views
3 Replies
Message 1 of 4

Marginal condition causes a bug in ConstructionPlaneInput.setByDistanceOnPath

nnikbin
Collaborator
Collaborator

When the active units of the design is set to inch or foot, passing 1.0 as the distance parameter to ConstructionPlaneInput.setByDistanceOnPath method creates an invalid state.

 

Here is a my code for testing this issue:

 

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        rootComponent = design.rootComponent
        sketches = rootComponent.sketches

        p1 = adsk.core.Point3D.create(0, 0, 0)
        p2 = adsk.core.Point3D.create(5, 0, 0)
        
        sketch = sketches.add(rootComponent.xYConstructionPlane)
        sketchLines = sketch.sketchCurves.sketchLines
        sketchLine = sketchLines.addByTwoPoints(p1, p2)
        
        constructionPlanes = rootComponent.constructionPlanes
        constructionPlaneInput = constructionPlanes.createInput()
        
        constructionPlaneInput.setByDistanceOnPath(sketchLine, adsk.core.ValueInput.createByReal(0))
        constructionPlane = constructionPlanes.add(constructionPlaneInput)
        
        constructionPlaneInput.setByDistanceOnPath(sketchLine, adsk.core.ValueInput.createByReal(0.5))
        constructionPlane = constructionPlanes.add(constructionPlaneInput)
        
        constructionPlaneInput.setByDistanceOnPath(sketchLine, adsk.core.ValueInput.createByReal(1.0))
        constructionPlane = constructionPlanes.add(constructionPlaneInput)
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

  

Capture_02.png

 

 

As you can see the add-in fails in creating the 3rd construction plane. I guess some round-off errors in conversion between imperial and metric units results a larger than 1.0 parameter which causes this issue.

 

The same issue happens in using C++ API. There isn't any problem  in running the code when the active unit of the design is set to one of the metric units.

 

Capture_01.png

 

0 Likes
Accepted solutions (1)
898 Views
3 Replies
Replies (3)
Message 2 of 4

nnikbin
Collaborator
Collaborator

As a simple temporary solution:

  • Using 0.9999999 instead of 1.0 solves the issue when the active units of the design is set to "inch", but causes failure when the active units of the design is set to "foot"
  • Using 0.99999 instead of 1.0 solves the issue for "inch" and "foot"

So I suggest checking the distance and if it is grater than 0.99999 then change it to 0.99999. In this case the command at history timeline rounds-up the distance and shows 1.00 instead of 0.99999

0 Likes
Message 3 of 4

liujac
Alumni
Alumni
Accepted solution

Hi,

 

Thanks for reporting this issue. I logged a defect (UP-30784) in our internal system. We will fix it soon.

 

Regards,

Jack 

0 Likes
Message 4 of 4

nnikbin
Collaborator
Collaborator

Hi Jack,

 

Thanks for logging the defect.

 

Regards,

Navid

0 Likes