Rhino to Blender (Mesh Bridge) import and export

Sometimes is useful to make corrections to the mesh inside Blender. To go back and forward between these two applications. And for this, thx to Rhino developers, I use just a button scripts.

Now lates version on GitHub
If you wish to improve it, it is now on GitHub

Here it is the Rhino Export command script to be added to a button. It will export to Blender:

! -_Export _GeometryOnly=_Yes _SaveTextures=_No _SaveNotes=_No _SaveSmall=_Yes
"X:\DoNotMove\Rhino-Blender-mesh.obj"
VertexWelding=Unmodified YUp=Yes enter enter

And the Rhino Import by clicking the right button. It will import from Blender:

! -_Import
"X:\DoNotMove\Rhino-Blender-mesh.obj"
MapYtoZ=Yes
enter

Then in Blender, you can use python

Rhino Blender Mesh Bridge Python V0.1 beta

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~ Alan Mattano 2020 SoaringStars lab
# ~~~~~~ 
# ~~~~~~ Blender Rhino Bridge
# ~~~~~~
# ~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import os
import bpy

def main1(context):    
    
    print("Importing...")
    full_path_to_file = "X:\DoNotMove\Rhino-Blender-mesh.obj"
    # bpy.ops.import_scene.obj(filepath=full_path_to_file)
    bpy.ops.import_scene.obj(filepath=full_path_to_file, axis_forward='-Z', axis_up='Y', filter_glob="*.obj;*.mtl")
    

def main2(context):    
    
    print("Exporting...")
    full_path_to_file = "X:\DoNotMove\Rhino-Blender-mesh.obj"
    bpy.ops.export_scene.obj(filepath=full_path_to_file, use_selection=True)


class ImportOBJMesh(bpy.types.Operator):
    """Tooltip Import"""
    bl_idname = "myops.import_rhino_add_obj"
    bl_label = "Import Rhino OBJ Mesh"

    def execute(self, context):
        main1(context)
        return {'FINISHED'}
    
class ExportOBJMesh(bpy.types.Operator):
    """Tooltip Export"""
    bl_idname = "myops.export_rhino_selected_obj"
    bl_label = "Export OBJ Mesh to Rhino"

    def execute(self, context):
        main2(context)
        return {'FINISHED'}
    
# ~~~ end Import Export ~~~~~~~~~

class AMrhinoBridgeButton(bpy.types.Panel):
    """A Alan Mattano Custom Panel in the top bar viewport for importing and exporting files fast to Rhino"""
    ui_tabTitle ="------> Rhino Bridge <--------"
    ui_topHeader = "Rhino Import and Export tool"
    declare_filepath = "X:\DoNotMove\Rhino-Blender-mesh.obj"
    
    
    bl_label = ui_tabTitle
    
    # internal blender name 
    bl_idname = "OBJECT_PT_rhinobridge"
    
    # place where will be the panle
    bl_space_type = 'PROPERTIES'    
    bl_region_type = 'WINDOW'
    bl_context = "object"    
    

    def draw(self, context):
        layout = self.layout

        # new line \n 
        row = layout.row()
              
        row.label(text="Bridge", icon='MESH_CYLINDER')
        
        # new line \n 
        row = layout.row()

        # BUTTON DELETE
        row.operator("object.delete", text="Delete Selected")
        
        # BUTTON IMPORT OBJ
        op = row.operator("myops.import_rhino_add_obj", text="IMPORT MESH")
        
        # BUTTON EXPORT OBJ
        op = row.operator("myops.export_rhino_selected_obj", text="EXPORT MESH To Rhino")

# ~~~ end Rhino Bridge Button ~~~~~~



def register():
    bpy.utils.register_class(AMrhinoBridgeButton)
    bpy.utils.register_class(ImportOBJMesh)
    bpy.utils.register_class(ExportOBJMesh)



def unregister():
    bpy.utils.unregister_class(AMrhinoBridgeButton)
    bpy.utils.unregister_class(ImportOBJMesh)
    bpy.utils.unregister_class(ExportOBJMesh)


if __name__ == "__main__":
    register()

This script will create an Import and Export button in the Object Properties section. To activate this button you need to select an object and then go to Object Properties. There you will find Import and Export buttons. There is extra code that is not needed. You can clean it. I will be creating a better version (plugin).

6 Likes

Rhino Blender Mesh Bridge Python V0.5 beta

Blender Plugin: Import only

bl_info = {
    "name": "New Rhino Object",
    "author": "Alan Mattano",
    "version": (0, 5),
    "blender": (2, 81, 0),
    "location": "View3D > Add > Mesh > New Rhino Object",
    "description": "Adds a new Mesh Object",
    "warning": "",
    "wiki_url": "",
    "category": "Add Mesh",
}


import bpy
from bpy.types import Operator
from bpy.props import FloatVectorProperty
from bpy_extras.object_utils import AddObjectHelper, object_data_add
from mathutils import Vector

