-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodify_exposures.ps1
More file actions
181 lines (164 loc) · 5.99 KB
/
modify_exposures.ps1
File metadata and controls
181 lines (164 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# UVtools Script
#Testing for powershell v7, it's required
# Check for required PowerShell version (7+)
if (!($PSVersionTable.PSVersion.Major -ge 7)) {
try {
# Install PowerShell 7
if(!(Test-Path "$env:SystemDrive\Program Files\PowerShell\7")) {
Write-Output 'Installing PowerShell version 7...'
Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet"
}
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# Restart script in PowerShell 7
pwsh "`"$PSCommandPath`"" (($MyInvocation.Line -split '\.ps1[\s\''\"]\s*', 2)[-1]).Split(' ')
} catch {
Write-Output 'PowerShell 7 was not installed. Update PowerShell and try again.'
throw $Error
} finally { Exit }
}
$inputFile = $null
$slicerFile = $null
#Find the User Documents folder, for default folder when running Get-Filename
$folderpath = "$($env:OneDriveConsumer)\documents"
IF($null -eq (get-childitem -Path $folderpath))
{
$folderpath = "$($env:UserProfile)\documents"
}
Function Get-FileName
{
param (
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName,position=0)]
[string]$folderpath,
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName,position=1)]
[string]$title
)
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.Title = $title
$OpenFileDialog.initialDirectory = $folderpath
$outer = New-Object System.Windows.Forms.Form
$outer.StartPosition = [Windows.Forms.FormStartPosition] "Manual"
$outer.Location = New-Object System.Drawing.Point -100, -100
$outer.Size = New-Object System.Drawing.Size 10, 10
$outer.add_Shown( {
$outer.Activate();
$outer.DialogResult = $OpenFileDialog.ShowDialog($outer);
$outer.Close();
} )
$outer.ShowDialog()
$OpenFileDialog.FileName
}
#end function Get-FileName
Write-Output "Loading UVTools.Core.dll"
try
{
Add-Type -Path "C:\Program Files\UVtools\UVtools.Core.dll"
}
catch
{
try
{
Add-Type -Path "C:\Program Files (x86)\UVtools\UVtools.Core.dll"
}
catch
{
Write-Error "Unable to find $coreDll"
$folderpath = 'C:\Program Files\'
Add-Type -Path ((Get-Filename $folderpath "Please Select the UVTools.Core.dll file on your system.")[2])
return
}
}
# Progress variable, not really used here but require with some methods
$progress = New-Object UVtools.Core.Operations.OperationProgress
##############
# Dont touch #
##############
# Input file and validation
$open_count = 3
$inputFile = $null
while (($null -eq $inputFile) -and ($open_count -gt 0))
{ # Keep asking for a file if the input is invalid
write-output "Please select the Base Slicer File in the dialog box"
$inputFile = (Get-FileName $folderpath "Please Select the Base Slicer File")[2]
if($null -eq $inputFile)
{
return;
}
if((get-item $inputFile).psiscontainer)
{
Write-host "Input file must be an valid file, re-enter."
$inputFile = $null
}
else
{
$slicerFile = [UVtools.Core.FileFormats.FileFormat]::FindByExtensionOrFilePath($inputFile, $true)
if(!$slicerFile)
{
Write-host "Invalid file format, re-enter."
$inputFile = $null
}
}
$open_count--
}
IF($open_count -eq 0){
exit
}
######################################
# All user inputs should be put here #
######################################
# Input iterations number
[decimal]$max = 0;
while ($max -le 0) { # Keep asking for a number if the input is invalid
[decimal]$max = Read-Host "Enter Maximum Exposure Value (In Seconds)"
}
IF($max.ToString() -notlike "*.*")
{
}
[decimal]$step_value = 0;
while ($step_value -le 0) { # Keep asking for a number if the input is invalid
[decimal]$step_value = Read-Host "Enter Value for each Exposure Step"
}
[int]$iterations = 0;
while ($iterations -le 0) { # Keep asking for a number if the input is invalid
[int]$iterations = Read-Host "Number of Exposure Step iterations"
}
##############
# Dont touch #
##############
# Decode the file
Write-Output "Decoding, please wait..."
$slicerFile.Decode($inputFile, $progress);
###################################################
# All operations over the file should be put here #
###################################################
# Morph bottom erode
Write-Output "Creating $iterations files with Max Exposure: $("{0:n2}" -f $max) and a Step Exposure of $step_value"
$count = $iterations
While($count -gt 0)
{
try
{
$exposure = $max
$slicerFile.ExposureTime = $exposure
# Save file with _modified name appended
$filePath = [System.IO.Path]::GetDirectoryName($inputFile)
$fileExt = [System.IO.Path]::GetExtension($inputFile)
$fileNoExt = [System.IO.Path]::GetFileNameWithoutExtension($inputFile)
$fileOutput = "${filePath}\${fileNoExt}_$("{0:n2}" -f $exposure)${fileExt}"
Write-Output "Saving as ${fileNoExt}_$("{0:n2}" -f $exposure)${fileExt}, please wait..."
$slicerFile.SaveAs("$fileOutput", $progress)
Write-Output "$fileOutput"
Write-Output "Finished!"
}
catch
{
# Catch errors
Write-Error "An error occurred:"
Write-Error $_.ScriptStackTrace
Write-Error $_.Exception.Message
Write-Error $_.Exception.ItemName
}
$max = $max - $step_value
$count--
}