Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Sketch Plane - Python Modification

1 REPLY 1
Reply
Message 1 of 2
isocam
172 Views, 1 Reply

Get Sketch Plane - Python Modification

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

1 REPLY 1
Message 2 of 2
BrianEkins
in reply to: isocam

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report