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: 

Incorrect/unexpected isValid results from certain API classes

2 REPLIES 2
Reply
Message 1 of 3
jesse
287 Views, 2 Replies

Incorrect/unexpected isValid results from certain API classes

I see this behavior both with the C++ and Python API; certain objects will return false for isValid immediately after creation, e.g. the camera returned from Viewport (app.activeViewport.camera.isValid == False), the ParameterList returned from a design (app.activeProduct.allParameters.isValid == False, when a design is loaded).  These objects are perfectly fine to use, except calling isValid will return false.

 

Is this expected, and there are only certain objects for which we should rely on isValid?  Or is this a bug, and the expectation is that isValid will return true for all valid objects that extend Base?

2 REPLIES 2
Message 2 of 3
BrianEkins
in reply to: jesse

That's a bug.  The isValid property is on the Base class so everything in the API supports it, but in reality, it's not very useful for many of the objects.  It's intended to indicate if the object you're holding still exists in a valid state.  It doesn't mean the data within the object is good or bad.  It's the most useful for B-Rep-related objects because you can hold a reference to an object like a face and then make changes to the model that will invalidate the face you're referencing.  Other objects like a Point3D, Vector3D, and Camera are transient and will always be valid.

 

I'm fairly certain this has never been thoroughly tested and the behavior you're seeing is just an oversight that wasn't caught earlier.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3
Anonymous
in reply to: jesse

In some contexts, it may be better to not throw an exception at all, but (IMO) You have also, very reasonably, defined the behavior of your class in one the most natural result for the last case - non-coinciding parallel lines.

 

MyBalanceNow

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

Post to forums  

Autodesk Design & Make Report