Example #1
0
def select_facegroups(remote, groups_list):
    """Select the faces which have a facegroup ID in groups_list"""
    cmd = mmapi.StoredCommands()
    vgroups = mmapi.vectori();
    for group in groups_list:
        vgroups.push_back(group);
    cmd2 = mmapi.StoredCommands()
    cmd2.AppendSelectCommand_ByFaceGroups(vgroups)
    remote.runCommand(cmd2)
Example #2
0
def select_triangles(remote, triangles_list, mode=0):
    """Select the listed triangles"""
    cmd = mmapi.StoredCommands()
    vtris = mmapi.vectori()
    for t in triangles_list:
        vtris.push_back(t)
    cmd2 = mmapi.StoredCommands()
    cmd2.AppendSelectCommand_ByTriangleID(vtris, mode)
    remote.runCommand(cmd2)
Example #3
0
def select_facegroups(remote, groups_list):
    """select facegroups"""
    cmd = mmapi.StoredCommands()
    vgroups = mmapi.vectori()
    for group in groups_list:
        vgroups.push_back(group)
    cmd2 = mmapi.StoredCommands()
    cmd2.AppendSelectCommand_ByFaceGroups(vgroups)
    remote.runCommand(cmd2)
Example #4
0
def show_all(remote):
    cmd = mmapi.StoredCommands()
    key = cmd.AppendSceneCommand_ShowAll()
    remote.runCommand(cmd)
    print({'result_from_show_all': cmd.GetSceneCommandResult_IsOK(key)})
    cmd = mmapi.StoredCommands()
    cmd.ViewControl_SetShowWireframe(True)  # void; no result to check
    remote.runCommand(cmd)
    cmd = mmapi.StoredCommands()
    cmd.ViewControl_SetShowBoundaries(True)  # void; no result to check
    remote.runCommand(cmd)
def TestFit(selFrame, scale_size, move_dy):
    new_objs = mm.append_objects_from_file(remote, hole_filename)
    mm.select_objects(remote, new_objs)

    mm.begin_tool(remote, "transform")
    mm.set_toolparam(remote, "scale", scale_size)
    mm.accept_tool(remote)

    (min, max) = mm.get_selected_bounding_box(remote)

    mm.begin_tool(remote, "transform")
    cur_origin = mm.get_toolparam(remote, "origin")
    dy = -((cur_origin[1] - min[1]) + move_dy * 2 / size_x)
    rotation = mm.make_matrix_from_axes(selFrame.x, mm.negv3(selFrame.z),
                                        selFrame.y)
    mm.set_toolparam(remote, "rotation", rotation)

    translate = mm.subv3(selFrame.origin, cur_origin)
    translate = mm.addv3(translate, mm.mulv3s(selFrame.z, dy))
    mm.set_toolparam(remote, "translation", translate)
    mm.accept_tool(remote)

    mm.select_objects(remote, [obj_list[0], new_objs[0]])
    result = TestIntersection(obj_list[0], new_objs[0])
    mm.select_objects(remote, [new_objs[0]])
    cmd_D = mmapi.StoredCommands()
    cmd_D.AppendSceneCommand_DeleteSelectedObjects()
    remote.runCommand(cmd_D)
    mm.select_objects(remote, [obj_list[0]])
    return not result
Example #6
0
def select_hit_triangle(remote, origin, direction):
    cmd = mmapi.StoredCommands()
    cmd.AppendSelectCommand_FirstTriangleIntersectingRay(
        origin[0], origin[1], origin[2], direction[0], direction[1],
        direction[2])

    remote.runCommand(cmd)
Example #7
0
def select_all(remote):
    """select all faces (will begin selection tool if not in it)"""
    cmd = mmapi.StoredCommands()
    cmd.AppendCompleteToolCommand("cancel")
    cmd.AppendBeginToolCommand("select")
    cmd.AppendSelectCommand_All()
    remote.runCommand(cmd)
Example #8
0
def select_objects(remote, objects_list):
    select_objects = mmapi.vectori()
    for object in objects_list:
        select_objects.push_back(object)
    cmd2 = mmapi.StoredCommands()
    cmd2.AppendSceneCommand_SelectObjects(select_objects)
    remote.runCommand(cmd2)
Example #9
0
def delete_objects(remote, objects_list):
    cur_selection = list_selected_objects(remote)
    select_objects(remote, objects_list)
    cmd = mmapi.StoredCommands()
    cmd.AppendSceneCommand_DeleteSelectedObjects()
    remote.runCommand(cmd)
    select_objects(cur_selection, remote)
