Skip to content

Instantly share code, notes, and snippets.

@ialhashim
Last active February 5, 2024 18:21
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ialhashim/9522211 to your computer and use it in GitHub Desktop.
Save ialhashim/9522211 to your computer and use it in GitHub Desktop.
==============================
Expression: (id=\d)(.+?)(")
==============================
Python script to download:
import os.path
import urllib.request
links = open('list.txt', 'r')
c=0
for link in links:
prefix = "https://3dwarehouse.sketchup.com/3dw/getbinary?subjectClass=entity&name=s&subjectId="
prefix6 = "https://3dwarehouse.sketchup.com/3dw/getbinary?subjectClass=entity&name=s6&subjectId="
prefix7 = "https://3dwarehouse.sketchup.com/3dw/getbinary?subjectClass=entity&name=s7&subjectId="
prefix8 = "https://3dwarehouse.sketchup.com/3dw/getbinary?subjectClass=entity&name=s8&subjectId="
link = link.strip()
name = link.rsplit('/', 1)[-1]
filename = os.path.dirname(os.path.realpath(__file__)) + "\\downloads\\" + ("%03d" % c) + ".skp"
c += 1
if not os.path.isfile(filename):
print('Downloading: ' + filename)
try:
urllib.request.urlretrieve(prefix8 + link, filename)
except Exception as inst:
print(inst)
print(' Encountered unknown error. Continuing.')
try:
urllib.request.urlretrieve(prefix7 + link, filename)
except Exception as inst:
print(inst)
print(' Encountered unknown error. Continuing.')
try:
urllib.request.urlretrieve(prefix6 + link, filename)
except Exception as inst:
print(inst)
print(' Encountered unknown error. Continuing.')
try:
urllib.request.urlretrieve(prefix + link, filename)
except Exception as inst:
print(inst)
print(' Encountered unknown error. Continuing.')
===========================================
Ruby to convert to STL
==========================
STL_ASCII = 'ASCII'.freeze
OPTIONS = {
'selection_only' => false,
'export_units' => 'Model Units',
'stl_format' => STL_ASCII
}
STL_Exporter = CommunityExtensions::STL::Exporter
model_path = Sketchup.active_model.path
model_basename = File.basename(model_path, ".skp")
model_dir = File.dirname(model_path)
Dir.entries(model_dir).each{ |d|
file_load = File.join(model_dir,d)
next if File.extname(file_load).upcase!=".SKP"
mbasename = File.basename(file_load, ".skp")
next if File.exist?(model_dir + "/" + mbasename + ".stl")
model = Sketchup.active_model
entities = model.active_entities
definitions = model.definitions
status = entities.clear!
componentdefinition = definitions.load( file_load )
point = Geom::Point3d.new 0,0,0
transform = Geom::Transformation.new point
instance = entities.add_instance componentdefinition, transform
e = instance
target_size = 1.m
s = [e.bounds.width, e.bounds.height, e.bounds.depth].max
r = target_size / s
t = Geom::Transformation.scaling(r)
e.transform!(t)
mpath = Sketchup.active_model.path
outfile = "#{model_dir}/#{mbasename}.stl"
STL_Exporter.export(outfile, OPTIONS)
}
@vinyvince
Copy link

Hola!
Would this script allow me to batch download a full collection of sketchup model with picture preview in collection selected in warehouse?
Im on osx mac, snow leopard, how could i run it please?

@joseribe
Copy link

joseribe commented Nov 8, 2017

Como puedo usar este script para descargar varios modelos del 3d warehouse, muchas gracias

@vinyvince
Copy link

Will be nice to have more description please for those who are not familiar with Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment