Get Sketch Plane - Python Modification

Get Sketch Plane - Python Modification

isocam
Collaborator Collaborator
354 Views
1 Reply
Message 1 of 2

Get Sketch Plane - Python Modification

isocam
Collaborator
Collaborator

Can anybody help?

 

I have the following Python script. You have to select the sketch "manually" to get its sketch plane.

 

import adsk.core, adsk.fusion, adsk.cam, traceback, csv, subprocess

 

def run(context):
ui = None
try:
app = adsk.core.Application.get()

ui = app.userInterface

sel = Sel('select sketch','Sketches')

if sel is None: return

skt = adsk.fusion.Sketch.cast(sel.entity)

refplane = skt.referencePlane #This

if refplane.classType() == 'adsk::fusion::BRepFace':
SketchPlane = '{} face'.format(refplane.body.name)
else:
SketchPlane = refplane.name

ui.messageBox('Reference Plane is\n' + SketchPlane )

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

def Sel(msg, selFilter):
app = adsk.core.Application.get()

ui = app.userInterface

try:
return ui.selectEntity(msg, selFilter)
except:
return None

 

Can any body modify, for testing purposes only, the script so that it always, automatically, selects Sketch1?

 

Many thanks in advance!

 

Darren

0 Likes
355 Views
1 Reply
Reply (1)
Message 2 of 2

BrianEkins
Mentor
Mentor

Replace your existing:

sel = Sel('select sketch','Sketches')
if sel is None: return
skt = adsk.fusion.Sketch.cast(sel.entity)

with:

des: adsk.fusion.Design = app.activeProduct
root = des.rootComponent
sk = root.sketches.itemByName('Sketch1')

 

You'll want to check that the variable sk is not None before using it.  That will happen if there's not a sketch named "Sketch1".

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