Startup.py - tiny popup window?

Hello pyRevit friends,

In the last weeks i get this tiny popup window on revit startup

Is this pyRevit related?

I have a startup script for connecting a network drive, here is the code if it is relevant.
It worked for a few weeks without this popup, I din#t change anything but now I get this little window.

#-*- coding: utf-8 -*-
import os
import clr
clr.AddReference('RevitAPIUI')

from Autodesk.Revit.UI import (
    TaskDialog,
    TaskDialogCommonButtons,
    TaskDialogIcon
)

def is_drive_connected():

    try:
        os.listdir(drive_letter + ":\\")
        return True

    except:
        return False

def get_all_network_paths():
    # Retrieves all network paths.
    clr.AddReference('System.Management')
    import System.Management

    searcher = System.Management.ManagementObjectSearcher("SELECT * FROM Win32_NetworkConnection")
    network_paths = {}
    for item in searcher.Get():
        local_name = item["LocalName"]
        if local_name:
            remote_name = item["RemoteName"]
            network_paths[local_name.lower()] = remote_name
    return network_paths

def user_message(line1, line2):

    taskDialog = TaskDialog("")
    taskDialog.MainInstruction = line1
    taskDialog.MainContent = line2
    taskDialog.TitleAutoPrefix = False  
    taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconInformation
    taskDialog.CommonButtons = TaskDialogCommonButtons.Ok
    return taskDialog.Show()

def connect():

    def connect_network_drive(network_path):

        # Connects to a specific network drive.
        from System.Diagnostics import Process
        TIMEOUT_IN_MS = 10000  # For example, 10 seconds
        process = Process()
        process.StartInfo.FileName = "net.exe"
        process.StartInfo.Arguments = "use {0}: {1}".format(drive_letter, network_path)
        process.StartInfo.CreateNoWindow = True
        process.StartInfo.UseShellExecute = False
        process.Start()
        # Wait for the timeout period
        process_exited = process.WaitForExit(TIMEOUT_IN_MS)
        
        if not process_exited:  # If the process didn't exit within the timeout period
            process.Kill()  # Forcefully terminate the process
            #user_message("Timeout", "DNS server not available, can´t connect to drive X.")

    all_paths = get_all_network_paths()
    network_path = all_paths.get(drive_letter.lower() + ":")
    try:
        connect_network_drive(network_path)
        if is_drive_connected():
            return True
        else:
            user_message("Connection failed!", "Failed to connect to the network drive X. \nToolbar could not be loaded. \nPlease connect drive X and reload pyRevit to make Toolbar available.")
            return False
    except Exception as e:
        user_message("Error", str(e))
        return False

def reload():

    # Reload pyRevit.

    from pyrevit.loader import sessionmgr

    try:
        sessionmgr.reload_pyrevit()
        user_message("Success", "Network drive X has been reconnected and Toolbar has been loaded.")
    except Exception as e:
        user_message("Failed", str(e))

def app_initialized_handler(sender, args):

    """
    This function is executed when the application is fully initialized.
    It first unsubscribes itself from the ApplicationInitialized event 
    to avoid being executed again. Then, it tries to connect to the 
    network drive and, if successful, reloads the associated toolbar.
    """
    
    # Unsubscribe from the ApplicationInitialized event to avoid 
    # this handler being triggered multiple times.
    controlled_app.ApplicationInitialized -= app_initialized_handler
    
    # Try to connect to the network drive and reload the toolbar if successful.
    if connect():
        reload()

drive_letter = "X"

if not is_drive_connected():
    try:
        # Subscribe to the ApplicationInitialized event.
        controlled_app = __revit__.Application
        controlled_app.ApplicationInitialized += app_initialized_handler
    except Exception as e:
        pass


You know I’ve seen this window pop up too from time to time. I’m pretty sure it’s pyrevit related. Though what the exact cause is I don’t know. But it appears harmless to me.
My guess is that it’s either an ironpython engine spinning up or pyrevit waiting for a file to load before further initialisation is possible

I can understand it is a bit of an eyesore, though… don’t know what can be done about it.

1 Like