示例#1
0
def connector_join():
    remote = mmRemote();
    remote.connect();

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

    [found,id1] = mm.find_object_by_name(remote,'socket')
    [found,id2] = mm.find_object_by_name(remote,"connector")
    mm.select_objects(remote,[id1,id2])



    # combine part with socket
    mm.begin_tool(remote, "combine")

    # select-all and do join # [TODO] support select-boundary-loops in API
    mm.select_all(remote)
    mm.begin_tool(remote, "join")
    mm.accept_tool(remote)


    [foundconnector,id1] = mm.find_object_by_name(remote,'connector')
    ## we need to rename the connector back to socket
    if foundconnector:
        cmd  = mmapi.StoredCommands()
        cmd.AppendSceneCommand_SetObjectName(id1,'socket')
        remote.runCommand(cmd)

    ## [RMS] this block will clean up holes, but requires ability to save & restore selection!
    ##   [TODO] we can do this now, because we can read back facegroup after createFaceGroup...
    #if False:
    #    # save selection
    #    mm.begin_tool(remote, "createFaceGroup")
    #    mm.clear_face_selection(remote)

    #    # do repair pass, in case join created holes (happens!)
    #    mm.begin_tool(remote, "inspector")
    #    mm.tool_utility_command(remote, "repairAll")

    #    # [TODO] restore selection


    ## expand selection a few times, then remesh
    #if True:
    #    for x in range(0,8):
    #        mm.selection_utility_command(remote, "expandByOneRing")

    #    mm.begin_tool(remote, "remesh")
    #    mm.accept_tool(remote)
    #    mm.begin_tool(remote, "smooth")
    #    mm.set_toolparam(remote, "scale", 500.0)
    #    mm.accept_tool(remote)

    #mm.clear_face_selection(remote)

    remote.shutdown()
示例#2
0
def connector_join():
    remote = mmRemote();
    remote.connect();

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

    [found,id1] = mm.find_object_by_name(remote,SocketName())
    [found,id2] = mm.find_object_by_name(remote,ConnectorName())
    mm.select_objects(remote,[id1,id2])



    # combine part with socket
    mm.begin_tool(remote, "combine")

    # select-all and do join # [TODO] support select-boundary-loops in API
    mm.select_all(remote)
    mm.begin_tool(remote, "join")
    mm.accept_tool(remote)

    # [RMS] this block will clean up holes, but requires ability to save & restore selection!
    #   [TODO] we can do this now, because we can read back facegroup after createFaceGroup...
    if False:
        # save selection
        mm.begin_tool(remote, "createFaceGroup")
        mm.clear_face_selection(remote)

        # do repair pass, in case join created holes (happens!)
        mm.begin_tool(remote, "inspector")
        mm.tool_utility_command(remote, "repairAll")

        # [TODO] restore selection


    # expand selection a few times, then remesh
    if True:
        for x in range(0,8):
            mm.selection_utility_command(remote, "expandByOneRing")

        mm.begin_tool(remote, "remesh")
        mm.accept_tool(remote)
        mm.begin_tool(remote, "smooth")
        mm.set_toolparam(remote, "scale", 500.0)
        mm.accept_tool(remote)

    mm.clear_face_selection(remote)

    remote.shutdown()
示例#3
0
def main():
    env_dist = os.environ
    apipath = env_dist.get('ITF')
    home_dir1 = apipath + "\\Surface_approximation\\meshmixer_API\\python"
    home_dir2 = apipath + "\\Surface_approximation\\meshmixer_API\\distrib\\python"

    sys.path.append(home_dir2)
    sys.path.append(home_dir1)

    fname = apipath + "\\Surface_approximation\\Input Parameters.txt"
    with open(fname, 'r') as f:
        lines = f.readlines()
        last_line = lines[-1]

    #print(sys.path)

    import mmapi
    import platform
    import socket
    from mmRemote import *
    import mm
    import math
    import shutil

    # initialize connection
    remote = mmRemote()
    remote.connect()
    examples_dir = os.getcwd()
    cmd = mmapi.StoredCommands()

    path = apipath + "\\Surface_approximation\\Examples\\Intermediate"
    if os.path.isdir(path + "/remesh"):  #check if the folder exists
        shutil.rmtree(path + "/remesh")  #if it exists, delete it
    os.mkdir(path + "/remesh")  #if it's not, build it

    if not os.path.exists(path + "/stl"):
        print("No stl folder in /Surface_approxiamtion/Examples/Intermediate")
        print("We will now build it automaticly for you")
        os.mkdir(path + "/stl")

    files = os.listdir(path + "/stl")  #read names of all stl files
    #print(files)
    if files == []:
        print(
            "No stl files in folder(/Surface_approxiamtion/Examples/Intermediate/stl/)"
        )
        print(
            "You should close this window, click the preprocess button and then remesh button"
        )
        time.sleep(1000)
        os._exit(0)

    for file in files:
        input_file = path + "/stl" + "/" + file
        print(input_file)
        output_file1 = path + "/remesh" + "/" + file
        output_file = output_file1[:-3]
        output_file += "obj"
        #str_list = list(output_path)
        #nPos = str_list.index('.')
        #str_list.insert(nPos,'_remesh')
        #output_path = "".join(str_list)
        print(output_file)
        key = cmd.AppendSceneCommand_AppendMeshFile(input_file)
        remote.runCommand(cmd)

        #build remesh parameters EdgeLength
        mm.tool.begin_tool(remote, "stability")
        area = mm.tool.get_toolparam(remote, "surfaceArea")
        mm.tool.accept_tool(remote)
        #a = area
        length = math.sqrt(area / 3600)
        length /= 2
        #print(sys.argv[0])
        #last_line = last_line[1:-1]
        #print(last_line)

        parameter = float(last_line)
        #print(parameter)
        length *= parameter
        #print(length)
        #length *= 0.0021
        #print("area:"+ area)

        #start remeshing
        selected_objects_all = mm.select_all(remote)
        mm.tool.begin_tool(remote, "remesh")
        mm.tool.set_toolparam(remote, "edgeLength", length)
        mm.tool.set_toolparam(
            remote, "boundaryMode",
            2)  # 0:freeboundary; 1:fixedboundary; 2:refinedfixedboudary
        mm.tool.set_toolparam(
            remote, "goalType", 2
        )  # RelativeDensity = 0, AdaptiveDensity = 1, TargetEdgeLength = 2, LinearSubdivision = 3
        cmd.AppendCompleteToolCommand
        mm.tool.accept_tool(remote)
        mm.scene.export_mesh(remote, output_file)  #build remeshed stl file
        #print(mm.scene.get_vertex_count(remote, selected_objects_all))
        #str_list = list(input_path)
        #nPos = str_list.index('.')
        #str_list.insert(nPos,'_remesh')
        #output_path = "".join(str_list)
        #input_path = raw_input("Enter Filename: ")
    time.sleep(5)
    remote.shutdown()
示例#4
0
#   - select a patch on original object and Attract To Target
#   (coded for default bunny, but should work with other objects)

import mmapi
from mmRemote import *
import mm

# initialize connection
r = mmRemote()
r.connect()

# 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)
#   - select a patch on original object and Attract To Target
#   (coded for default bunny, but should work with other objects)

import mmapi
from mmRemote import *
import mm

# initialize connection
r = mmRemote()
r.connect()

# 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)