Example #10
0
def link_pivot(remote, pivot_id, obj_id):
    """link pivot to a given object"""
    cmd = mmapi.StoredCommands()
    cmd_key = cmd.AppendSceneCommand_LinkPivot(pivot_id, obj_id)
    remote.runCommand(cmd)
    ok = cmd.GetSceneCommandResult_IsOK(cmd_key)
    return (ok != 0)
Example #11
0
def select_all(remote):
    """Select all faces of the active object (will initialize a Selection Tool if necessary)"""
    cmd = mmapi.StoredCommands()
    cmd.AppendCompleteToolCommand("cancel")
    cmd.AppendBeginToolCommand("select")
    cmd.AppendSelectCommand_All()
    remote.runCommand(cmd)
Example #12
0
def list_selected_groups(remote):
    """Returns a list of unique facegroup IDs for the current face selection (requires an active selection)"""
    cmd1 = mmapi.StoredCommands()
    key1 = cmd1.AppendSelectCommand_ListSelectedFaceGroups()
    remote.runCommand(cmd1)
    groups1 = mmapi.vectori()
    cmd1.GetSelectCommandResult_ListSelectedFaceGroups(key1, groups1)
    return vectori_to_list(groups1)
Example #13
0
def list_selected_objects(remote):
    """Returns a list of object IDs for the current set of selected scene objects"""
    cmd1 = mmapi.StoredCommands()
    key1 = cmd1.AppendSceneCommand_ListSelectedObjects()
    remote.runCommand(cmd1)
    objects = mmapi.vectori()
    cmd1.GetSceneCommandResult_ListObjects(key1, objects)
    return vectori_to_list(objects)
Example #14
0
def append_objects_from_file(remote, filename):
    """Read objects from a mesh file, append them to the scene, and return a list of new object IDs"""
    cmd = mmapi.StoredCommands()
    key = cmd.AppendSceneCommand_AppendMeshFile(filename)
    remote.runCommand(cmd)
    new_objs_vec = mmapi.vectori()
    cmd.GetSceneCommandResult_AppendMeshFile(key, new_objs_vec)
    return vectori_to_list(new_objs_vec)
Example #15
0
def create_pivot(remote, frame):
    """create a pivot at a given mmFrame (not frame3f)"""
    cmd = mmapi.StoredCommands()
    cmd_key = cmd.AppendSceneCommand_CreatePivot(frame.get_frame3f())
    remote.runCommand(cmd)
    new_objs_vec = mmapi.vectori()
    cmd.GetSceneCommandResult_AppendMeshFile(cmd_key, new_objs_vec)
    return new_objs_vec[0]
Example #16
0
def set_vertex_color(remote, objectid, vertexid, col):
    cmd1 = mmapi.StoredCommands()
    p = mmapi.vec3f()
    p.x = col[0]
    p.y = col[1]
    p.z = col[2]
    key1 = cmd1.AppendSceneCommand_SetVertexColor(objectid, vertexid, p)
    remote.runCommand(cmd1)
Example #17
0
def find_object_by_name(remote, obj_name):
    """Find the ID of the scene object with the given string name. Returns a 2-tuple (boolFound, object_id)"""
    cmd = mmapi.StoredCommands()
    cmd_key = cmd.AppendSceneCommand_FindObjectByName(obj_name)
    remote.runCommand(cmd)
    result_val = mmapi.any_result()
    bFound = cmd.GetSceneCommandResult_FindObjectByName(cmd_key, result_val)
    return (bFound, result_val.i)
Example #18
0
def allocate_group(remote, objectid):
    """allocates a new group id"""
    cmd1 = mmapi.StoredCommands()
    key1 = cmd1.AppendSceneCommand_AllocateNewGroupID(objectid)
    remote.runCommand(cmd1)
    result_val = mmapi.any_result()
    cmd1.GetSceneCommandResult_AllocateNewGroupID(key1, result_val)
    return result_val.i
Example #19
0
def get_object_uuid(remote, object_id):
    """Return the string uuid of the scene object with the given ID"""
    cmd = mmapi.StoredCommands()
    cmd_key = cmd.AppendSceneCommand_GetObjectUUID(object_id)
    remote.runCommand(cmd)
    byte_vec = mmapi.vectorub()
    cmd.GetSceneCommandResult_GetObjectUUID(cmd_key, byte_vec)
    return vectorub_to_string(byte_vec)
Example #20
0
def get_group(remote, objectid, triangleid):
    """returns group id for triangle"""
    cmd1 = mmapi.StoredCommands()
    key1 = cmd1.AppendSceneCommand_GetTriangleGroup(objectid, triangleid)
    remote.runCommand(cmd1)
    result_val = mmapi.any_result()
    cmd1.GetSceneCommandResult_GetTriangleGroup(key1, result_val)
    return result_val.i
