Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class IMPORT_DATABASE(Operator):
- bl_idname = "importgis.database" # important since its how bpy.ops.import.shapefile is constructed (allows calling operator from python console or another script)
- # bl_idname rules: must contain one '.' (dot) charactere, no capital letters, no reserved words (like 'import')
- bl_description = 'Import data from postgis database'
- bl_label = "Import database"
- host = bpy.props.StringProperty(name="Host:", default="localhost")
- port = bpy.props.StringProperty(name="Port:", default="5432")
- database = bpy.props.StringProperty(name="Database:", default="scans")
- user = bpy.props.StringProperty(name="Username:",default="postgres")
- password = bpy.props.StringProperty(name="Password:",default="postgres")
- def execute(self, context):
- bpy.ops.importgis.database_connection('INVOKE_DEFAULT', password=self.password, username=self.user, database=self.database, port=self.port, host=self.host)
- return {'FINISHED'}
- def invoke(self, context, event):
- wm = context.window_manager
- return wm.invoke_props_dialog(self)
- class IMPORT_DATABASE_CONNECTION(Operator):
- bl_idname = "importgis.database_connection" # important since its how bpy.ops.import.shapefile is constructed (allows calling operator from python console or another script)
- # bl_idname rules: must contain one '.' (dot) charactere, no capital letters, no reserved words (like 'import')
- bl_description = 'Geometry'
- bl_label = "Geometry"
- host = StringProperty(options={'HIDDEN'})
- port = StringProperty(options={'HIDDEN'})
- database = StringProperty(options={'HIDDEN'})
- username = StringProperty(options={'HIDDEN'})
- password = StringProperty(options={'HIDDEN'})
- num = EnumProperty(
- items=get_items(),
- name="Geometry",
- description="choose a geometry",
- default=None,
- options={'ANIMATABLE'},
- update=None,
- get=None,
- set=None)
- def get_items(self):
- # condata = "dbname='%s' user='%s' host='%s' password='%s'" %
- # (self.database, self.user, self.host, self.password)
- # try:
- # conn = psycopg2.connect(condata)
- # except:
- # print ("I am unable to connect to the database")
- # cur = conn.cursor()
- # cur.execute("""SELECT * FROM public.geometry_columns""")
- # rows = cur.fetchall()
- # items = []
- # for row in rows:
- # geomItems = geomItems+row[0]+"//"+row[1]+"//"+row[2]+"#"
- # geomItems = geomItems + row[0] + "#"
- # items.append(row[0],row[1],row[2])
- items = [
- ('NONE', 'None', "Flat geometry"),
- ('GEOM', 'Geometry', "Use z value from shape geometry if exists"),
- ('FIELD', 'Field', "Extract z elevation value from an attribute field"),
- ('OBJ', 'Object', "Get z elevation value from an existing ground mesh")
- ]
- return items
- def execute(self, context):
- message = "Connection"
- self.report({'INFO'}, message)
- return {'FINISHED'}
- def invoke(self, context, event):
- print("Invoke")
- self.pretty_print()
- wm = context.window_manager
- return wm.invoke_props_dialog(self)
- import bpy
- from bpy.props import StringProperty, EnumProperty
- class ImportDataBaseConnection(bpy.types.Operator):
- bl_idname = "importgis.database_connection"
- bl_description = 'Import Geometry Data'
- bl_label = "Geometry"
- host = StringProperty(options={'HIDDEN'})
- port = StringProperty(options={'HIDDEN'})
- database = StringProperty(options={'HIDDEN'})
- username = StringProperty(options={'HIDDEN'})
- password = StringProperty(options={'HIDDEN'})
- def item_callback(self, context):
- return (
- ('NONE', 'None', "Flat geometry"),
- ('GEOM', 'Geometry', "Use z value from shape geometry if exists"),
- ('FIELD', 'Field', "Extract z elevation value from an attribute field"),
- ('OBJ', 'Object', "Get z elevation value from an existing ground mesh"),
- )
- geo_type = EnumProperty(
- items=item_callback,
- name="Geometry Type",
- description="choose a geometry",
- default=None,
- options={'ANIMATABLE'},
- update=None,
- get=None,
- set=None)
- def execute(self, context):
- message = "Connection"
- self.report({'INFO'}, message)
- return {'FINISHED'}
- def invoke(self, context, event):
- wm = context.window_manager
- return wm.invoke_props_dialog(self, width=500)
- def register():
- bpy.utils.register_class(ImportDataBaseConnection)
- def unregister():
- bpy.utils.unregister_class(ImportDataBaseConnection)
- if __name__ == "__main__":
- register()
- # test call
- bpy.ops.importgis.database_connection('INVOKE_DEFAULT')
Add Comment
Please, Sign In to add comment