コード例 #1
0
def drill_holes(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.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, "difference")
    mm.accept_tool(remote)
    return
コード例 #2
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
コード例 #3
0
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
コード例 #4
0
ファイル: connector.py プロジェクト: SemaphoreTO/socketmixer
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()
コード例 #5
0
ファイル: connector.py プロジェクト: applekey/wizard
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()
コード例 #6
0
ファイル: connector.py プロジェクト: SemaphoreTO/socketmixer
def connector_plane_cut(do_accept):
    remote = mmRemote();
    remote.connect();

    # accept outstanding tools, if there are any
    mm.accept_tool(remote)

    # get bbox of connector
    mm.select_object_by_name(remote, ConnectorName() )
    (min,max) = mm.get_selected_bounding_box(remote)
    partCenter =  ( (min[0]+max[0])/2, (min[1]+max[1])/2, (min[2]+max[2])/2 )
    partH = max[1]-min[1]

    mm.select_object_by_name(remote, SocketName() )

    # shoot ray upwards to hit exterior of socket, and then get facegroup of outer shell
    (bounds_min, bounds_max) = mm.get_selected_bounding_box(remote)
    bounds_ctr = mm.mulvs(mm.addv3(bounds_min, bounds_max), 0.5)
    mm.begin_tool(remote, "select")
    mm.select_hit_triangle(remote, mm.addv3(bounds_ctr, (0,-10,0)), (0,1,0) )
    groups = mm.list_selected_groups(remote)

    # select outer shell facegroup and start plane cut
    mm.select_facegroups(remote, groups)
    mm.begin_tool(remote, "planeCut")

    # position cutting plane at offset from part
    mm.set_toolparam(remote, "fillType", 0)
    planeNormal = (0,1,0)
    #mm.set_toolparam(remote, "normal", planeNormal )
    planeOrigin = max
    planeOrigin = mm.addv3( planeOrigin, mm.mulv3s(planeNormal, 0.5*partH) )
    mm.set_toolparam(remote, "origin", planeOrigin)

    if do_accept:
        mm.accept_tool(remote)

    remote.shutdown()
コード例 #7
0
ファイル: connector.py プロジェクト: applekey/wizard
def connector_plane_cut(do_accept):
    remote = mmRemote();
    remote.connect();

    # accept outstanding tools, if there are any
    mm.accept_tool(remote)

    # get bbox of connector
    mm.select_object_by_name(remote, ConnectorName() )
    (min,max) = mm.get_selected_bounding_box(remote)
    partCenter =  ( (min[0]+max[0])/2, (min[1]+max[1])/2, (min[2]+max[2])/2 )
    partH = max[1]-min[1]

    mm.select_object_by_name(remote, SocketName() )

    # shoot ray upwards to hit exterior of socket, and then get facegroup of outer shell
    (bounds_min, bounds_max) = mm.get_selected_bounding_box(remote)
    bounds_ctr = mm.mulvs(mm.addv3(bounds_min, bounds_max), 0.5)
    mm.begin_tool(remote, "select")
    mm.select_hit_triangle(remote, mm.addv3(bounds_ctr, (0,-10,0)), (0,1,0) )
    groups = mm.list_selected_groups(remote)

    # select outer shell facegroup and start plane cut
    mm.select_facegroups(remote, groups)
    mm.begin_tool(remote, "planeCut")

    # position cutting plane at offset from part
    mm.set_toolparam(remote, "fillType", 0)
    #planeNormal = (0,1,0)
    #mm.set_toolparam(remote, "normal", planeNormal )
    planeOrigin = max
    planeOrigin = mm.addv3( planeOrigin, mm.mulv3s(planeNormal, 0.5*partH) )
    mm.set_toolparam(remote, "origin", planeOrigin)

    if do_accept:
        mm.accept_tool(remote)

    remote.shutdown()
コード例 #8
0
    mm.begin_tool(remote, "transform")
    cur_origin = mm.get_toolparam(remote, "origin")
    print(cur_origin)
    print(min)
    move_dy = 5 * 2 / 129.66
    print(move_dy)
    dy = -((cur_origin[1] - min[1]) + move_dy)
    # 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)

    # make a copy of the object, because boolean will delete it and it is useful to be able to see where the part was
    #mm.begin_tool(remote, "duplicate")
    #mm.accept_tool(remote)

    # select original object and cylinder we imported
    mm.select_objects(remote, [obj_list[0], new_objs[0]])

    # do a boolean difference to subtract the object
    mm.begin_tool(remote, "difference")
    mm.accept_tool(remote)