Example #21
0
def get_triangle(remote, objectid, triangleid):
    """returns tuple of indices"""
    cmd1 = mmapi.StoredCommands()
    key1 = cmd1.AppendSceneCommand_GetTriangleIndices(objectid, triangleid)
    remote.runCommand(cmd1)
    t = mmapi.vec3i()
    cmd1.GetSceneCommandResult_GetTriangleIndices(key1, t)
    return (t.i, t.j, t.k)
Example #22
0
def append_vertex(remote, objectid, position, normal=(0,1,0), color=(1,1,1) ):
    """Appends a vertex to mesh and returns new VertexID"""
    cmd1 = mmapi.StoredCommands()
    key1 = cmd1.AppendSceneCommand_AppendVertex(objectid, to_vec3f(position), to_vec3f(normal), to_vec3f(color) )
    remote.runCommand(cmd1)
    result_val = mmapi.any_result()
    cmd1.GetSceneCommandResult_AppendVertex(key1, result_val)
    return result_val.i
Example #23
0
def select_objects(remote, objects_list):
    """Set the current objects selection to be the set of scene objects corresponding to the IDs in objects_list"""
    select_objects = mmapi.vectori()
    for object in objects_list:
        select_objects.push_back(object)
    cmd2 = mmapi.StoredCommands()
    cmd2.AppendSceneCommand_SelectObjects(select_objects)
    remote.runCommand(cmd2)
Example #24
0
def find_object_by_name(remote, obj_name):
    """returns tuple(boolFound, object_id)"""
    cmd = mmapi.StoredCommands()
    cmd_key = cmd.AppendSceneCommand_FindObjectByName(obj_name)
    remote.runCommand(cmd)
    result_val = mmapi.any_result()
    bFound = cmd.GetSceneCommandResult_FindObjectByName(cmd_key, result_val)
    return (bFound, result_val.i)
Example #25
0
def delete_objects(remote, objects_list):
    """Delete the scene objects corresponding to the IDs in objects_list"""
    cur_selection = list_selected_objects(remote)
    select_objects(remote, objects_list)
    cmd = mmapi.StoredCommands()
    cmd.AppendSceneCommand_DeleteSelectedObjects()
    remote.runCommand(cmd)
    select_objects(cur_selection, remote)
Example #26
0
def get_triangle_count(remote, objectid):
    """Returns number of triangles for object"""
    cmd1 = mmapi.StoredCommands()
    key1 = cmd1.AppendSceneCommand_GetTriangleCount(objectid)
    remote.runCommand(cmd1)
    result_val = mmapi.any_result()
    cmd1.GetSceneCommandResult_GetTriangleCount(key1, result_val)
    return result_val.i
Example #27
0
def list_number_of_holes(remote):
    """Returns a list of object IDs for the current set of selected scene objects"""
    cmd1 = mmapi.StoredCommands()
    key1 = cmd1.AppendQueryCommand_ListNumberOfHoles()
    remote.runCommand(cmd1)
    result_val = mmapi.any_result()
    cmd1.GetQueryResult_ListNumberOfHoles(key1, result_val)
    return result_val.i
Example #28
0
def set_vertex_position(remote, objectid, vertexid, pos):
    cmd1 = mmapi.StoredCommands()
    p = mmapi.vec3f()
    p.x = pos[0]
    p.y = pos[1]
    p.z = pos[2]
    key1 = cmd1.AppendSceneCommand_SetVertexPosition(objectid, vertexid, p)
    remote.runCommand(cmd1)
Example #29
0
def list_selected_triangles(remote):
    """Returns a list of currently-selected triangles (requires an active selection)"""
    cmd1 = mmapi.StoredCommands()
    key1 = cmd1.AppendSelectCommand_ListSelectedTriangles()
    remote.runCommand(cmd1)
    groups1 = mmapi.vectori()
    cmd1.GetSelectCommandResult_ListSelectedTriangles(key1, groups1)
    return vectori_to_list(groups1)
Example #30
0
def create_mesh(remote):
    """force MM to compactify mesh object, so that vertex/triangle ids are contiguous"""
    cmd1 = mmapi.StoredCommands()
    key1 = cmd1.AppendSceneCommand_CreateMesh()
    remote.runCommand(cmd1)
    result_val = mmapi.any_result()
    cmd1.GetSceneCommandResult_CreateMesh(key1, result_val)
    return result_val.i