@nnikbin .
As it is finished, I will leave it for those who want to use it in the future.
In the sample, first select the sketch curve.
It ends with a control point selected.
# Fusion360API Python script
import adsk.core, adsk.fusion, adsk.cam, traceback
import json
def run(context):
ui = adsk.core.UserInterface.cast(None)
try:
app :adsk.fusion.Application = adsk.core.Application.get()
ui = app.userInterface
# select Control Point Spline
msg :str = 'Select'
selFiltter :str = 'SketchCurves'
sel :adsk.core.Selection = selectEnt(msg ,selFiltter)
if not sel: return
crv = sel.entity
# get Control Points
controlPoints = getControlPoints(crv)
if len(controlPoints) < 1:
ui.messageBox('Not a Control Point Spline.')
return
# select Control Points
sels = ui.activeSelections
[sels.add(p) for p in controlPoints]
ui.messageBox('Done')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
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
# Get the Control Point
# Returns an empty list, except for control point splines.
def getControlPoints(crv :adsk.fusion.SketchFittedSpline) -> list:
app = adsk.core.Application.get()
ui = app.userInterface
sels = ui.activeSelections
# --support functions--
def getIdFromKey(entityId, key) -> int:
prop = getPropertiesJson(entityId)
return prop[key]['entityId']
def getIdsFromKey(entityId, key) -> List:
prop = getPropertiesJson(entityId)
ids = []
for idx in range(len(prop[key])):
ids.append(prop[key][idx]['entityId'])
return ids
def getPropertiesJson(entityId) -> json:
prop = app.executeTextCommand(u'PEntity.Properties {}'.format(entityId))
return json.loads(prop)
def getSelectItemEntityId(entity) -> int:
selectionsForcedClear()
sels.add(entity)
paths = app.executeTextCommand(u'Selections.List')
id = paths.split(':')[-1].split('+')[0]
selectionsForcedClear()
return int(id)
def getNextPointId(targetId, crvId, ids):
childrenIds = getIdsFromKey(targetId, 'children')
for id in childrenIds:
geoIds = getIdsFromKey(id, 'geometries')
for geoId in geoIds:
if geoId == crvId:
continue
sId = getIdFromKey(geoId, 'rStartPoint')
if not sId in ids:
return sId
eId = getIdFromKey(geoId, 'rEndPoint')
if not eId in ids:
return eId
def getEntityFromIds(ids) -> list:
selectionsForcedClear()
for id in ids:
app.executeTextCommand(u'Selections.add {}'.format(id))
lst = []
for idx in range(sels.count):
lst.append(sels[idx].entity)
selectionsForcedClear()
return lst
def selectionsForcedClear():
sels.clear()
if sels.count > 0:
ents = sels.all
app.executeTextCommand(u'Commands.Start SelectabilityToggleCmd')
[sels.add(ent) for ent in ents]
app.executeTextCommand(u'Commands.Start SelectabilityToggleCmd')
sels.clear()
def isControlPointSpline(crv, prop) -> bool:
if crv.objectType != 'adsk::fusion::SketchFittedSpline':
return False
if prop['intentionDegree'] != 5:
return False
return True
# ----
# get curve id
crvId = getSelectItemEntityId(crv)
prop = getPropertiesJson(crvId)
# ControlPointSpline check
if not isControlPointSpline(crv, prop):
return []
# get start/end point id
startId = prop['rStartPoint']['entityId']
endId = prop['rEndPoint']['entityId']
# get Control Point Ids
ids = [startId]
while True:
pass
id = getNextPointId(ids[-1], crvId, ids)
ids.append(id)
if id == endId:
break
# get Control Points
return getEntityFromIds(ids)
I am not sure if the Control Point Spline decision (isControlPointSpline) is correct, but I think it is.