<?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 Re: Weird Python error after extending a class in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/weird-python-error-after-extending-a-class/m-p/11289133#M5762</link>
    <description>&lt;P&gt;Apparently, properties with a double underscore are somewhat enforced as 'private' properties so that subclasses don't have easy access to them.&lt;BR /&gt;&lt;BR /&gt;Thanks for the help&lt;/P&gt;</description>
    <pubDate>Mon, 11 Jul 2022 12:39:30 GMT</pubDate>
    <dc:creator>vkr.mobile</dc:creator>
    <dc:date>2022-07-11T12:39:30Z</dc:date>
    <item>
      <title>Weird Python error after extending a class</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/weird-python-error-after-extending-a-class/m-p/11288048#M5760</link>
      <description>&lt;P&gt;I've asked this question on a Python Discord server, but the people that helped me there were not able to help me with this one. I'm hoping someone here can help me with the extended class of which Fusion Python says cannot access a member of the parent class.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error I get is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;File "/Users/user/Library/Application Support/Autodesk/Autodesk Fusion 360/API/Scripts/NewScript1/modules/VKR/order.py", line 86, in __init__
app.log(str(self.__filesWithInfo))
AttributeError: 'PriorityFiles' object has no attribute '_PriorityFiles__filesWithInfo'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since there are no line-numbers in the snippet, I've added a comment of &lt;FONT face="andale mono,times"&gt;#error&lt;/FONT&gt;&amp;nbsp;in the line that produces the error. As far as I can see, I've correctly extended the &lt;FONT face="andale mono,times"&gt;FilesWithInfo&lt;/FONT&gt; class with the &lt;FONT face="andale mono,times"&gt;PriorityFiles&lt;/FONT&gt; class. Yet, the child-class does not seem to have access to the parent's class member &lt;FONT face="andale mono,times"&gt;self.__filesWithInfo&lt;/FONT&gt;. What am I doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;'''
Module to handle checking if there are files to be processed.
'''
import adsk.core, adsk.fusion, adsk.cam, traceback
import os
from ..VKR.options import OPTIONS

app = adsk.core.Application.get()

class OrderFile:
    ''' A file that has been found in the orders directory that needs to be prioritized '''

    def __init__( self, name: str ):
        self.name: str = name
        self._mod_time: int = None
        self._priority_level: int = 0

    
    def mod_time( self ) -&amp;gt; int:
        ''' Modification time '''
        return self._mod_time

    _time.setter
    def mod_time( self, time: int ):
        self._mod_time = time

    
    def priority_level( self ) -&amp;gt; int:
        ''' The priority level of the file '''
        return self._priority_level

    _level.setter
    def priority_level( self, priority: int ):
        self._priority_level = priority




class FilesWithInfo:
    ''' A holder for filenames with information stored about the files '''

    def __init__( self, files: list[ OrderFile ] = [] ):

        self.__filesWithInfo = files

    def add( self, file: OrderFile ):
        ''' Add a file with information to the storage '''

        self.__filesWithInfo.append( file )

    
    def length( self ):
        ''' Return the amount of stored files '''

        return len( self.__filesWithInfo )

    
    def priorities( self ) -&amp;gt; list[ OrderFile ] or None:
        ''' Return only the files that have priority or return None '''

        ret     = list( filter( lambda x: int( x.priority_level ) &amp;gt; 0, self.__filesWithInfo ))
        ret2    = PriorityFiles( ret )

        return ret2 if ret2.length &amp;gt; 0 else None

    
    def oldest( self, files: list[ OrderFile ] ) -&amp;gt; OrderFile:
        ''' Return the oldest file '''

        ret = None

        for x in files:
            if ret and x.mod_time &amp;lt; ret.mod_time:
                ret = x

        return ret




class PriorityFiles( FilesWithInfo ):
    ''' FilesWithInfo, but then for priority files only '''

    def __init__( self, files: list[ OrderFile ] = [] ):
        super().__init__( files )
        app.log(str(self.__filesWithInfo)) #error

    
    def highest( self ) -&amp;gt; OrderFile:
        ''' Return the filename that has the highest priority '''

        highest = None

        for f in self.__filesWithInfo:
            if highest:
                highest = f if f.priority_level &amp;gt; highest.priority_level else highest
            elif not highest:
                highest = f

        return highest
            



class Order:
    ''' Find files to process in the designated directory '''

    def __init__( self, path ):

        self.__currentDirList   = os.listdir()
        self.__currentFileInfo  = FilesWithInfo()
        self.__nextOrder        = ''
        self.__done             = True
        return

    def check( self ) -&amp;gt; OrderFile or None:
        ''' Check if there are orders that need to be processed '''
        
        self.__oldDirList       = self.__currentDirList
        self.__currentDirList   = os.listdir()
        self.__currentFileInfo  = FilesWithInfo( self._getFileInformation( self.__currentDirList ))

        if len( self.__currentDirList ) &amp;gt; 0:
            self.__nextOrder = self._selectOrder( self.__currentFileInfo )
            return self.__nextOrder
        else:
            return None

    def _selectOrder( self, fileInfo: FilesWithInfo ):
        ''' Select an order to be processed next by applying selection priority criteria '''

        
        prio        = fileInfo.priorities if isinstance(fileInfo, FilesWithInfo ) else None
        nextOrder   = None

        if isinstance( prio, PriorityFiles ):
            nextOrder = prio.highest
        elif isinstance( fileInfo, FilesWithInfo ):
            nextOrder = fileInfo.oldest

        return nextOrder

    def _getFileInformation( self, files: [str] ) -&amp;gt; FilesWithInfo:
        ''' Run through all the found files and return a Dictionary of OrderFiles '''
        
        ret = []

        for name in files:
            f_stats                     = os.stat( name )
            newFileInfo                 = OrderFile( name )
            OrderFile.mod_time          = f_stats.st_mtime
            OrderFile.priority_level    = self._getPriorityLevel( name )
            ret.append( OrderFile )
        
        return ret

    def _getPriorityLevel( self, name: str ) -&amp;gt; int:
        ''' Find if a filename has priority or not and if so, return the priority level '''
        
        if 'priority' in name:
            tmp = name.split( '_' )

            locationOfPriority = tmp.index( 'priority' ) + 1

            return tmp[ locationOfPriority ]
        else:
            return 0&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2022 09:46:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/weird-python-error-after-extending-a-class/m-p/11288048#M5760</guid>
      <dc:creator>vkr.mobile</dc:creator>
      <dc:date>2022-07-10T09:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Weird Python error after extending a class</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/weird-python-error-after-extending-a-class/m-p/11288407#M5761</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's hard to find the error with the information you provided.&lt;/P&gt;&lt;P&gt;Printing the callstack with traceback module is very handy:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import traceback
....
    try:
        app.log(str(self.__filesWithInfo)) #error
    except:
        app.log(f'Traceback: {traceback.format_exc()}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nevertheless, if your idea with the&amp;nbsp;&lt;SPAN&gt;PriorityFiles class is to find the item with the highest priority, you can replace it with a lambda's function (see next snip) which could be implemented in a&amp;nbsp;&lt;SPAN&gt;FilesWithInfo's method (that way you get rid out of the class PriorityFiles)&lt;/SPAN&gt; :&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;max(file_list, key=lambda x: x.priority_level)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Also notice that it is strange that PriorityFiles being a subclass of&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;FilesWithInfo, you use an instance of it own subclass&amp;nbsp;&lt;SPAN&gt;PriorityFiles.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Finally, this is just a Python question, and nothing to be related with Fusion 360 API behavior.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Hope this could help you.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Jorge&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2022 17:26:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/weird-python-error-after-extending-a-class/m-p/11288407#M5761</guid>
      <dc:creator>Jorge_Jaramillo</dc:creator>
      <dc:date>2022-07-10T17:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Weird Python error after extending a class</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/weird-python-error-after-extending-a-class/m-p/11289133#M5762</link>
      <description>&lt;P&gt;Apparently, properties with a double underscore are somewhat enforced as 'private' properties so that subclasses don't have easy access to them.&lt;BR /&gt;&lt;BR /&gt;Thanks for the help&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2022 12:39:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/weird-python-error-after-extending-a-class/m-p/11289133#M5762</guid>
      <dc:creator>vkr.mobile</dc:creator>
      <dc:date>2022-07-11T12:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Weird Python error after extending a class</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/weird-python-error-after-extending-a-class/m-p/11289598#M5763</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12461829"&gt;@vkr.mobile&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was referring to this method in&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;FilesWithInfo&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    def priorities( self ) -&amp;gt; list[ OrderFile ] or None:
        ''' Return only the files that have priority or return None '''

        ret     = list( filter( lambda x: int( x.priority_level ) &amp;gt; 0, self.__filesWithInfo ))
        ret2    = PriorityFiles( ret )

        return ret2 if ret2.length &amp;gt; 0 else None&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;You are creating an object of a subclass (&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;class&lt;/SPAN&gt; &lt;SPAN&gt;PriorityFiles&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;FilesWithInfo&lt;/SPAN&gt;&lt;SPAN&gt;)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;) inside it's parent class (FilesWithInfo).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'd suggest to add a highest() method (same as you have with oldest() method) inside FilesWithInfo class with the lambda expression I already send you and to remove the PriorityFiles class, which is causing the problem.&amp;nbsp; At least just to try.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Jorge&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2022 12:33:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/weird-python-error-after-extending-a-class/m-p/11289598#M5763</guid>
      <dc:creator>Jorge_Jaramillo</dc:creator>
      <dc:date>2022-07-11T12:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: Weird Python error after extending a class</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/weird-python-error-after-extending-a-class/m-p/11289615#M5764</link>
      <description>&lt;P&gt;Yeah, not very elegant. I'll change it. Thanks for the tip&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2022 12:40:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/weird-python-error-after-extending-a-class/m-p/11289615#M5764</guid>
      <dc:creator>vkr.mobile</dc:creator>
      <dc:date>2022-07-11T12:40:44Z</dc:date>
    </item>
  </channel>
</rss>

