def render_example(model_id): # select the car as object obj = bpy.data.objects[model_id] obj.select = True # scale the DimsPlane to illustrate dimensions plane = bpy.data.objects['DimsPlane'] plane.location = [0, 0, 0] roi = bounds(obj) dims = [ roi.x.max - roi.x.min, roi.y.max - roi.y.min, roi.z.max - roi.z.min ] dims = dict(zip(['x', 'y', 'z'], dims)) plane.scale.x = dims['x'] * 0.5 plane.scale.y = dims['y'] * 0.5 # save a rendered example example_file = model['example_file'] if not op.exists(atcadillac(op.dirname(example_file))): os.makedirs(atcadillac(op.dirname(example_file))) logging.info('writing example to %s' % example_file) render_scene(atcadillac(example_file))
def makeCarQueryDb(cursor): def convert(x, func=lambda x: x): ''' The CSV file has '' and 'NULL' for NULL. ''' try: return None if x in ['', 'NULL', 'Not Available'] else func(x) except Exception: logging.error('Problem converting %s' % x) raise Exception() car_query_csv_path = atcadillac('resources/CQA_Advanced.csv') with open(car_query_csv_path, 'r') as csvfile: reader = csv.reader(csvfile, delimiter=',') header = next(reader, None) # Skip the header. for irow,row in enumerate(reader): make, year, model, trim, body, L, W, H, wheelbase = np.array(row)[[1,4,2,3,5,26,27,28,29],] try: make = convert(make, lambda x: x.lower()) year = convert(year, lambda x: int(x)) model = convert(model, lambda x: x.lower()) L = convert(L, lambda x: float(x) / 1000) W = convert(W, lambda x: float(x) / 1000) H = convert(H, lambda x: float(x) / 1000) wheelbase = convert(wheelbase, lambda x: float(x) / 1000) trim = convert(trim, lambda x: x.lower()) body = convert(body, lambda x: x.lower()) except Exception as e: logging.error('Failed to parse row "%s" with exception: %s' % (np.array(row)[[1,4,2,3,5,26,27,28],], e)) raise Exception() s = 'INSERT INTO gt(%s) VALUES (?,?,?,?,?,?,?,?,?)' % ','.join(getAllGtColumns()) cursor.execute(s, (make, year, model, trim, body, L, W, H, wheelbase)) for field in getAllGtColumns(): cursor.execute('SELECT COUNT(1) FROM gt WHERE %s IS NOT NULL' % field) logging.info('Field %s has %d non-empty values.' % (field, cursor.fetchone()[0]))
if __name__ == '__main__': logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) model_path = op.join(COLLECTION_WORK_DIR, 'model.json') model = json.load(open(model_path)) scale = model['scale'] logging.info('Will scale with f=%f' % scale) dry_run = model['dry_run'] logging.info('Dry run mode is %s.' % ('on' if dry_run else 'off')) model_id = op.basename(op.splitext(model['blend_file'])[0]) logging.info('Processing model: %s' % model_id) scene_path = atcadillac('scenes/empty-import.blend') bpy.ops.wm.open_mainfile(filepath=atcadillac(model['blend_file'])) logging.info('Import succeeded.') scaleModel(model_id, scale) status = 'ok' if not dry_run: bpy.ops.wm.save_as_mainfile(filepath=atcadillac(model['blend_file'])) with open(model_path, 'w') as fid: fid.write(json.dumps({'status': status}, indent=2))
return {'dims': dims, 'x_wheels': x_wheels} if __name__ == '__main__': logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) model_path = op.join(COLLECTION_WORK_DIR, 'model.json') model = json.load(open(model_path)) model_id = op.basename(op.splitext(model['blend_file'])[0]) logging.info('Processing model: %s' % model_id) scene_path = atcadillac('scenes/empty-import.blend') bpy.ops.wm.open_mainfile(filepath=scene_path) try: import_blend_car(atcadillac(model['blend_file']), model_id) except: logging.error('Could not import .blend model: %s' % atcadillac(model['blend_file'])) model['error'] = 'blender cannot import .blend model' sys.exit() dims = get_dims(model_id) with open(model_path, 'w') as fid: fid.write(json.dumps(dims, indent=2))
cursor_out.execute(sout, entry) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--in_db_file', required=True) parser.add_argument('--out_db_file', default=':memory:') parser.add_argument('--logging', type=int, default=20) parser.add_argument('--fields', required=True, nargs='+') args = parser.parse_args() logging.basicConfig(level=args.logging, format='%(levelname)s: %(message)s') # Backup the output db. safeCopy(args.out_db_file, args.out_db_file) conn_in = sqlite3.connect(atcadillac(args.in_db_file)) cursor_in = conn_in.cursor() conn_out = sqlite3.connect(atcadillac(args.out_db_file)) cursor_out = conn_out.cursor() maybeCreateTableCad(cursor_out) # In case of in-memory db. copyDataBetweenDbs(cursor_in, cursor_out, args.fields) conn_out.commit() conn_out.close() conn_in.close()
from selenium.webdriver.support.ui import WebDriverWait import os, os.path as op #import urllib2 import logging import json import string import argparse import shutil import time import traceback from glob import glob from collectionUtilities import atcadillac CAD_DIR = atcadillac('CAD') README_NAME = 'collection.json' # delete special characters def validateString(line): for char in '\n\t"\\': line = line.replace(char, '') return line def _find_carmodel_in_vehicles_(models_info, model_id): # TODO: replace sequential search with an elasticsearch index for carmodel in models_info: if carmodel['model_id'] == model_id: return carmodel