pythonparsingprogress-bar3dsmax

How to retrieve code for .exe file and see how is it build and working?


The thing is that there 3dsmaxcmd.exe which is used for rendering, and which is capable to show how long does it take and estimated time till finish. is capable to show how long does it take and estimated time till finish

And my goal is to extract that both timedates, or see how is it built and counting progress, to build that kind of tool myself. By this approach im willing to solve an issue of keeping progress of rendering single frame. Any other approaches and ideas are welcome)

thank you for you attention!


Solution

  • I created a sample code that grabs the timestamps from an image. I broke it up into a few functions that should get you started.

    To get the window screenshot and all the text using OCR (optical character recognition)

    *Note: I am using a Mac so I haven't tested the get_window_screenshot() on windows.

    def get_window_screenshot(window_title):
        if DEBUG:
            im = Image.open('3dsmaxcmd_exe.jpeg')
            return im
        screenshot = pyautogui.screenshot()
        if system_platform == 'Windows':
            # for windows
            window = pygetwindow.getWindowsWithTitle(window_title)
            l, t = window.topleft
            r, b = window.bottomright
        elif system_platform == 'Darwin':
            # for mac
            l, t, w, h = pygetwindow.getWindowGeometry(window_title)
            r = l + w
            b = t + h
        screenshot = screenshot.crop((l, t, r, b))
        return screenshot
    
    def get_window_content(window_screenshot):
        # returns all content in image as a string
        content = pytesseract.image_to_string(window_screenshot)
        return content
    

    That gets me: Current Task: Rendering image... [02:08:05.9] [02:09:37.0 est]

    Now to get the timestamps. Here is a way you can do it:

    def get_timestamps(content):
        t_list = []
        timestamp = _find_timestamp(content)
        while timestamp:
            t_list.append(timestamp[0])
            timestamp = _find_timestamp(content, timestamp[1])
        return t_list
    
    def _find_timestamp(content, start=0):
        timestamp_start = content.find('[', start + 1)
        timestamp_end = content.find(']', start + 1)
        if timestamp_start > 0 and timestamp_end > 0:
            return content[timestamp_start + 1: timestamp_end], timestamp_end
        return False
    

    Calling this function gives me: ['02:08:05.9', '02:09:37.0 est']

    Here's the code I used to run:

    import platform
    
    import pyautogui
    import pytesseract
    import pygetwindow
    from PIL import Image
    
    system_platform = platform.system()
    
    DEBUG = True
    
    if __name__ == '__main__':
        window_shot = get_window_screenshot("I'm debugging")
        content = get_window_content(window_shot)
        timestamps = get_timestamps(content)