[Missing?] API for creating a sketch using a profile as its reference plane

[Missing?] API for creating a sketch using a profile as its reference plane

nnikbin
Collaborator Collaborator
1,116 Views
6 Replies
Message 1 of 7

[Missing?] API for creating a sketch using a profile as its reference plane

nnikbin
Collaborator
Collaborator

In Fusion 360 UI, we can create a sketch using a ConstructionPlane, planar BRepFace or Profile as its referencePlane. But it seems if we use a Profile as the planarEntity argument of Sketches.add Method , the method returns nullptr (in C++). Also using a Profile for setting Sketch.referencePlane Property simply does not work.

 

Is there a reason for this difference between the UI and the API?

 

If we use UI to create a sketch using a Profile, the objectType of referencePlane property will be returened as "adsk::fusion::Profile" using API (as expected).

0 Likes
Accepted solutions (2)
1,117 Views
6 Replies
Replies (6)
Message 2 of 7

kandennti
Mentor
Mentor

Hi @nnikbin .

 

It's python, but I didn't have any problems.

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        design = adsk.fusion.Design.cast(app.activeProduct)
        rootComp = design.rootComponent

        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xZConstructionPlane)
        sketchCircles = sketch.sketchCurves.sketchCircles
        centerPoint = adsk.core.Point3D.create(0, 0, 0)
        sketchCircles.addByCenterRadius(centerPoint, 3.0)

        # Create a sketch using Profile
        prof = sketch.profiles.item(0)
        sketches.add(prof.parentSketch.referencePlane)
        sketches.addWithoutEdges(prof.parentSketch.referencePlane)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 3 of 7

nnikbin
Collaborator
Collaborator

Hi @kandennti ,

Thank you for your reply. In your script you create a sketch using the referencePlane of profile's parent sketch as the planar entity. What I am looking for is to create a sketch using a Profile as its referencePlane. As you know in 3D sketches it is possible to have profiles that are not aligned with their parent sketch's plane. 

 

I know that we can create construction planes aligned with the profile, then create a sketch using them, but I was wondering why the API does not accept Profiles as referencePlanes, while the UI accept them.

0 Likes
Message 4 of 7

kandennti
Mentor
Mentor
Accepted solution

Sorry, I hadn't thought about 3D sketch.

 

The API does not support it, so I thought of another way.

def run(context):
    ・・・
    skt :adsk.fusion.Sketch = createSketchFromProfile(prof)
    ・・・

def createSketchFromProfile(
    prof :adsk.fusion.Profile) -> adsk.fusion.Sketch:

    app = adsk.core.Application.get()
    ui = app.userInterface
    des = adsk.fusion.Design.cast(app.activeProduct)
    skts = des.activeComponent.sketches
    sktsCount = skts.count

    sels = ui.activeSelections
    sels.clear()
    sels.add(prof)

    app.executeTextCommand(u'NaFusionUI.SketchCreateCmd')
    app.executeTextCommand(u'NaFusionUI.SketchStopCmd')

    if sktsCount + 1 == skts.count:
        return skts[-1]
    else:
        return adsk.fusion.Sketch.cast(None)

 

Message 5 of 7

nnikbin
Collaborator
Collaborator

Thank you @kandennti . Your solution works fine!

 

I do not just click on "Accept Solution" button because I want to wait to hopefully get the answer to my main question. Then I accept both answers as solutions.

0 Likes
Message 6 of 7

BrianEkins
Mentor
Mentor
Accepted solution

This is a bug in the API. If it's supported when using the UI in Fusion, the API should also support it.

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

nnikbin
Collaborator
Collaborator

Thank you @BrianEkins for your reply. In this case the API documentation matches the API behavior so after solving the issue the documents need to be edited.


As it seems that there is no public list for reporting bugs, what is the best way to make sure the bugs that are reported in the forum and marked as "Solved" (because of a workaround or confirmation) will be reported?

0 Likes