vertex, faces and other mesh data

hi how are you?? thanks for reading

I’m want to add some custom objects to blender… that is so easy with some information in web and python templates, but the problem is that I need the vertex, faces and/or borders data in tuple or vector… (I’m not sure…

 verts = [Vector((-1 * scale_x, 1 * scale_y, 0)),             Vector((1 * scale_x, 1 * scale_y, 0)),
             Vector((1 * scale_x, -1 * scale_y, 0)),
             Vector((-1 * scale_x, -1 * scale_y, 0)),

that is from last python template)

then I try with cgcookie tutorial in order to access to that information : http://cgcookie.com/blender/2011/04/29/exporting-mesh-data-to-a-txt-file/comment-page-1/#comment-466682

import bpy

class exportToTXT(bpy.types.Operator):
    bl_idname = "export.export_to_txt"
    bl_label =  "Export To TXT"
    
    filepath = bpy.props.StringProperty(subtype="FILE_PATH")
    
    def execute(self, context):
        obverts = bpy.context.active_object.data.vertices
        obfaces = bpy.context.active_object.data.faces 
        
        verts =  []
        faces =  []
        
        for vertex in obverts:
            verts.append(tuple(vertex.co))
            
        for face in obfaces:
            faces.append(tuple(obfaces.vertices))    
            
            
        file = open(self.filepath, 'w')
        file.write(str(verts))
        file.write(str("











"))    #para clarificar la distancia
        file.write(str(faces))
        
            
        return {'FINISHED'}
    
    
    def invoke(self, context, event):
        context.window_manager.fileselect_add(self)
        return {'RUNNING_MODAL'}
    
   
class exportToTXTPanel(bpy.types.Panel):
    bl_idname = "Export_To_TXT"
    bl_label =  "Export To TXT"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bñ_context = "objectmode"
    
    def draw(self, context):
        layout = self.layout
        layout.operator("export.export_to_txt", text="Export to TXT")
    
    
            
def register():
    bpy.utils.register_module(__name__)


def unregister():
    bpy.utils.unregister_module(__name__)




if __name__ == "__main__":
    register()

but this is for a last api, then this tutorial is out of date :frowning:

is really crazy because when I test the code in console that’s work but when I put into script that don’t work :frowning:

then I tried with object_creaprim.py addon but is the same think… is out of date…

then I tried to see some api reference but only see some things about MeshTessFace…

and now I’m here

do you can teach me please?

thanks a lot

Diego

hello… I’m going to answere to me :smiley:

here the right and complete code to obtain data: (I made some little modifications and now this add work in blender 2.7)

http://www.pasteall.org/51127/python



- bl_info = {

-     "name": "export mesh data to TXT",

-     "author": "PATRICK BOELEN",

-     "version": (1, 0),

-     "blender": (2, 7, 0),

-     "location": "View3D > Tool Shelf",

-     "description": "EXPORT MESH DATA TO TXT",

-     "warning": "",

-     "wiki_url": "",

-     "category": "Import-Export"}

-  

-  

- <b>import</b> bpy

-  

- <b>class</b> exportToTXT(bpy.types.Operator):

-     bl_idname = "export.export_to_txt"

-     bl_label =  "Export To TXT"

-    

-     filepath = bpy.props.StringProperty(subtype="FILE_PATH")

-    

-     <b>def</b> execute(self, context):

-         obverts = bpy.context.active_object.data.vertices

-         obfaces = bpy.context.active_object.data.polygons

-  

-         verts = []

-         faces = []

-        

-  

-        

-         <b>for</b> vertex <b>in</b> obverts:

-             verts.append(tuple(vertex.co))

-            

-            

-         <b>for</b> face <b>in</b> obfaces:

-             faces.append(tuple(face.vertices))

-            

-            

-         file = open(self.filepath, 'w')

-         file.write(str("datos de Vertices:   "))

-         file.write(str("


"))

-         file.write(str(verts))

-         file.write(str("











"))

-         file.write(str("datos de Caras:   "))

-         file.write(str("


"))

-         file.write(str(faces))

-  

-        

-        

-            

-         <b>return</b> {'FINISHED'}

-    

-    

-     <b>def</b> invoke(self, context, event):

-         context.window_manager.fileselect_add(self)

-         <b>return</b> {'RUNNING_MODAL' }

-    

-    

- <b>class</b> exportToTXTPanel(bpy.types.Panel):

-     bl_idname = "Export_To_TXT"

-     bl_label =  "Export To TXT"

-     bl_space_type = "VIEW_3D"

-     bl_region_type = "TOOLS"

-     bñ_context = "objectmode"

-    

-     <b>def</b> draw(self, context):

-         layout = self.layout

-         layout.operator("export.export_to_txt", text="Export to TXT")

-    

-    

-            

- <b>def</b> register():

-     bpy.utils.register_module(__name__)

-  

- <b>def</b> unregister():

-     bpy.utils.unregister_module(__name__)

-  

-  

- <b>if</b> __name__ == "__main__":

-     register()


best and thanks :smiley:

Diego