<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic What invalidates a Product? in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-invalidates-a-product/m-p/5730543#M21026</link>
    <description>&lt;P&gt;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. &amp;nbsp;Suppose we want to get the active product and do some work with it. &amp;nbsp;Previously, we had a line like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;app = adsk.core.Application.get()
design = app.activeProduct&lt;/PRE&gt;&lt;P&gt;every time we wanted to do that, which seemed pretty wasteful, so we refactored it such that they were global variables. &amp;nbsp;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&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;design = None

def getDesign():
    global design
    if design is not None and design.isValid():    
        return design
    else:
        return app.activeProduct&lt;/PRE&gt;&lt;P&gt;ho&lt;FONT color="#000000"&gt;we&lt;FONT face="arial,helvetica,sans-serif"&gt;ver we aren't sure when exactly a Product object will be invalidated - the documentation just has this to say about the isValid property: &amp;nbsp;"Indicates if this object is still valid, i.e. hasn't been deleted or some other action done to invalidate the reference".&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;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? &amp;nbsp;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?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Jul 2015 13:22:57 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-07-21T13:22:57Z</dc:date>
    <item>
      <title>What invalidates a Product?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-invalidates-a-product/m-p/5730543#M21026</link>
      <description>&lt;P&gt;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. &amp;nbsp;Suppose we want to get the active product and do some work with it. &amp;nbsp;Previously, we had a line like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;app = adsk.core.Application.get()
design = app.activeProduct&lt;/PRE&gt;&lt;P&gt;every time we wanted to do that, which seemed pretty wasteful, so we refactored it such that they were global variables. &amp;nbsp;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&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;design = None

def getDesign():
    global design
    if design is not None and design.isValid():    
        return design
    else:
        return app.activeProduct&lt;/PRE&gt;&lt;P&gt;ho&lt;FONT color="#000000"&gt;we&lt;FONT face="arial,helvetica,sans-serif"&gt;ver we aren't sure when exactly a Product object will be invalidated - the documentation just has this to say about the isValid property: &amp;nbsp;"Indicates if this object is still valid, i.e. hasn't been deleted or some other action done to invalidate the reference".&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;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? &amp;nbsp;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?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2015 13:22:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-invalidates-a-product/m-p/5730543#M21026</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-07-21T13:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: What invalidates a Product?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-invalidates-a-product/m-p/5731874#M21027</link>
      <description>&lt;P&gt;All Fusion API objects support the isValid property.&amp;nbsp; It indicates if the reference you're holding to the Fusion object is still valid.&amp;nbsp; A reference can become invalid for many reasons.&amp;nbsp; For example, if you have a reference to a sketch line and the user deletes the line.&amp;nbsp; In the case of a Design, it can become invalid when the user closes that document that contains the design.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you get a design it doesn't matter how you obtained it, the reference you have it to a specific design.&amp;nbsp; For example, if you use the Application.activeProduct property to get the active design, the design returned is for the design in the currently active document.&amp;nbsp; If the user activates another document so the activeProduct is not a different design, that doesn't change the reference you already have, which is to the document that was previosly active and t's still valid, as long as the user hasn't closed it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you always want to work on the design that the user is looking at (the active product) then you'll need to get it each time.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2015 17:35:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/what-invalidates-a-product/m-p/5731874#M21027</guid>
      <dc:creator>ekinsb</dc:creator>
      <dc:date>2015-07-21T17:35:56Z</dc:date>
    </item>
  </channel>
</rss>

