def addPosition(event): cur_groups = mm.list_selected_groups(remote) if len(cur_groups) == 0: setStatusText("Error! Please select an area") else: centroid = mm.get_face_selection_centroid(remote) (bFound, Frame) = mm.find_nearest(remote, centroid) selected_area.append(Frame) mm.clear_face_selection(remote) setStatusText("Position Added")
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()
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()
def addPosition(event): """ Function that is called when "Add Position" is pressed """ # check that we have a selection cur_groups = mm.list_selected_groups(remote) if len(cur_groups) == 0: setStatusText("Error! Please select an area") else: centroid = mm.get_face_selection_centroid(remote) sel_ctr = centroid (bFound, Frame) = mm.find_nearest(remote, sel_ctr) selected_area.append(Frame) mm.clear_face_selection(remote) setStatusText("Position Added")
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()
def OnAdd(self, e): global frame_dict cur_groups = mm.list_selected_groups(remote) if len(cur_groups) == 0: self.text.SetValue("Error! Please select an area") else: centroid = mm.get_face_selection_centroid(remote) (bFound, Frame) = mm.find_nearest(remote, centroid) create_ring(mm.list_selected_objects(remote)[0], Frame, [8, 2, 8]) selected_area.append(Frame) mm.clear_face_selection(remote) dlg = wx.TextEntryDialog(self, 'What you want here', 'Text Entry Dialog', '', wx.ICON_QUESTION | wx.OK | wx.CANCEL, (dis_size[0] - 400, 300)) if dlg.ShowModal() == wx.ID_OK: frame_dict[Frame] = str(dlg.GetValue()) dlg.Destroy() self.text.SetValue("Position Added")
def addPosition(event): obj_list = mm.list_selected_objects(remote) mm.select_objects(remote, [obj_list[0]]) # check that we have a selection cur_groups = mm.list_selected_groups(remote) if len(cur_groups) == 0: setStatusText("Error! Please select an area") else: print("1:") setStatusText("Computing...") centroid = mm.get_face_selection_centroid(remote) (bFound, Frame) = mm.find_nearest(remote, centroid) flag_done = 0 for size in hole_sizes: if size in used_sizes: continue print("Test:" + str(size) + ":" + str(TestFit(Frame, [size, size, size], 5))) if TestFit(Frame, [size, size, size], 5): print("Created size with" + str(size)) used_sizes.append(size) create_ring(Frame, [8, 2, 8]) drill_holes(Frame, pipe_filename, [1, 0.5, 1], 0, 0) drill_holes(Frame, hole_filename, [size, size, size], 5, 1) flag_done = 1 break print("2:" + str(flag_done)) if flag_done == 0: setStatusText( "Unable to create hole here, Please select another area") else: #text = ask(message = 'What do you want to do here?') #function_call[size]=text #pickle.dump( function_call, open( "function_dict.p", "wb" ) ) setStatusText("Position added, now you can select another area") #selected_area.append(Frame) mm.clear_face_selection(remote)
print "this script requires an active Face Selection" raw_input("Press Enter to exit...") os._exit(1) # assumption: we have object we want to modify selected, # and there is a selection made on this object obj_list = mm.list_selected_objects(remote) # find center of current selection, and then closest point on surface # this gives us a 3D frame we can align an object to centroid = mm.get_face_selection_centroid(remote) sel_ctr = centroid (bFound, selFrame) = mm.find_nearest(remote, sel_ctr) # exit out of selection tool mm.clear_face_selection(remote) for size in [0.5]: # import part we want to position at selection new_objs = mm.append_objects_from_file(remote, pipe_filename) # 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)
print "this script requires an active Face Selection" raw_input("Press Enter to exit...") os._exit(1) # assumption: we have object we want to modify selected, # and there is a selection made on this object obj_list = mm.list_selected_objects(remote) # find center of current selection, and then closest point on surface # this gives us a 3D frame we can align an object to centroid = mm.get_face_selection_centroid(remote) sel_ctr = centroid (bFound, selFrame) = mm.find_nearest(remote, sel_ctr) # 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]