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
def create_ring(selFrame, scale_size):
    new_objs = mm.append_objects_from_file(remote, ring_name)
    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 = flag_set_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.begin_tool(remote, "duplicate")
    #mm.accept_tool(remote)

    mm.select_objects(remote, [obj_list[0], new_objs[0]])

    mm.begin_tool(remote, "combine")
    mm.accept_tool(remote)
    return
示例#3
0
def create_ring(tar_object, selFrame, scale_size):
    new_objs = mm.append_objects_from_file(remote, ring_name)
    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")
    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)
    mm.set_toolparam(remote, "translation", translate)
    mm.accept_tool(remote)

    mm.select_objects(remote, [tar_object, new_objs[0]])

    mm.begin_tool(remote, "combine")
    mm.accept_tool(remote)
    return
示例#4
0
def drill_holes(tar_object, selFrame, filenames, scale_size, move_dy,
                flag_set_dy):
    new_objs = mm.append_objects_from_file(remote, filenames)
    mm.select_objects(remote, new_objs)

    mm.begin_tool(remote, "transform")
    mm.set_toolparam(remote, "scale", scale_size)
    #mm.set_toolparam(remote, "translation", [0,0,0])
    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 = flag_set_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.begin_tool(remote, "duplicate")
    #mm.accept_tool(remote)

    mm.select_objects(remote, [tar_object, new_objs[0]])

    mm.begin_tool(remote, "difference")
    mm.accept_tool(remote)
    return
示例#5
0
def TestFit(tar_object, 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.set_toolparam(remote, "translation", [0,0,0])
    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, [tar_object, new_objs[0]])
    result = TestIntersection(tar_object, new_objs[0])
    mm.select_objects(remote, [new_objs[0]])
    delete_select_objects()
    mm.select_objects(remote, [tar_object])
    return not result
示例#6
0
def import_connector(do_accept,connectorName):
    # initialize connection
    remote = mmRemote();
    remote.connect();
    setConnectorPath(connectorName)
    # find center of current selection, and then shoot ray from below this point, straight upwards, and
    # hope that it hits outer shell
    centroid = mm.get_face_selection_centroid(remote)
    sel_ctr = centroid
    (bFound, selFrame) = mm.find_ray_hit(remote, mm.addv3(sel_ctr, (0,-10,0)), (0,1,0)  )

    # exit out of selection tool
    mm.clear_face_selection(remote)

    # import part we want to position at selection
    cwd = os.getcwd()
    socketPath = os.path.join(cwd,'socket',connectorName)
    new_objs = mm.append_objects_from_file(remote, socketPath);

    # rename part
    mm.set_object_name(remote, new_objs[0], ConnectorName() )

    # select new part
    mm.select_objects(remote, new_objs)

    # get bbox of part, so that we can put origin at bottom of cylinder if desired (assume file authored that way)
    (min,max) = mm.get_selected_bounding_box(remote)
    partTop = ( (min[0]+max[0])/2, max[1], (min[2]+max[2])/2 )
    partCenter =  ( (min[0]+max[0])/2, (min[1]+max[1])/2, (min[2]+max[2])/2 )
    partH = max[1]-min[1]

    # RMS HACK BECAUSE OF UNITS STUPID
    plane_cut_setback = partH * 0.5

    # start transform tool
    mm.begin_tool(remote, "transform")
    cur_origin = mm.get_toolparam(remote, "origin")
    dy = 0.5*partH

    # [RMS] currently assuming that leg is oriented wrt axis, so we keep connector vertical
    # compute and apply rotation
    #rotation = mm.make_matrix_from_axes(selFrame.x, mm.negv3(selFrame.z), selFrame.y )
    #mm.set_toolparam(remote, "rotation", rotation )

    # translate origin of part to frame origin
    translate = mm.subv3( selFrame.origin, cur_origin )
    # shift along frame Z to place bottom of part on surface (ie at frame origin)
    translate = mm.addv3( translate, mm.mulv3s( selFrame.z, dy ) )
    mm.set_toolparam(remote, "translation", translate )

    # accept xform
    if do_accept:
        mm.accept_tool(remote)

    remote.shutdown()
