Reimport and Update Mesh

python
addons

#1

I am not an expert in programming Blender addons and would be happy to receive tips to implement the following:

Keyshot is a rendering software that is often used by industrial designers.
It has an fast and easy to use collaboration with CAD software through plugins.

CAD Software: Modeling —> Keyshot: Visualization:
Edit CAD (Rhino) —> One Click: Update Keyshot Render Scene —> Check Design —> Edit CAD —> One Click: Update Keyshot render scene …

I think Blender can be a free and better alternative to keyshot. What’s missing is just a little “Update Geometrie Plugin”

The Plan:

  • Import geometry via OBJ.
  • Import first Time:
    Does the object name from the OBJ file not existent in the blendfile, everything runs with normal OBJ import.
  • Import second time / update
    If a mesh/object exists with the name from the OBJ,
    the mesh is updated. Material and object are not touched.

How to do the mesh update?
(It is important that the name is kept and that no name.001 is created.)

Way 1:
Just overwrite the mesh data
bpy.data.meshes[name].faces / vetices…
But it looks like, it’s not possible?

Way 2:
bpy.ops - something like this ?: Blenderartists Topic

    bpy.ops.mesh.select_all(action='DESELECT')
    bpy.ops.object.mode_set(mode='OBJECT')
    for v in bpy.context.object.data.vertices:
        if v.co[1] > 0:
            v.select = True
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.delete(type='VERT')

Way 3:
Rename, delete and create mesh -> Create new with correct name?

Which one should I take? Thanks! :slight_smile:

Next steps:
Rhino Plugin -> OBJ Export -> IPC File -> Blender Plugin


#2

You should be able to simply import the new mesh, remove the old one, and rename the new one to the original name without actually editing any meshes. If you do end up needing to edit the mesh directly, use BMesh.


#3

Thanks. Bmesh is a wired to me… :slight_smile:
and for now, this way seems to work:

#dataname = Object name

#Deselect and select
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects[dataname].select_set(state=True)
bpy.context.view_layer.objects.active = bpy.data.objects[dataname]

# Remove vertecies to clean mesh blank before add new imported
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.reveal()
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.delete(type='VERT')
bpy.ops.object.mode_set(mode='OBJECT')

me = bpy.data.meshes[dataname]

default obj import script follows…

me.vertices.add(len(verts_loc))
me.loops.add(tot_loops)
me.polygons.add(len(faces))