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')
Solved! Go to Solution.
Solved by BrianEkins. Go to 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()))
Thank you very much for your fast response. I will check that out right away. 🙂
Happy to help. Best of luck on your project.
Can't find what you're looking for? Ask the community or share your knowledge.