CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   enGrid (https://www.cfd-online.com/Forums/engrid/)
-   -   Blender Export to Engrid script for Blender 2.69? (https://www.cfd-online.com/Forums/engrid/137874-blender-export-engrid-script-blender-2-69-a.html)

eaglemckenna June 24, 2014 13:37

Blender Export to Engrid script for Blender 2.69?
 
Hi
Is there an updated export .begc to Engrid script for Blender 2.69 available?
I can only locate ones for 2.6?
kind regards
g

ogloth June 25, 2014 09:03

Did you try to run the 2.6 scripts with Blender 2.69?

eaglemckenna June 25, 2014 09:32

Hi there,
yes I have tried to run the script for 2.6 entitled io_export_engrid.py
see below for terminal error messages:
gowain@gowain-Aspire-V5-122P:/usr/share/blender/scripts$ ./io_export_engrid.py
./io_export_engrid.py: line 19: bl_info: command not found
./io_export_engrid.py: line 20: name:: command not found
./io_export_engrid.py: line 21: author:: command not found
./io_export_engrid.py: line 22: syntax error near unexpected token `0,'
./io_export_engrid.py: line 22: ` "version": (0, 2),'
gowain@gowain-Aspire-V5-122P:/usr/share/blender/scripts$

is there any other modelling software that can be used that is integrated with engrid and openfoam?

hopefully I will get the blender 2.69 export sorted soon.

kind regards
g

eaglemckenna June 25, 2014 09:35

the cat io_export_engrid.py command:
Code:

gowain@gowain-Aspire-V5-122P:/usr/share/blender/scripts$ cat io_export_engrid.py
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

bl_info = {
    "name": "Export to enGrid (.begc)",
    "author": "Unknown Author",
    "version": (0, 2),
    "blender": (2, 5, 9),
    "api": 36079,
    "location": "File > Export > enGrid (.begc)",
    "description": "Export objects as boundaries to enGrid's Blender exchange format (*.begc)",
    "warning": "",
    "wiki_url": "http://engits.eu/wiki",
    "tracker_url": "http://sourceforge.net/apps/mantisbt/engrid",
    "category": "Import-Export"}

'''
Usage Notes:
'''

import bpy
from bpy.props import *
import mathutils, math, struct
from os import remove
import time
from bpy_extras.io_utils import ExportHelper


def do_export(context, props, filepath):
    mat_x90 = mathutils.Matrix.Rotation(-math.pi/2, 4, 'X')

    obmnames=""
    obmcount=0
    for obj in bpy.data.objects:
        if obj.type == 'MESH':
            obmcount+=1
            obmnames+=obj.name+'\n'
   
    if obmcount!=0:
        node_offset = 0
        out = open(filepath, "w")
        out.write('%d' % obmcount)
        out.write('\n')
        out.write(obmnames)
       
        for obj in bpy.data.objects:
            if obj.type == 'MESH':
                mesh = obj.to_mesh(context.scene, props.apply_modifiers, 'PREVIEW')
                if props.world_space:
                    mesh.transform(obj.matrix_world)
                if props.rot_x90:
                    mesh.transform(mat_x90)
                faces = mesh.faces
                nodes = mesh.vertices
                out.write('%d' % len(nodes))
                out.write(' %d\n' % len(faces))
                for n in nodes:
                    out.write("%e " % n.co[0])
                    out.write("%e " % n.co[1])
                    out.write("%e\n" % n.co[2])
                for f in faces:
                    out.write("%d" % len(f.vertices))
                    for v in f.vertices:
                        out.write(' %d' % (v + node_offset))
                    out.write('\n')
                node_offset = node_offset + len(nodes)
        out.flush()
        out.close()
    return True


###### EXPORT OPERATOR #######
class Export_engrid(bpy.types.Operator, ExportHelper):
    bl_idname = "export_shape.engrid"
    bl_label = "Export enGrid (.begc)"
    filepath = "untitled"
    filename_ext = ".begc"


    rot_x90 = BoolProperty(name="Convert to Y-up",
            description="Rotate 90 degrees around X to convert to y-up",
            default=False,
            )
    world_space = BoolProperty(name="Export into Worldspace",
            description="Transform the Vertexcoordinates into Worldspace",
            default=True,
            )
    apply_modifiers = BoolProperty(name="Apply Modifiers",
            description="Applies the Modifiers",
            default=True,
            )

    @classmethod
    def poll(cls, context):
        return context.active_object.type in {'MESH', 'CURVE', 'SURFACE', 'FONT'}

    def execute(self, context):
        start_time = time.time()
        print('\n_____START_____')
        print(self.filepath)
        props = self.properties
        filepath = self.filepath
        filepath = bpy.path.ensure_ext(filepath, self.filename_ext)
        print(self.filepath)
        exported = do_export(context, props, filepath)

        if exported:
            print('finished export in %s seconds' %((time.time() - start_time)))
            print(filepath)

        return {'FINISHED'}

    def invoke(self, context, event):
        wm = context.window_manager

        if True:
            # File selector
            wm.fileselect_add(self) # will run self.execute()
            return {'RUNNING_MODAL'}
        elif True:
            # search the enum
            wm.invoke_search_popup(self)
            return {'RUNNING_MODAL'}
        elif False:
            # Redo popup
            return wm.invoke_props_popup(self, event)
        elif False:
            return self.execute(context)


### REGISTER ###

def menu_func(self, context):
    self.layout.operator(Export_engrid.bl_idname, text="enGrid (.begc)")


def register():
    bpy.utils.register_module(__name__)
    bpy.types.INFO_MT_file_export.append(menu_func)

def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.INFO_MT_file_export.remove(menu_func)

if __name__ == "__main__":
    register()


eaglemckenna June 27, 2014 09:16

Hi
I installed the blender 2.63a version and ran the script for blender 2.63a for engrid export within the following scripts directory and received the following error.
I am sure it is something simple I am not doing right and would be most grateful for your help. thanks
Code:

gowain@gowain-Aspire-V5-122P:~/Blender 2.63a/blender-2.63a-linux-glibc27-x86_64/2.63/scripts$ ./io_export_engrid.py
./io_export_engrid.py: line 19: bl_info: command not found
./io_export_engrid.py: line 20: name:: command not found
./io_export_engrid.py: line 21: author:: command not found
./io_export_engrid.py: line 22: syntax error near unexpected token `1,'
./io_export_engrid.py: line 22: `    "version": (1, 1),'

then i tried python command and it states there is no bpy module:

Code:

gowain@gowain-Aspire-V5-122P:~/Blender 2.63a/blender-2.63a-linux-glibc27-x86_64/2.63/scripts$ python io_export_engrid.py
Traceback (most recent call last):
  File "io_export_engrid.py", line 35, in <module>
    import bpy
ImportError: No module named bpy
gowain@gowain-Aspire-V5-122P:~/Blender 2.63a/blender-2.63a-linux-glibc27-x86_64/2.63/scripts$

apologies once again
g

wyldckat July 1, 2014 16:05

Greetings to all!

@Gowain: Uhm... you're not meant to run the scripts from the command line. You're meant to install them in Blender and then use them in Blender:
Best regards,
Bruno

ogloth July 3, 2014 05:51

Hello,

I just tried the scripts with Blender 2.7 and it worked without problem, so I assume that 2.69 will be fine too.

Regards,
Oliver

eaglemckenna July 4, 2014 08:40

Thanks so much guys
It's sorted now.
:)

student666 August 29, 2014 20:15

I changed the blender export script as the one posted above gives me following errors:

Code:

mesh object has no attribute faces
I changed ti according to http://blenderartists.org/forum/show...ute-Faces-quot

Code:

# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

bl_info = {
    "name": "Export to enGrid (.begc)",
    "author": "Unknown Author",
    "version": (0, 2),
    "blender": (2, 5, 9),
    "api": 36079,
    "location": "File > Export > enGrid (.begc)",
    "description": "Export objects as boundaries to enGrid's Blender exchange format (*.begc)",
    "warning": "",
    "wiki_url": "http://engits.eu/wiki",
    "tracker_url": "http://sourceforge.net/apps/mantisbt/engrid",
    "category": "Import-Export"}

'''
Usage Notes:
'''

import bpy
from bpy.props import *
import mathutils, math, struct
from os import remove
import time
from bpy_extras.io_utils import ExportHelper


def do_export(context, props, filepath):
    mat_x90 = mathutils.Matrix.Rotation(-math.pi/2, 4, 'X')

    obmnames=""
    obmcount=0
    for obj in bpy.data.objects:
        if obj.type == 'MESH':
            obmcount+=1
            obmnames+=obj.name+'\n'
   
    if obmcount!=0:
        node_offset = 0
        out = open(filepath, "w")
        out.write('%d' % obmcount)
        out.write('\n')
        out.write(obmnames)
       
        for obj in bpy.data.objects:
            if obj.type == 'MESH':
                mesh = obj.to_mesh(context.scene, props.apply_modifiers, 'PREVIEW')
                if props.world_space:
                    mesh.transform(obj.matrix_world)
                if props.rot_x90:
                    mesh.transform(mat_x90)
                polygons = mesh.polygons
                nodes = mesh.vertices
                out.write('%d' % len(nodes))
                out.write(' %d\n' % len(polygons))
                for n in nodes:
                    out.write("%e " % n.co[0])
                    out.write("%e " % n.co[1])
                    out.write("%e\n" % n.co[2])
                for f in polygons:
                    out.write("%d" % len(f.vertices))
                    for v in f.vertices:
                        out.write(' %d' % (v + node_offset))
                    out.write('\n')
                node_offset = node_offset + len(nodes)
        out.flush()
        out.close()
    return True


###### EXPORT OPERATOR #######
class Export_engrid(bpy.types.Operator, ExportHelper):
    bl_idname = "export_shape.engrid"
    bl_label = "Export enGrid (.begc)"
    filepath = "untitled"
    filename_ext = ".begc"


    rot_x90 = BoolProperty(name="Convert to Y-up",
            description="Rotate 90 degrees around X to convert to y-up",
            default=False,
            )
    world_space = BoolProperty(name="Export into Worldspace",
            description="Transform the Vertexcoordinates into Worldspace",
            default=True,
            )
    apply_modifiers = BoolProperty(name="Apply Modifiers",
            description="Applies the Modifiers",
            default=True,
            )

    @classmethod
    def poll(cls, context):
        return context.active_object.type in {'MESH', 'CURVE', 'SURFACE', 'FONT'}

    def execute(self, context):
        start_time = time.time()
        print('\n_____START_____')
        print(self.filepath)
        props = self.properties
        filepath = self.filepath
        filepath = bpy.path.ensure_ext(filepath, self.filename_ext)
        print(self.filepath)
        exported = do_export(context, props, filepath)

        if exported:
            print('finished export in %s seconds' %((time.time() - start_time)))
            print(filepath)

        return {'FINISHED'}

    def invoke(self, context, event):
        wm = context.window_manager

        if True:
            # File selector
            wm.fileselect_add(self) # will run self.execute()
            return {'RUNNING_MODAL'}
        elif True:
            # search the enum
            wm.invoke_search_popup(self)
            return {'RUNNING_MODAL'}
        elif False:
            # Redo popup
            return wm.invoke_props_popup(self, event)
        elif False:
            return self.execute(context)


### REGISTER ###

def menu_func(self, context):
    self.layout.operator(Export_engrid.bl_idname, text="enGrid (.begc)")


def register():
    bpy.utils.register_module(__name__)
    bpy.types.INFO_MT_file_export.append(menu_func)

def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.INFO_MT_file_export.remove(menu_func)

if __name__ == "__main__":
    register()

hope this can help

KateEisenhower April 21, 2015 05:54

Hello,

I try to use the export script 2.63a io_export_engrid.py version from sourceforge with Blender 2.74 on OS X. As intended I put the script in the Contents/Resources/2.74/scripts folder. However in the File/export menu I can't see any export to enGrid option.
Has anyone experienced the same. Is it generally just supposed to work with the Linux version of Blender?

KateEisenhower April 21, 2015 08:45

Okay, I got it. You have to put the the import and export script inside the Contents/Resources/2.74/scripts/addons folder. After that go to File/User Preferences in blender, search for the scripta and activate them.

Davidkep July 29, 2019 14:52

Blender Export to Engrid script for Blender 2 69
 
Hi guys

i dont have much info about scripting, I have this script for zbrush import/export, its for windows and Im using Mac osx, i tried to use it on Mac but apparently only "Obj out"export works fine but the "Obj in"import Dosent work, can anyone help me to rewrite this script for Mac ? i tried it on windows and it worked fine.btw i tried to fix it by changing the location of the folder to match Mac path

Copy the 2 files into your Zplusg64, and the two button will show on your right button on you zbrush screen.

Thanks in advance

SimonStar April 23, 2020 05:37

Hello,

is there somewhere a guide how to put a script into blender? Or how did you do that exactly?

I'm still in the beginning with trying to understad OpenFoam and the meshinge, so I guess I need mone help.

Tanks for any help.


All times are GMT -4. The time now is 16:47.