- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good day,
Using the `itemByName(_name_)` method on instances of `MirrorFeatures` and `StichFeatures` results in exceptions when there is no feature with a name as the given argument `_name_` in the collection. The online API reference at itemByName, states that `null` i.e. `None` should be returned if `_name_` can't be found. This is seemingly not the case for the two mentioned collections.
The script following further on replicates the problem and shows that other collections seemingly work, for non-existent names, as documented in the API reference.
Regards,
Nicolaas
import adsk.fusion, adsk.core, traceback
def replicate_problem():
# Identify the root component
app = adsk.core.Application.get()
design = app.activeProduct
root = design.rootComponent
# Get the names of all collections on the root component
collections = [c for c in dir(root.features) if c.lower().endswith('features') and not c.startswith('_')]
# Try out each collection to verify the behaviour
results = []
for c in collections:
statement = f'root.features.{c}.itemByName("non-existent")'
try:
result = eval(statement)
result_str = f'{statement} -> {result}'
except:
result_str = f'{statement} -> {result}: {traceback.format_exc()}'
results.append(result_str)
return results # list of results for all Feature collections
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
results = replicate_problem()
print('\n'.join(results))
ui.messageBox('\n'.join(results))
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.