I’ve written a small addon to import models that have been saved by VTK(C++) in ASCII format
bl_info = {#represents data about the script and the version of blender it is intended for#and where it exists in the menu structure
"name": "Import VTK",
"author": "Sum Yung Gai",
"blender": (2,68,0),
"version": (1,0,0),
"location": "File > Import-Export",
"description": "Import VTK PolyData(.vtk)",
"category": "Import-Export"
}
import bpy #import bpy for blender python API access
from bpy.props import *
import os #import os for filename and directory manipulation
import re #import re for regular expression manipulation
from bpy_extras.io_utils import ImportHelper
from bpy.props import (StringProperty,
BoolProperty,
CollectionProperty,
EnumProperty,
FloatProperty,
)
from bpy_extras.io_utils import (ImportHelper)
from bpy.types import Operator, OperatorFileListElement
class ImportVTK(bpy.types.Operator, ImportHelper):
"""Load VTK triangle mesh data"""
bl_idname = "import_mesh.vtk"
bl_label = "Import VTK mesh"
bl_options = {'UNDO'}
filename_ext = ".vtk"
filter_glob = StringProperty(name=".vtk",default="*.vtk", options=('HIDDEN'))
files = CollectionProperty(name="File Path",type=OperatorFileListElement,)
directory = StringProperty(subtype='DIR_PATH',)
def execute(self, context):
from . import blender_utils
paths = [os.path.join(self.directory, name.name)
for name in self.files]
if not paths:
paths.append(self.filepath)
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode='OBJECT')
if bpy.ops.object.select_all.poll():
bpy.ops.object.select_all(action='DESELECT')
for path in paths:
objName = bpy.path.display_name(os.path.basename(path))
importVTK(path)
return {'FINISHED'}
Every time I try to register this, blender prints the following to the system console:
TypeError: StringProperty() argument 6 must be set, not str
ValueError: bpy_struct "IMPORT_MESH_OT_vtk" registration error: filter_glob could not register
I did copy this code out of the STL import/export addon and then did a bit of surgery to make it what I wanted. Apparently I missed some key bits when I was doing it. Any suggestions/ideas are appreciated.