Skip to content

Commit

Permalink
Python docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sn4k3 committed Apr 6, 2022
1 parent 331d37b commit 6065d8f
Show file tree
Hide file tree
Showing 10 changed files with 1,599 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,4 @@ MigrationBackup/

build/secret/
manifests/

.idea/
File renamed without changes.
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions Scripts/UVtools.Python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# UVtools Python Scripting

![Logo](https://github.com/sn4k3/UVtools/raw/master/UVtools.CAD/UVtools_python.png)

## Requirements

- [Python 3.x](https://www.python.org/downloads)
- [Pythonnet 3.x](https://github.com/pythonnet/pythonnet)
- `pip install git+https://github.com/pythonnet/pythonnet`
- [.NET 6.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)
- [UVtools](https://github.com/sn4k3/UVtools/releases/latest):
- Windows: Must install MSI
- Linux and macOS: Need to register `UVTOOLS_PATH` (Environment Variable)
- Near your .py script:
- [UVtoolsBootstrap.py](https://github.com/sn4k3/UVtools/blob/master/Scripts/UVtools.Python/UVtoolsBootstrap.py)
`wget https://github.com/sn4k3/UVtools/blob/master/Scripts/UVtools.Python/UVtoolsBootstrap.py`
- [UVtools.runtimeconfig.json](https://github.com/sn4k3/UVtools/blob/master/Scripts/UVtools.Python/UVtools.runtimeconfig.json)
`wget https://github.com/sn4k3/UVtools/blob/master/Scripts/UVtools.Python/UVtools.runtimeconfig.json`

## Bootstrap

```python
#!/usr/bin/env python
"""print_layers.py: Print all layers from a file."""
__author__ = "Someone"
__copyright__ = "Copyright 2022, Planet Earth"
from UVToolsBootstrap import *

# Your code here
```


## Documentation

- Must explore [UVtools.Core](https://github.com/sn4k3/UVtools/tree/master/UVtools.Core) code, functions and arguments
are the same as source.
- See [code samples](https://github.com/sn4k3/UVtools/tree/master/Scripts/UVtools.Python)

## Support
https://github.com/sn4k3/UVtools/discussions/categories/scripts

## 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](https://github.com/sn4k3/UVtools/discussions/categories/scripts).
58 changes: 58 additions & 0 deletions Scripts/UVtools.Python/UVToolsBootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python
"""
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
"""
from clr_loader import get_coreclr
from pythonnet import set_runtime
import sys
import platform
import os

UVTOOLS_PATH = None
if platform.system() == 'Windows':
try:
import winreg

key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\UVtools', 0, winreg.KEY_READ)
UVTOOLS_PATH = winreg.QueryValueEx(key, 'InstallDir')[0]
if key:
winreg.CloseKey(key)
except:
pass
else:
UVTOOLS_PATH = os.getenv('UVTOOLS_PATH')

if UVTOOLS_PATH is None or not os.path.exists(UVTOOLS_PATH):
print("Unable to find UVtools path, please install and register the path with a Environment Variable (UVTOOLS_PATH)")
exit(-1)

# Don't touch
# Set runtime
sys.path.append(UVTOOLS_PATH)
rt = get_coreclr(r"UVtools.runtimeconfig.json")
set_runtime(rt)
import clr

clr.AddReference(r"UVtools.Core")
from UVtools.Core import *
from UVtools.Core.EmguCV import *
from UVtools.Core.Extensions import *
from UVtools.Core.FileFormats import *
from UVtools.Core.GCode import *
from UVtools.Core.Layers import *
from UVtools.Core.Managers import *
from UVtools.Core.MeshFormats import *
from UVtools.Core.Network import *
from UVtools.Core.Objects import *
from UVtools.Core.Operations import *
from UVtools.Core.PixelEditor import *
from UVtools.Core.Printer import *
from UVtools.Core.Scripting import *
from UVtools.Core.Suggestions import *
from UVtools.Core.SystemOS import *

print(f'{About.SoftwareWithVersionArch}')
9 changes: 9 additions & 0 deletions Scripts/UVtools.Python/UVtools.runtimeconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.3"
}
}
}
21 changes: 21 additions & 0 deletions Scripts/UVtools.Python/print_layers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
"""print_layers.py: Print all layers from a file."""
__author__ = "Someone"
__copyright__ = "Copyright 2022, Planet Earth"
from UVToolsBootstrap import *

file = input('Input the file path: ')

slicerFile = None
try:
slicerFile = FileFormat.Open(file)
except Exception as e:
print(e)
exit(-1)

if slicerFile is None:
print(f'Unable to find {file} or it\'s invalid file')
exit(-1)

for layer in slicerFile:
print(layer)
Loading

0 comments on commit 6065d8f

Please sign in to comment.