Exemple #1
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()
Exemple #2
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()
# save initial selection list
initial_selection = mm.list_selected_objects(r)

# generate shell using Offset tool
mm.select_all(r)
mm.begin_tool(r, "offset")
mm.set_toolparam(r, "offsetWorld", 1.25)
mm.accept_tool(r)

# now Offset is done, and shell is selected. Next we Separate it
mm.begin_tool(r, "separate")
mm.accept_tool(r)

# read back current selection (will be shell)
shell_objects = mm.list_selected_objects(r)
mm.set_object_name(r, shell_objects[0], "shell")

# set current as target (will be offset shell)
mm.set_as_target(r)

# restore original selection
mm.select_objects(r, initial_selection)

# select an area on the surface
(found,sfc_pt) = mm.find_nearest(r, (1,1,1))
mm.select_inside_sphere(r, sfc_pt.origin, mm.toS(r,10.0))

# run Attract to Target tool
mm.begin_tool(r, "attractToTarget")
mm.accept_tool(r)
# save initial selection list
initial_selection = mm.list_selected_objects(r)

# generate shell using Offset tool
mm.select_all(r)
mm.begin_tool(r, "offset")
mm.set_toolparam(r, "offsetWorld", 1.25)
mm.accept_tool(r)

# now Offset is done, and shell is selected. Next we Separate it
mm.begin_tool(r, "separate")
mm.accept_tool(r)

# read back current selection (will be shell)
shell_objects = mm.list_selected_objects(r)
mm.set_object_name(r, shell_objects[0], "shell")

# set current as target (will be offset shell)
mm.set_as_target(r)

# restore original selection
mm.select_objects(r, initial_selection)

# select an area on the surface
(found, sfc_pt) = mm.find_nearest(r, (1, 1, 1))
mm.select_inside_sphere(r, sfc_pt.origin, mm.toS(r, 10.0))

# run Attract to Target tool
mm.begin_tool(r, "attractToTarget")
mm.accept_tool(r)