示例#7
0
def import_connector(do_accept):
    # initialize connection
    remote = mmRemote();
    remote.connect();

    # find center of current selection, and then shoot ray from below this point, straight upwards, and
    # hope that it hits outer shell
    centroid = mm.get_face_selection_centroid(remote)
    sel_ctr = centroid
    (bFound, selFrame) = mm.find_ray_hit(remote, mm.addv3(sel_ctr, (0,-10,0)), (0,1,0)  )

    # exit out of selection tool
    mm.clear_face_selection(remote)

    # import part we want to position at selection
    cwd = os.getcwd()
    socketPath = os.path.join(cwd,'socket','socket.obj')
    new_objs = mm.append_objects_from_file(remote, socketPath);

    # rename part
    mm.set_object_name(remote, new_objs[0], ConnectorName() )

    # select new part
    mm.select_objects(remote, new_objs)

    # get bbox of part, so that we can put origin at bottom of cylinder if desired (assume file authored that way)
    (min,max) = mm.get_selected_bounding_box(remote)
    partTop = ( (min[0]+max[0])/2, max[1], (min[2]+max[2])/2 )
    partCenter =  ( (min[0]+max[0])/2, (min[1]+max[1])/2, (min[2]+max[2])/2 )
    partH = max[1]-min[1]

    # RMS HACK BECAUSE OF UNITS STUPID
    plane_cut_setback = partH * 0.5

    # start transform tool
    mm.begin_tool(remote, "transform")
    cur_origin = mm.get_toolparam(remote, "origin")
    dy = 0.5*partH

    # [RMS] currently assuming that leg is oriented wrt axis, so we keep connector vertical
    # compute and apply rotation
    #rotation = mm.make_matrix_from_axes(selFrame.x, mm.negv3(selFrame.z), selFrame.y )
    #mm.set_toolparam(remote, "rotation", rotation )

    # translate origin of part to frame origin
    translate = mm.subv3( selFrame.origin, cur_origin )
    # shift along frame Z to place bottom of part on surface (ie at frame origin)
    translate = mm.addv3( translate, mm.mulv3s( selFrame.z, dy ) )
    mm.set_toolparam(remote, "translation", translate )

    # accept xform
    if do_accept:
        mm.accept_tool(remote)

    remote.shutdown()
    # select imported part
    mm.select_objects(remote, new_objs)

    mm.begin_tool(remote, "transform")
    mm.set_toolparam(remote, "scale", [1, size, 1])
    #mm.set_toolparam(remote, "translation", [0,0,0])
    mm.accept_tool(remote)

    # get bbox of part, so that we can put origin at bottom of object if desired
    # (we are assuming that in its file, the part is positioned at the origin, on the ground plane)
    (min, max) = mm.get_selected_bounding_box(remote)

    # start transform tool
    mm.begin_tool(remote, "transform")
    cur_origin = mm.get_toolparam(remote, "origin")
    print(cur_origin)
    print(min)
    dy = -(cur_origin[1] - min[1])
    # compute and apply rotation
    rotation = mm.make_matrix_from_axes(selFrame.x, mm.negv3(selFrame.z),
                                        selFrame.y)
    mm.set_toolparam(remote, "rotation", rotation)

    # translate origin of part to frame origin
    translate = mm.subv3(selFrame.origin, cur_origin)
    # uncomment this line to shift along frame Z, this will place bottom of part on surface (ie at frame origin)
    #translate = mm.addv3( translate, mm.mulv3s( selFrame.z, dy ) )
    mm.set_toolparam(remote, "translation", translate)

    # accept xform
示例#9
0
# exit out of selection tool
mm.clear_face_selection(remote)

# import part we want to position at selection
new_objs = mm.append_objects_from_file(remote, part_filename);

# select imported part
mm.select_objects(remote, new_objs)

# get bbox of part, so that we can put origin at bottom of object if desired 
# (we are assuming that in its file, the part is positioned at the origin, on the ground plane)
(min,max) = mm.get_selected_bounding_box(remote)

# start transform tool
mm.begin_tool(remote, "transform")
cur_origin = mm.get_toolparam(remote, "origin")
dy = cur_origin[1] - min[1]

# compute and apply rotation
rotation = mm.make_matrix_from_axes(selFrame.x, mm.negv3(selFrame.z), selFrame.y )
mm.set_toolparam(remote, "rotation", rotation )

# translate origin of part to frame origin
translate = mm.subv3( selFrame.origin, cur_origin )
# uncomment this line to shift along frame Z, this will place bottom of part on surface (ie at frame origin)
#translate = mm.addv3( translate, mm.mulv3s( selFrame.z, dy ) )
mm.set_toolparam(remote, "translation", translate )

# accept xform
mm.accept_tool(remote)