From 50b299964e1dfbbbee30f7e2c877e8c0340a3ab4 Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 26 Nov 2024 15:22:25 -0500 Subject: [PATCH] Add ResetRevitUI.ps1 --- ResetRevitUI.ps1 | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ResetRevitUI.ps1 diff --git a/ResetRevitUI.ps1 b/ResetRevitUI.ps1 new file mode 100644 index 0000000..5b2f9bf --- /dev/null +++ b/ResetRevitUI.ps1 @@ -0,0 +1,49 @@ +# Define the base path for Revit settings in the AppData folder +$basePath = "$env:APPDATA\Autodesk\Revit" + +# Get a list of directories for Revit versions +$revitVersions = Get-ChildItem -Path $basePath -Directory | Where-Object { $_.Name -match "^Revit \d{4}$" } + +# Find the latest version of Revit +$latestRevit = $revitVersions | Sort-Object Name -Descending | Select-Object -First 1 + +if ($latestRevit) { + # Path to the latest Revit folder + $latestRevitPath = $latestRevit.FullName + Write-Output "Latest Revit Version Path: $latestRevitPath" + + # Path to the UIState.dat file + $uiStateFilePath = Join-Path -Path $latestRevitPath -ChildPath "UIState.dat" + + if (Test-Path -Path $uiStateFilePath) { + Write-Output "Found UIState.dat at: $uiStateFilePath" + + # Close Revit if it is running + $revitProcess = Get-Process -Name "Revit" -ErrorAction SilentlyContinue + if ($revitProcess) { + Write-Output "Closing Revit..." + Stop-Process -Id $revitProcess.Id -Force + Start-Sleep -Seconds 5 # Wait a few seconds to ensure Revit is fully closed + } else { + Write-Output "Revit is not currently running." + } + + # Rename the UIState.dat file + $backupFilePath = "$uiStateFilePath.bak" + Rename-Item -Path $uiStateFilePath -NewName $backupFilePath + Write-Output "Renamed UIState.dat to UIState.dat.bak" + + # Relaunch Revit + $revitExePath = "C:\Program Files\Autodesk\Revit $($latestRevit.Name.Substring(6))\Revit.exe" + if (Test-Path -Path $revitExePath) { + Write-Output "Relaunching Revit..." + Start-Process -FilePath $revitExePath + } else { + Write-Output "Revit executable not found at: $revitExePath" + } + } else { + Write-Output "UIState.dat file not found in the latest Revit version folder." + } +} else { + Write-Output "No Revit version folders found in $basePath." +}