Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Selection Object 'entity' fails with RuntimeError: 3 when a 'Setups' is selected

mantacast4154
Explorer

Selection Object 'entity' fails with RuntimeError: 3 when a 'Setups' is selected

mantacast4154
Explorer
Explorer

I have made a Fusion AddIn that uses a ActiveSelectionEventHandler to to let the user select faces to inspect and then I filter to see if it is a relevant BRep object by looking at .entity.objectType of the selection. This works pretty well except for when I select the 'Setups' tab or 'Named Views' as when I call entity it cant convert them, It would be useful if every object that would be possible to select could at least present the 'Base' object properties so that they can be filtered out.
Also as a sidenote it would be nice if the selection details in the bottom right corner of the screen was accessible through the API.

0 Likes
Reply
338 Views
4 Replies
Replies (4)

j.han97
Advocate
Advocate

You could consider using "try...except" statement in Python to ignore items that do not have an entity. Besides that, I am not sure what details you are referring to (bottom right corner of screen). Could you attach an example for reference?

2 Likes

mantacast4154
Explorer
Explorer

I am currently using a try and except structure which at least makes my addin usable, I am just trying to avoid having to 'mute' all exceptions so if there is a actual bug/problem elsewhere in my program that people using my addin can send me the error messages (just using the standard boiler plate for addins with 

_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

In terms of the UI I mentioned I am talking about this: 

mantacast4154_0-1649301370450.png

 

0 Likes

j.han97
Advocate
Advocate

Maybe wrap the try-except block just around the line to obtain entity only.

try:
     ent = selection.entity
except RuntimeError:
     app.log('Selection has no entity)

This is not error-proof (perhaps there are other actions that could trigger runtime error) but I think it is sufficient for use.

 

As for the selection details, it is possible to obtain the information through API, although not so convenient. For example, to know the radius:

radius = selectedFace.geometry.radius

I am sure you are able to figure out the method to obtain the correct information. 

1 Like

j.han97
Advocate
Advocate

Actually, if it is not necessary to use ActiveSelectionEventHandler, you could consider using selectionCommandInput or even ui.selectEntity() method to accept selection(s) from users. This way, selection filter(s) could be applied to limit the selection(s) made.

1 Like