Last active
June 10, 2021 20:21
-
-
Save ChadDevOps/3c9e3697fb71a76df95c1bb5dbb575bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run as admin | |
# Summary: Generates a random shortname for directories and generates png from stl | |
# Pre-req: | |
# Install OpenSCAD (Ex using chocolatey: choco install openscad -y) | |
# Enable Shortnames in Windows 10 by running the following commands (helps with 260 char. limits): | |
# fsutil 8dot3name query | |
# fsutil behavior set disable8dot3 0 | |
# Post [optional] | |
# If you want to convert png to jpg run the following from wsl (you'll need imagemagick and parallel) | |
# find . -iname "*.png" | parallel convert -quality 95% {} {.}.jpg | |
# find . -iname "*.png" | parallel rm {} | |
# Change all dates - windows (useful to get the photos app to show all images under one date, eg. 2099-02-02): | |
# https://github.com/nrogoff/ImageProcessingConsole | |
# Change all dates - linux/wsl: | |
# sudo apt-get install libimage-exiftool-perl | |
# find . -iname "*.jpg" | parallel "exiftool -overwrite_original -AllDates='2099:02:02 02:02:02' -datetime='2099:02:02 02:02:02' {} && touch -a -m -t 209902020202 {}" | |
# Copy all jpgs and file structure - linux/wsl: | |
# find . -name '*.jpg' | parallel "cp -u --parents {} ../all_images" | |
Get-ChildItem -Recurse -Directory | ForEach-Object { | |
# or in reverse comment out above and uncomment below | |
# Get-ChildItem -Recurse -Directory | sort @{expression = {$_.fullname}} -DESC | ForEach-Object { | |
$fullpath = $_.FullName | |
$foldername = $_.Name | |
$ShortPath = (New-Object -ComObject Scripting.FileSystemObject).GetFolder($fullpath).ShortPath | |
$ShortName = $ShortPath|split-path -leaf | |
if($ShortName.Contains('~')) { | |
#echo "'$foldername' is MSDOS: $ShortName" | |
}else{ | |
if ($ShortName.length -gt 8) { | |
if($foldername -match '^[a-zA-Z0-9]'){ | |
[string]$first = $foldername.SubString(0,1) | |
}else{ | |
[string]$first = Get-Random -Minimum 1 -Maximum 9 | |
} | |
[string]$num = Get-Random -Minimum 1000 -Maximum 9999 | |
[string]$newShortName = $first + $num + '~1' | |
echo "creating MSDOS $newShortName for '$foldername' at $ShortPath" | |
& fsutil.exe file setshortname "$ShortPath" $newShortName | |
}else{ | |
# do nothing or set shortname to nothing by uncommenting the below | |
& fsutil.exe file setshortname "$ShortPath" """" | |
} | |
} | |
$ShortPath = (New-Object -ComObject Scripting.FileSystemObject).GetFolder($fullpath).ShortPath | |
Get-ChildItem -Path "$ShortPath/*.stl" | ForEach-Object { | |
[string]$stlname = $_.Name | |
[string]$stlpath = $ShortPath + '\' + $stlname | |
[string]$name = [io.path]::GetFileNameWithoutExtension("$stlpath") | |
[string]$pngname = $name + '.png' | |
[string]$jpgname = $name + '.jpg' | |
[string]$file = $ShortPath + '\' + $pngname | |
[string]$file2 = $ShortPath + '\' + $jpgname | |
if (-not(Test-Path -LiteralPath "$file" -PathType Leaf)) { | |
if (-not(Test-Path -LiteralPath "$file2" -PathType Leaf)) { | |
[string]$tmpname = "__tmpSTL4L1F3__" + $name + "__tmp" | |
[string]$tmppath = $ShortPath + '\' + $tmpname | |
cmd.exe /c "echo import(""$stlname""); >""$tmppath""" | |
cmd.exe /c "c:/PROGRA~1/OpenSCAD/openscad.exe -o ""$file"" --autocenter --viewall --imgsize=1080,1080 ""$tmppath"" > nul 2>&1" | |
echo "creating '$pngname' for '$ShortPath\$stlname'" | |
} | |
} | |
} | |
rm $ShortPath/__tmpSTL4L1F3* | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment