I do not know how to use ConstructionPlaneInput.setByDistanceOnPath()

I do not know how to use ConstructionPlaneInput.setByDistanceOnPath()

CreatonStyle
Participant Participant
859 Views
4 Replies
Message 1 of 5

I do not know how to use ConstructionPlaneInput.setByDistanceOnPath()

CreatonStyle
Participant
Participant

 

I am creating an Add-in that I want to create a construction plane.

 

I am not able to create the construction plane normal to the selected profile. Can someone please help me with this?

 

The code below does not work. The last print statement does not get executed.

 

 

_app = adsk.core.Application.get()
_ui  = _app.userInterface
print('app ui')

# Get root component of active product
product = _app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
print('root comp')

# Get construction planes
constructionPlanes = rootComp.constructionPlanes
print('constructionPlanes')
# Create construction plane input
constructionPlaneInput = constructionPlanes.createInput()
print('constructionPlaneInput')
# Get selected profile
sketchProfile = _selectedProfile.selection(0).entity
print('sketchProfile')
constructionPlaneInput.setByDistanceOnPath(sketchProfile, 0)
print('setByDistanceOnPath')

 

 

 

 

 

 

0 Likes
Accepted solutions (1)
860 Views
4 Replies
Replies (4)
Message 2 of 5

BrianEkins
Mentor
Mentor
Accepted solution

Try the code below.  There was one problem with your code and possibly two.  The first was when calling the setByDistanceOnPath method.  The last argument that specifies the distance along the curve to create the construction plane must be a ValueInput object and you were providing a simple float value.  Any time a value will end up being used to create a parameter, the API expected a ValueInput object.  Using this you can supply simple values or you can supply an equation so you can create more complex parametric relationships.

 

The second probably problem is the profile being passed in.  Creating a construction plane on a path doesn't support a Profile.  Instead it supports individual curves or a Path object.  In my sample below I get a selection of a single curve and then create a path from that.  My test was a set of connected curves and this results in creating a path of all of the curves that are connected.

 

import adsk.core, adsk.fusion, adsk.cam, traceback
_app: adsk.core.Application = None
_ui: adsk.core.UserInterface = None


def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui  = _app.userInterface

        # Have a profile selected.
        sketchCurveSel = _ui.selectEntity('Select a sketch entity', 'SketchCurves')
        if sketchCurveSel is not None:
            curve: adsk.fusion.SketchCurve = sketchCurveSel.entity
            path: adsk.fusion.Path = adsk.fusion.Path.create(curve, adsk.fusion.ChainedCurveOptions.connectedChainedCurves)
        else:
            return
        
        # Get root component of active product
        design: adsk.fusion.Design = _app.activeProduct
        rootComp = design.rootComponent

        # Get construction planes
        constructionPlanes = rootComp.constructionPlanes

        # Create construction plane input
        constructionPlaneInput = constructionPlanes.createInput()
        constructionPlaneInput.setByDistanceOnPath(path, adsk.core.ValueInput.createByReal(0))
        constructionPlanes.add(constructionPlaneInput)
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

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

CreatonStyle
Participant
Participant

Thank you very much for your fast response. I will check that out right away. 🙂

0 Likes
Message 4 of 5

CreatonStyle
Participant
Participant

You really helped me man. I would like to buy you a beer or something.

0 Likes
Message 5 of 5

BrianEkins
Mentor
Mentor

Happy to help.  Best of luck on your project.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes