How do I emulate the create sketch command?

How do I emulate the create sketch command?

RubyRedRick
Enthusiast Enthusiast
435 Views
2 Replies
Message 1 of 3

How do I emulate the create sketch command?

RubyRedRick
Enthusiast
Enthusiast

I'm trying to modify a script  from https://youtu.be/QYsf8y4nZ4E which currently adds geometry to an existing sketch.

 

I'd like it to work if there is no active sketch, similar to the create sketch command,, by getting a face or plane from the user and creating a new sketch.

 

Here's what I have so far.

 

 

app = adsk.core.Application.get()
        ui  = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)
        component = design.activeComponent
        if app.activeEditObject.objectType != adsk.fusion.Sketch.classType():
            sketchPlane = ui.selectEntity('Select a plane or planar face', 'PlanarFaces,ConstructionPlanes')
            sketch = component.sketches.add(sketchPlane)
        else:
            sketch = adsk.fusion.Sketch.cast(app.activeEditObject)

 

 

when I run this I get 

Failed:

Traceback (most recent call last):

File "/Users/rick/Library/Application Support/Autodesk/Autodesk Fusion 360/API/Scripts/adsk2020ai/adsk2020ai.py", line 15, in run

sketch = component.sketches.add(sketchPlane)

File "/Users/rick/Library/Application Support/Autodesk/webdeploy/production/6a4ee1e135d539f7735a031beb7a5c1c01c7a76f/Autodesk Fusion 360.app/Contents/Api/Python/packages/adsk/fusion.py", line 38203, in add

return _fusion.Sketches_add(self, *args)

RuntimeError: 3 : not a planar entity

 

I guess I need to cast the result of the ui.selectEntity to some type, but I can't seem to figure out what is needed to satisfy the requirement for a 'planar entity'.

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

BrianEkins
Mentor
Mentor
Accepted solution

The selectEntity function returns a Selection object. You need to use the entity property on it to get what was selected.

 

This works

sketchPlane = ui.selectEntity('Select a plane or planar face', 'PlanarFaces,ConstructionPlanes').entity

or this

select = ui.selectEntity('Select a plane or planar face', 'PlanarFaces,ConstructionPlanes')
sketchPlane = select.entity
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

RubyRedRick
Enthusiast
Enthusiast

Thanks!

0 Likes