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: 

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

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
CreatonStyle
226 Views, 4 Replies

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

 

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')

 

 

 

 

 

 

4 REPLIES 4
Message 2 of 5
BrianEkins
in reply to: CreatonStyle

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
Message 3 of 5
CreatonStyle
in reply to: BrianEkins

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

Message 4 of 5
CreatonStyle
in reply to: CreatonStyle

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

Message 5 of 5
BrianEkins
in reply to: CreatonStyle

Happy to help.  Best of luck on your project.

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

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