Skip to content

Instantly share code, notes, and snippets.

@kevinCefalu
Last active April 7, 2020 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinCefalu/7b878f774a1765f9fb70a61972f015da to your computer and use it in GitHub Desktop.
Save kevinCefalu/7b878f774a1765f9fb70a61972f015da to your computer and use it in GitHub Desktop.
Function to download a thingiverse file archive
function Get-ThingiverseFile
{
[CmdletBinding()]
[OutputType([void])]
param (
[Parameter(Mandatory)]
[uint32] $Id,
[Parameter(Mandatory)]
[IO.DirectoryInfo] $OutputDirectory
);
do
{
[IO.DirectoryInfo] $Directory = "$([IO.Path]::GetTempPath())\$([Guid]::NewGuid().Guid)";
}
while ($Directory.Exists)
New-Item -ItemType Directory -Path $Directory | Out-Null;
[IO.FileInfo] $FilePath = Join-Path -Path $Directory -ChildPath "$([Guid]::NewGuid().Guid).zip";
Invoke-WebRequest -Uri "https://www.thingiverse.com/thing:$Id/zip" -OutFile $FilePath;
[IO.DirectoryInfo] $OriginalOutputDirectoryPath = $OutputDirectory.FullName;
$OutputDirectoryIncrement = 1;
while ($OutputDirectory.Exists)
{
[IO.DirectoryInfo] $OutputDirectory = (
$OriginalOutputDirectoryPath.FullName +
'-' + $OutputDirectoryIncrement++
);
}
Expand-7Zip -ArchiveFileName $FilePath -TargetPath $OutputDirectory;
Remove-Item -Path $Directory -Recurse -Force;
Start-Process $OutputDirectory;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment