Skip to content

Add preview images and a script to extract them #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1321 Battery 9V/1321 Battery 9V.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1376 NeoPixel Strip/1376 NeoPixel Strip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1426 8x NeoPixel Stick/1426 8x NeoPixel Stick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1463 16x NeoPixel Ring/1463 16x NeoPixel Ring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1501 Trinket 5V/1501 Trinket 5V.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1578 500mAh battery/1578 500mAh battery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1586 24x NeoRing/1586 24x NeoRing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1586 NeoPixel Ring 24x/1586 NeoPixel Ring 24x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1602 CAP1188/1602 CAP1188.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1680 5in TFT Display/1680 5in TFT Display.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1739 Pizero Large/1739 Pizero Large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1752 MAX9744/1752 MAX9744.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1781 2200mAh Battery/1781 2200mAh Battery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1946 Adafruit FONA/1946 Adafruit FONA.png
Binary file removed 1946 Adafruit FONA/1946-Adafruit-FONA-800-GSM.jpg
Diff not rendered.
Binary file added 1982 MPR121/1982 MPR121.png
Binary file added 2011 2000mAh Battery/2011 2000mAh Battery.png
Binary file added 2130 PAM8302/2130 PAM8302.png
Binary file added 2190 Verter 5V USB/2190 Verter 5V USB.png
Binary file added 2201 Submicro servo/2201 Submicro servo.png
Binary file added 2226 NeoPixel Jewel/2226 NeoPixel Jewel.png
Binary file added 2232 5in HDMI Backpack/2232 5in HDMI Backpack.png
Binary file added 2315 PiTFT 2.2/2315 PiTFT 2.2.png
Binary file added 2423 PiTFT 2.8/2423 PiTFT 2.8.png
Binary file added 2441 PiTFT 3.5/2441 PiTFT 3.5.png
Binary file added 2465 Powerboost 1000C/2465 Powerboost 1000C.png
Binary file added 258 1200mAh lipo/258 1200mAh lipo.png
Binary file added 2756 Teensy 3.2/2756 Teensy 3.2.png
Binary file added 2809 LIS3DH/2809 LIS3DH.png
Binary file added 2884 Proto FeatherWing/2884 Proto FeatherWing.png
Binary file added 2900 Feather OLED Wing/2900 Feather OLED Wing.png
Binary file added 3006 MAX98357/3006 MAX98357.png
Diff not rendered.
Binary file added 3010 Feather M0 Wifi/3010 Feather M0 Wifi.png
Binary file added 3093 Crickit CPX/3093 Crickit CPX.png
Binary file added 3101 8mm soft button/3101 8mm soft button.png
Binary file added 3102 Mini Joystick/3102 Mini Joystick.png
Binary file added 3202 Spy Camera/3202 Spy Camera.png
Binary file added 3221 Toggle Switch/3221 Toggle Switch.png
Binary file removed 3221 Toggle Switch/3221-Toggle-Switch.jpg
Diff not rendered.
Binary file added 328 2500mAh battery/328 2500mAh battery.png
Binary file added 3347 metal ball button/3347 metal ball button.png
Binary file added 3464 Joy Bonnet/3464 Joy Bonnet.png
Binary file added 3500 Trinket M0/3500 Trinket M0.png
Binary file added 3501 GEMMA M0/3501 GEMMA M0.png
Binary file added 353 6600mAh Battery/353 6600mAh Battery.png
Binary file added 354 4400mah battery/354 4400mah battery.png
Binary file added 355 MOSFET P-channel/355 MOSFET P-channel.png
Binary file added 3577 PICO Hat/3577 PICO Hat.png
Binary file added 3632 Joy FeatherWing/3632 Joy FeatherWing.png
Binary file added 3692 TRS Jack/3692 TRS Jack.png
Binary file added 3722 Snowglobe/3722 Snowglobe.png
Binary file added 3727 ItsyBitsy M0/3727 ItsyBitsy M0.png
Binary file added 3777 TT Motor/3777 TT Motor.png
Binary file added 3842 3xAA Battery/3842 3xAA Battery.png
Binary file added 3900 Hallowing/3900 Hallowing.png
Binary file removed 3923 Mini Oval Speaker/3923-mini-oval-speaker.jpg
Diff not rendered.
Binary file removed 3954 Adafruit NeoTrellis/neotrellis-preview.jpg
Diff not rendered.
Binary file added 562 10K Potentiometer/562 10K Potentiometer.png
Binary file added 610 DC Jack/610 DC Jack.png
Binary file added 64 Halfsize Breadboard/64 Halfsize Breadboard.png
Binary file added 67 9V Battery Holder/67 9V Battery Holder.png
Binary file added 711 DC Toy Motor/711 DC Toy Motor.png
Binary file added 723 Minty Perma-Proto/723 Minty Perma-Proto.png
Binary file added 805 slide switch/805 slide switch.png
Binary file added 817 Zippy Micro Switch/817 Zippy Micro Switch.png
Binary file added 830 Battery Holder/830 Battery Holder.png
Binary file added 858 Stepper Motor 5VDC/858 Stepper Motor 5VDC.png
Binary file added 916 metal button/916 metal button.png
Binary file added 931 OLED 128x32 I2C/931 OLED 128x32 I2C.png
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# Adafruit_CAD_Parts
STEP, Fusion 360, and STL files for various boards, components and parts
Fusion 360 design files for various boards, components and parts

## get-previews.py
This script extracts preview PNGs from F3D files (which are actually just ZIPs.) Invoke it with `python get-previews.py` to extract previews for all products that don't already have them. The script will automatically put the images in the right directories.

By default, the script skips over any product folders that already have a PNG matching the title of the product. This means that if you want to export a custom image from Fusion 360 instead of the default thumbnail (let's say, for product 610 DC Jack), as long as you set the filename to match the product name (`610 DC Jack.png`), the script won't overwrite your custom image. You can, however, override this behavior with the `--force` command line flag - this causes the script to overwrite any existing PNGs with the extracted previews.

*Note: This script is written for Python 3, although a quick test indicates Python 2 might work. YMMV.*
=======
STEP, Fusion 360, and STL files for various boards, components and parts
35 changes: 35 additions & 0 deletions get-previews.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from argparse import ArgumentParser
from fnmatch import filter as fnfilter
from glob import glob
from os.path import dirname, exists, join
from zipfile import ZipFile

parser = ArgumentParser(description='Extract thumbnail images from F3D files')
parser.add_argument('--force', action='store_true', help='overwrite existing thumbnails')
parser.add_argument('-v', action='store_true', help='enable verbose logging')
args = parser.parse_args()

f3dfiles = glob('**/*.f3d')

for f3dfile in f3dfiles:
productname = dirname(f3dfile)
targetimagepath = join(productname, '{}.png'.format(productname))
if exists(targetimagepath):
if args.force:
print('Preview image for {} already exists, but --force was specified so we\'re overwriting it'.format(productname))
else:
if args.v:
print('Preview image for {} already exists; skipping (pass --force to override)'.format(productname))
continue

zipfile = ZipFile(f3dfile)
pngs = fnfilter(zipfile.namelist(), '**/Previews/*.png')
if len(pngs) <= 0:
print('Could not find a preview image for {}; skipping'.format(productname))
continue
biggestPNG = sorted(pngs, key=(lambda png: zipfile.getinfo(png).file_size))[0]

with open(targetimagepath, 'wb') as f:
f.write(zipfile.read(biggestPNG))

print('Extracted preview image for {}'.format(productname))