class OBJECT_OT_add_object(Operator, AddObjectHelper):
    """Import a Rhino Mesh Object"""
    bl_idname = "mesh.add_object"
    bl_label = "Add Mesh Object"
    bl_options = {'REGISTER', 'UNDO'}

    scale: FloatVectorProperty(
        name="scale",
        default=(1.0, 1.0, 1.0),
        subtype='TRANSLATION',
        description="scaling",
    )

    def execute(self, context):        
        
        full_path_to_file = "X:\DoNotMove\Rhino-Blender-mesh.obj"
        # bpy.ops.import_scene.obj(filepath=full_path_to_file)
        bpy.ops.import_scene.obj(filepath=full_path_to_file, axis_forward='-Z', axis_up='Y', filter_glob="*.obj;*.mtl")

        return {'FINISHED'}


# Registration

def add_object_button(self, context):
    self.layout.operator(
        OBJECT_OT_add_object.bl_idname,
        text="Add Rhino Object",
        icon='PLUGIN')


# This allows you to right click on a button and link to documentation
def add_object_manual_map():
    url_manual_prefix = "https://discourse.mcneel.com/t/"
    url_manual_mapping = (
        ("bpy.ops.mesh.add_object", "rhino-to-blender-mesh-bridge-import-and-export/94448"),
    )
    return url_manual_prefix, url_manual_mapping


def register():
    bpy.utils.register_class(OBJECT_OT_add_object)
    bpy.utils.register_manual_map(add_object_manual_map)
    bpy.types.VIEW3D_MT_mesh_add.append(add_object_button)


def unregister():
    bpy.utils.unregister_class(OBJECT_OT_add_object)
    bpy.utils.unregister_manual_map(add_object_manual_map)
    bpy.types.VIEW3D_MT_mesh_add.remove(add_object_button)


if __name__ == "__main__":
    register()
1 Like

Rhino Blender Mesh Bridge Python V0.7 beta

Blender Plugin: Blender script side for import and export.

bl_info = {
    "name": "New Rhino Object",
    "author": "Alan Mattano, Soaring Stars lab",
    "version": (0, 7),
    "blender": (2, 81, 0),
    "location": "View3D > Add > Mesh > New Rhino Object",
    "description": "Adds a new Mesh Object",
    "warning": "",
    "wiki_url": "",
    "category": "Add Mesh",
}


import bpy
from bpy.types import Operator
from bpy.props import FloatVectorProperty
from bpy_extras.object_utils import AddObjectHelper, object_data_add
from mathutils import Vector

class OBJECT_OT_add_object(Operator, AddObjectHelper):
    """Import a Rhino Mesh Object"""
    bl_idname = "mesh.add_object"
    bl_label = "Add Mesh Object"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):        
        
        full_path_to_file = "X:\DoNotMove\Rhino-Blender-mesh.obj"
        # bpy.ops.import_scene.obj(filepath=full_path_to_file)
        bpy.ops.import_scene.obj(filepath=full_path_to_file, axis_forward='-Z', axis_up='Y', filter_glob="*.obj;*.mtl")

        return {'FINISHED'}

def add_object_button(self, context):
    self.layout.operator(
        OBJECT_OT_add_object.bl_idname,
        text="Add Rhino Object",
        icon='PLUGIN')
        
        
# This allows you to right click on a button and link to documentation
def add_object_manual_map():
    url_manual_prefix = "https://discourse.mcneel.com/t/"
    url_manual_mapping = (
        ("bpy.ops.mesh.add_object", "rhino-to-blender-mesh-bridge-import-and-export/94448"),
    )
    return url_manual_prefix, url_manual_mapping

#----------------------------------------------------------------------------

class OBJECT_OT_add_objectexport(Operator, AddObjectHelper):
    """Import a Rhino Mesh Object"""
    bl_idname = "mesh.add_objectexport"
    bl_label = "Save Mesh Object"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):        
        
        print("Exporting...")
        full_path_to_file = "X:\DoNotMove\Rhino-Blender-mesh.obj"
        bpy.ops.export_scene.obj(filepath=full_path_to_file, use_selection=True)

        return {'FINISHED'}

def add_objectexport_button(self, context):
    self.layout.operator(
        OBJECT_OT_add_objectexport.bl_idname,
        text="Save Rhino Object",
        icon='PLUGIN')


# Registration

def register():
    bpy.utils.register_class(OBJECT_OT_add_object)
    bpy.utils.register_manual_map(add_object_manual_map)
    bpy.types.VIEW3D_MT_mesh_add.append(add_object_button)
    
    bpy.utils.register_class(OBJECT_OT_add_objectexport)
    bpy.types.VIEW3D_MT_mesh_add.append(add_objectexport_button)


def unregister():
    bpy.utils.unregister_class(OBJECT_OT_add_object)
    bpy.utils.unregister_manual_map(add_object_manual_map)
    bpy.types.VIEW3D_MT_mesh_add.remove(add_object_button)
    
    bpy.utils.unregister_class(OBJECT_OT_add_objectexport)
    bpy.types.VIEW3D_MT_mesh_add.remove(add_objectexport_button)


if __name__ == "__main__":
    register()
4 Likes

If you wish to improve it, it is now on GitHub

2 Likes

Thanks for sharing very works perfectly

1 Like

Did you change directory file adress in blender? Because my Blender coulnd’t find the file and gave an error.

I do not remember. This is for Windows. And you must change the full path inside the script to much your directory full path(directory file address).

full_path_to_file = "X:\DoNotMove\Rhino-Blender-mesh.obj"

As well as in the Rhino button.
Let me know if is not working or not clear.