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
|
# UVtools Script
########################
# Script Configuration #
########################
$_TITLE = 'List Layers'
$_DESCRIPTION = 'List all layers and show it information'
$_AUTHOR = 'Tiago Conceição'
$_VERSION = 1
$_CORE_PATH = '' # Input folder path to 'UVtools.Core.dll' if unable to work with env variables
#eg: [System.Environment]::SetEnvironmentVariable('UVTOOLS_PATH','C:\Program Files (x86)\UVtools', [System.EnvironmentVariableTarget]::User)
##############
# Dont touch #
##############
# Sets the culture
$currentThread = [System.Threading.Thread]::CurrentThread
$culture = [System.Globalization.CultureInfo]::InvariantCulture
$currentThread.CurrentCulture = $culture
$currentThread.CurrentUICulture = $culture
##############
# Dont touch #
##############
# Usefull Variables
$dirSeparator = [IO.Path]::DirectorySeparatorChar
$scriptPath = $MyInvocation.MyCommand.Name
$scriptFilenameNoExt = [System.IO.Path]::GetFileNameWithoutExtension($scriptPath);
$coreDll = 'UVtools.Core.dll'
$inputFile = $null
$slicerFile = $null
##############
# Dont touch #
##############
# Script information
Write-Output "###############################################"
Write-Output "UVtools Script: ${scriptFilenameNoExt}.ps1"
Write-Output "Title: $_TITLE"
Write-Output $_DESCRIPTION
Write-Output "Author: $_AUTHOR"
Write-Output "Version: $_VERSION"
Write-Output "###############################################"
try{
if(Test-Path "$Env:UVTOOLS_PATH${dirSeparator}${coreDll}" -PathType Leaf){
Add-Type -Path "$Env:UVTOOLS_PATH${dirSeparator}${coreDll}"
}
elseif(Test-Path "${_CORE_PATH}${dirSeparator}${coreDll}" -PathType Leaf) {
Add-Type -Path "${_CORE_PATH}${dirSeparator}${coreDll}"
} else {
Write-Error "Unable to find $coreDll, solutions are:
1) Open powershell with admin and run: [System.Environment]::SetEnvironmentVariable('UVTOOLS_PATH','FOLDER/PATH/TO/UVTOOLS', [System.EnvironmentVariableTarget]::User)
2) Edit the script and set the _CORE_PATH variable with the FOLDER/PATH/TO/UVTOOLS
Path example: 'C:\Program Files (x86)\UVtools'
Exiting now!"
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
while ($null -eq $inputFile){ # Keep asking for a file if the input is invalid
$inputFile = read-host "Enter input file"
if($inputFile -eq 'q' -or $inputFile -eq 'e' -or $inputFile -eq 'exit')
{
return;
}
if (-not(test-path $inputFile)){
Write-host "Invalid file path, re-enter."
$inputFile = $null
}
elseif ((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
}
}
}
##############
# Dont touch #
##############
# Decode the file
Write-Output "Decoding, please wait..."
$slicerFile.Decode($inputFile, $progress);
###################################################
# All operations over the file should be put here #
###################################################
foreach($layer in $slicerFile){
Write-Output $layer.ToString()
}
##############
# Dont touch #
##############
# 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}${dirSeparator}${fileNoExt}_modified${fileExt}"
#Write-Output "Saving as ${fileNoExt}_modified${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
}
|