Can anybody help?
Is it possible, using a Python script, to extract the diameters of two circles in a sketch?
For example, If I create a hollow cylinder consisting of two circles extruded to a particular length, can I show the circle diameters in a message box?
Many thanks in advance!
Darren
Solved! Go to Solution.
Solved by isocam. Go to Solution.
Hi @isocam .
I took up the challenge.
Select a Feature.
# Fusion360API Python script
import adsk.core, adsk.fusion, traceback
def run(context):
ui = adsk.core.UserInterface.cast(None)
try:
app :adsk.fusion.Application = adsk.core.Application.get()
ui = app.userInterface
des :adsk.fusion.Design = app.activeProduct
# Select Feature
msg :str = 'Select'
selFiltter :str = 'Features'
sel :adsk.core.Selection = selectEnt(msg ,selFiltter)
if not sel: return
# Get Profile Circle Diameter
feat: adsk.fusion.Feature = sel.entity
diameterLst = getProfileCircleDiameterList(feat)
# Convert Unit
unitsMgr = des.unitsManager
defLenUnit = unitsMgr.defaultLengthUnits
retio = unitsMgr.convert(1, unitsMgr.internalUnits, defLenUnit)
msg = '\n'.join([str(d * retio ) + defLenUnit for d in diameterLst])
# Finish
ui.messageBox('-- Diameter List --\n' + msg)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def getProfileCircleDiameterList(
feat: adsk.fusion.Feature) -> list:
diameterLst = []
for proloop in feat.profile.profileLoops:
for proCrv in proloop.profileCurves:
sktEnt = proCrv.sketchEntity
if sktEnt.objectType == 'adsk::fusion::SketchCircle':
diameterLst.append(sktEnt.radius * 2)
list(set(diameterLst)).sort()
return diameterLst
def selectEnt(
msg :str,
filtterStr :str) -> adsk.core.Selection :
try:
app = adsk.core.Application.get()
ui = app.userInterface
sel = ui.selectEntity(msg, filtterStr)
return sel
except:
return None
Many thanks!!!
Is it possible to automatically always use Sketch1 rather than manually selecting the part?
Kind Regards
Darren
@isocam .
If there are multiple extrusions, can you determine which profile is meant?
You need to provide more specific examples, images, files, etc. I can't make a decision based on words alone.
Can't find what you're looking for? Ask the community or share your knowledge.