0
$\begingroup$

I created a script in Visual Studios Code to generate a panel and assigned vertex groups. When I run the code in Blender it is fine however when I import it(as an OBJ file), the vertex groups don't import.

I even exported it (after having the vertex groups created in Blender) and then imported the same OBJ and it's still removing the vertex groups.

All my settings look fine. Can someone help me understand importing OBJ's into Blender and what I'm missing?

import bpy

bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete()

bpy.context.scene.unit_settings.system = 'IMPERIAL'
bpy.context.scene.unit_settings.length_unit = 'INCHES'

def generateSinglePanel():
    # Set height_width_thickness
    overall_width = 48
    overall_thickness = 3/8
    overall_height = 82

    # 1 meter = 39.3701 inches
    scale_factor = 39.3701

    # vertex positions on the (x,y,z) axis based from the measurements above.
    vertices = [
        (-overall_width / 2, -overall_thickness / 2, -overall_height / 2),
        (-overall_width / 2, -overall_thickness / 2, overall_height / 2),
        (overall_width / 2, -overall_thickness / 2, overall_height / 2),
        (overall_width / 2, -overall_thickness / 2, -overall_height / 2),
        (-overall_width / 2, overall_thickness / 2, -overall_height / 2),
        (-overall_width / 2, overall_thickness / 2, overall_height / 2),
        (overall_width / 2, overall_thickness / 2, overall_height / 2),
        (overall_width / 2, overall_thickness / 2, -overall_height / 2),
    ]

    edges = []

    faces = [
        (3, 2, 1, 0), (7, 6, 2, 3), (4, 5, 6, 7),
        (0, 1, 5, 4), (2, 6, 5, 1), (7, 3, 0, 4)
    ]

    mesh_data = bpy.data.meshes.new("PanelA_data")
    mesh_data.from_pydata(vertices, edges, faces)
    mesh_obj = bpy.data.objects.new("PanelA", mesh_data)
    bpy.context.collection.objects.link(mesh_obj)

    # Vertex Grouping Section
    # Front and Back Face Grouping
    A = (0,1,2,3)
    group1 = mesh_obj.vertex_groups.new(name='A')
    group1.add(A, 0, 'REPLACE')

    face2 = (4,5,6,7)
    group2 = mesh_obj.vertex_groups.new(name='face2')
    group2.add(face2, 0, 'REPLACE')

    face3 = (3,6,4,0)
    group3 = mesh_obj.vertex_groups.new(name='face3')
    group3.add(face3, 0, 'REPLACE')

    face4 = (2,7,6,3)
    group4 = mesh_obj.vertex_groups.new(name='face4')
    group4.add(face4, 0, 'REPLACE')

    face5 = (1,5,7,2)
    group5 = mesh_obj.vertex_groups.new(name='face5')
    group5.add(face5, 0, 'REPLACE')

    face6 = (0,4,5,1)
    group6 = mesh_obj.vertex_groups.new(name='face6')
    group6.add(face6, 0, 'REPLACE')

    # dimensions
    dimensions = mesh_obj.dimensions
    dimensions_in_inches = (overall_width) / (scale_factor), (overall_thickness) / (scale_factor), (overall_height) / (scale_factor)
    mesh_obj.dimensions = dimensions_in_inches

    # set location
    mesh_obj.location = (0, 0, 0)

generateSinglePanel()

bpy.ops.wm.obj_export(
    filepath="generateSinglePanel.obj",
    check_existing=True,
    filter_blender=False,
    filter_backup=False,
    filter_image=False,
    filter_movie=False,
    filter_python=False,
    filter_font=False,
    filter_sound=False,
    filter_text=False,
    filter_archive=False,
    filter_btx=False,
    filter_collada=False,
    filter_alembic=False,
    filter_usd=False,
    filter_obj=False,
    filter_volume=False,
    filter_folder=True,
    filter_blenlib=False,
    filemode=8,
    display_type='DEFAULT',
    sort_method='DEFAULT',
    export_animation=False,
    start_frame=-2147483648,
    end_frame=2147483647,
    forward_axis='NEGATIVE_Z',
    up_axis='Y',
    global_scale=1.0,
    apply_modifiers=True,
    export_eval_mode='DAG_EVAL_VIEWPORT',
    export_selected_objects=False,
    export_uv=True,
    export_normals=True,
    export_colors=False,
    export_materials=True,
    export_pbr_extensions=False,
    path_mode='AUTO',
    export_triangulated_mesh=False,
    export_curves_as_nurbs=False,
    export_object_groups=False,
    export_material_groups=False,
    export_vertex_groups=True,
    export_smooth_groups=False,
    smooth_group_bitflags=False,
    filter_glob='*.obj;*.mtl'
)
$\endgroup$
1

0

You must log in to answer this question.

Browse other questions tagged .