Files
UVtools/UVtools.Scripts
Tiago Conceição 0ba61780b7 v2.4.0
* (Upgrade) EmguCV/OpenCV to v4.5.1
* (Upgrade) AvaloniaUI to 1.0
* (Improvement) GUI re-touched
* (Improvement) Make pixel editor tab to disappear when pixel editor is disabled
* (Improvement) Simplify the output filename from PrusaSlicer profiles
* (Improvement) All operations require a slicer file at constructor rather than on execute, this allow exposure the open file to the operation before run it
* (Improvement) Calibrations: Auto set "Mirror Output" if open file have MirrorDisplay set
* (Change) Tool - Redraw model/supports icon
* (Change) photon and cbddlp to use version 3 by default
* (Add) Tool - Dynamic layer height: Analyze and optimize the model with dynamic layer heights, larger angles will slice at lower layer height
        while more straight angles will slice larger layer height. (#131)
* (Add) Calibration - Exposure time finder: Generates test models with various strategies and increments to verify the best exposure time for a given layer height
* (Add) File load checks, trigger error when a file have critical errors and attempt to fix non-critical errors
  * Layers must have an valid image, otherwise trigger an error
  * Layers must have a incremental or equal position Z than it previous, otherwise trigger an error
  * If layer 0 starts at 0mm it will auto fix all layers, it will add Layer Height to the current z at every layer
* (Add) Tool - Edit print parameters: Allow set parameters to each x layers and skip n layers inside the given range.
        This allow the use of optimizations in a layer pattern, for example, to set 3s for a layer but 2.5s for the next.
* (Add) Layer height property to "Layer Data" table: Shows layer height for the slice
* (Fix) When automations applied and file is saved, it will not warn user about file overwrite for the first time save
* (Fix) Tool - Redraw model/supports: Disable apply button when no file selected
* (Fix) Tool - Infill: Lack of equality member to test if same infill profile already exists
* (Fix) Auto converted files from SL1 where clipping filename at first dot (.), now it only strips known extensions
* (Fix) SL1 encoded files wasn't generating the right information and lead to printer crash
* (Fix) PrusaSlicer printer "Anycubic Photon S" LiftSpeed was missing and contains a typo (#135)
* (Fix) PrusaSlicer profile manager wasnt marking missing profiles to be installed (#135)
* (Fix) PrusaSlicer folder search on linux to also look at %HOME%/.config/PrusaSlicer (#135, #136)
* (Fix) Operations were revised and some bug fixed, most about can't cancel the progress
* (Fix) Some typos on tooltips
* (Fix) Prevent PhotonS from enconding, it will trigger error now as this format is read-only
* **(Fix) Ctrl + Shift + Z to redo the last operation:**
  * The layer range is reseted instead of pull the used values
  * Tool - Arithmetic always disabled
  * Action - Layer import didn't generate info and always disabled
2021-02-06 22:09:55 +00:00
..
2021-02-06 22:09:55 +00:00
2021-01-07 05:02:13 +00:00
2021-02-06 22:09:55 +00:00

UVtools PowerShell Scripts

UVtools has become a big toolset, but do you know you can do your own scripts not limited to what GUI offers you? With PowerShell you can have access to whole UVtools.Core, which expose all core access to you to use. If you have a workflow and need to speed up, scripts can save time and dismiss the GUI interaction. You will get same performance as native calling, plus you can stack all your actions!

Requirements

How to run scripts

WARNING: Running PowerShell scripts as administrator are very powerfull and with wide access on your system. Never run scripts from untrusted sources! Always inspect the script content before run something new from others. Always try to run scripts with non-adminstration privileges.

  1. First you need to register the UVtools install directory under a environment variable. This will allow you to run scripts without have to modify each script to put the UVtools path in order to run them.
    • Open a PowerShell instance as admin
    • Enter: [System.Environment]::SetEnvironmentVariable('UVTOOLS_PATH','FOLDER/PATH/TO/UVTOOLS', [System.EnvironmentVariableTarget]::User)
    • Replace 'FOLDER/PATH/TO/UVTOOLS' with your UVtools instalation folder
    • Run command
    • Run: $Env:UVTOOLS_PATH to confirm if path is registed
    • Quit terminal
    • Note: You need to repeat this step if you change install directory
    • If your system is unable to register a environment you need to manuall set the path on each script
  2. Download and open a script with Visual Studio Code
    • After open a .ps1 file for the first time, visual code will ask if you want to install the PowerShell extension, say 'yes' and wait for instalation
  3. Click on the play arrow (Run) or F5
  4. Script will run and prompt for inputs
    • The easier way to input a file is drag and drop the file on the terminal

Documentation

The best way to get function names and variables is exploring UVtools.Core source code, most of the functions and variables have a good readable name that make sense what it does, you can only run public methods and variables.

On Visual Code, after you have an valid variable on your script, type it name with a ended dot (.) will show you a list of avaliable methods and variables that you can call. eg: $slicerFile., if the list don't show up, press CTRL+Space, that should force show the list.

Take Erode-Bottom.ps1 as bootstrap and minimal script, read each line and start exploring!

  • Core - Source code
  • IFileFormat.cs - File format functions & variables
    • How to load file:
      # Find a file format given a file path, $true = is file path, $true = Create a new instance
      # Returns null if file is invalid
      $slicerFile = [UVtools.Core.FileFormats.FileFormat]::FindByExtension($inputFile, $true, $true)
      if(!$slicerFile){ return } # Invalid file, exit
      $slicerFile.Decode($inputFile)
      
  • Layer.cs - Layer representation and hold it's own data
    • How to access:
      • $slicerFile[layerIndex]
      • $slicerFile.LayerManager[layerIndex] (Alternative)
      • $slicerFile.LayerManager.Layers[layerIndex] (Alternative)
    • Example:
      Write-Output $slicerFile[layerIndex].PositionZ
      Write-Output $slicerFile[layerIndex].ExposureTime
      Write-Output $slicerFile[layerIndex].LiftHeight
      Write-Output $slicerFile[layerIndex].LiftSpeed
      Write-Output $slicerFile[layerIndex].RetractSpeed
      Write-Output $slicerFile[layerIndex].LayerOffTime
      Write-Output $slicerFile[layerIndex].LightPWM
      Write-Output $slicerFile[layerIndex].BoundingRectangle
      Write-Output $slicerFile[layerIndex].NonZeroPixelCount
      Write-Output $slicerFile[layerIndex].IsModified
      
  • LayerManager.cs - The layer manager that keeps all layers within the file
    • How to access: $slicerFile.LayerManager
  • Operations - Applies operation over layers, the tools menu on the GUI
    • Example:
      # Erode bottom layers
      $morph = [UVtools.Core.Operations.OperationMorph]::new($slicerFile)
      $morph.MorphOperation = [Emgu.CV.CvEnum.MorphOp]::Erode
      $morph.IterationsStart = $iterations
      $morph.SelectBottomLayers()
      if(!$morph.Execute($progress)){ return }
      
      # Reuse object and erode normal layers with 1 less iteration
      $morph.IterationsStart = $iterations - 1
      $morph.SelectNormalLayers()
      if(!$morph.Execute($progress)){ return }
      
      # Rotate all layers, 45º
      $rotate = [UVtools.Core.Operations.OperationRotate]::new($slicerFile)
      $rotate.AngleDegrees = 45;
      if(!$rotate.Execute($progress)){ return }
      
      # Rotate layer 1, 90º
      $rotate.LayerIndexStart = 1
      $rotate.LayerIndexEnd = 1
      $rotate.AngleDegrees = 90
      if(!$rotate.Execute($progress)){ return }
      

Contribute with your scripts

If you make a usefull script and want to contribute you can share and publish your script under github - discussions - scripts. After analyzation it will be published on the repository