Jump to content

Blender 3D: Noob to Pro/Import and Render a SolidWorks Model/vrmlbatch.py

From Wikibooks, open books for an open world
#!BPY 

""" Registration info for Blender menus: 
Name: 'VRML batch loader'
Blender: 237 
Group: 'Import' 
Tooltip: 'Loads all .wrl files from a user defined folder' 
"""
#--------------------------------------------------------------------------
# Author Ewout                                     - Version 1.0 -  5 Aug 05
# Using Blender file dialog: b2b revision by Ewout - Version 1.1 - 16 Aug 05
#--------------------------------------------------------------------------
# The purpose of this script is to automatically load wrl (VRML) files,
# saved out from Solidworks assemblies as individual part files, from a
# source folder.When finished loading save as .blend before continuing.
#
# Depending on the source of the VRML files, you may have some empty files,
# which results in a message from blender: "ERROR: Found no data"
# just keep your mouse moving and ignore this message :o)
#--------------------------------------------------------------------------
# Copyright 2005. Not for resale.


import Blender
import sys
import os
print "loading script"

filename = ""

def f(name): # file selector callback
  global filename
  filename = name

  path = Blender.sys.dirname(filename)
  ext = '.wrl'
  print "Searching " + path
  for filename in os.listdir(path):
     if filename.endswith(ext): #check to make sure its a wrl file
       Blender.Load(path + "/" + filename)
  print "finished"

Blender.Window.FileSelector(f, "Open files in this dir")