
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
A piece of code I've been working on was flagged in code review, and we haven't been able to resolve this by reading the documentation. Suppose we want to get the active product and do some work with it. Previously, we had a line like
app = adsk.core.Application.get() design = app.activeProduct
every time we wanted to do that, which seemed pretty wasteful, so we refactored it such that they were global variables. Then we realized that the active product probably changes if they switch to a new design without closing the application, thus we used this getter function instead
design = None def getDesign(): global design if design is not None and design.isValid(): return design else: return app.activeProduct
however we aren't sure when exactly a Product object will be invalidated - the documentation just has this to say about the isValid property: "Indicates if this object is still valid, i.e. hasn't been deleted or some other action done to invalidate the reference".
Does switching the design being worked on invalidate the reference, i.e. is `design` a reference to a specific design, or to `app.activeProduct` whatever that may be? Or even more generally, what is the best way to get the active product while minimizing how often we need to get it from the app?
Solved! Go to Solution.