Project a body on a sketch

Project a body on a sketch

TRIALCAD2014
Enthusiast Enthusiast
549 Views
2 Replies
Message 1 of 3

Project a body on a sketch

TRIALCAD2014
Enthusiast
Enthusiast

Hi, It's possible from the UI to project a body onto a sketch when in a sketch via the create/project however I don't find any reference about how to do that in the API.

Any example beyond https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7a1981fc-0daa-4fc3-808f-ebccc5fa816e

which does not actually seem to support projecting a body.

Thank you,
Adrian

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

kandennti
Mentor
Mentor
Accepted solution

Hi @TRIALCAD2014 .

 

I prepared a body of some kind and ran the following script, and it projected without any problems.

# 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
        des: adsk.fusion.Design = app.activeProduct
        root: adsk.fusion.Component = des.rootComponent

        targetBody: adsk.fusion.BRepBody = root.bRepBodies[0]

        skt: adsk.fusion.Sketch = root.sketches.add(
            root.xYConstructionPlane
        )

        skt.project(targetBody)

        ui.messageBox('Done')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

1.png

It is possible that I am misunderstanding something.
If there is a problem, please be more specific.

 

 

 

0 Likes
Message 3 of 3

TRIALCAD2014
Enthusiast
Enthusiast
Hi, thank you very much. I also managed to get it running. Initially I
was getting an internal error -with no info about the cause. Also the
docs don't explicitly mention body as an argument.

I still don't know why I was getting the error but it might have been
because the sketch and body might have been in different components.

All this is jumping through hoops because of inconsistency and severe
limitations in the product.