def OnClick(self, e): obj_list = mm.list_selected_objects(remote) mm.select_objects(remote, [obj_list[0]]) cur_groups = mm.list_selected_groups(remote) if len(cur_groups) == 0: self.text.SetValue("Error! Please select an area") else: self.text.SetValue("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 if flag_done==0: self.text.SetValue("Unable to create hole here, Please select another area") else: dlg = wx.TextEntryDialog(self,'What you want here', 'Text Entry Dialog','',wx.ICON_QUESTION | wx.OK | wx.CANCEL,(dis_size[0]-300,200)) if dlg.ShowModal() == wx.ID_OK: function_call[size]=str(dlg.GetValue()) pickle.dump(function_call,open( "function_dict.p", "wb")) self.text.SetValue("updated:"+dlg.GetValue()) dlg.Destroy()
def backtracking(node): global final_result global used_sizes global selected_area global action_dict global frame_dict print("start: " + str(node.object)) if selected_area == []: final_result = node.object print(str(node.object) + " return 1") return 1 cur_frame = selected_area.pop() while len(node.possible_size): if final_result: print("result found") print(str(node.object) + " break") break print(str(node.object) + " possible: " + str(node.possible_size)) size = node.possible_size[0] for move_dy in tube_length: if not TestFit(node.object, cur_frame, [size, size, size], move_dy): print(str(node.object) + " removed " + str(size)) node.possible_size.remove(size) else: print(str(node.object) + " picked " + str(size)) node.possible_size.remove(size) action_dict[size] = frame_dict[cur_frame] mm.select_objects(remote, [node.object]) mm.begin_tool(remote, "duplicate") mm.accept_tool(remote) copy_object = mm.list_selected_objects(remote)[0] drill_holes(copy_object, cur_frame, pipe_filename, [1, 0.1 * move_dy + 0.1, 1], 0, 0) drill_holes(copy_object, cur_frame, hole_filename, [size, size, size], move_dy, 1) child = State(copy_object) child.used_size = size used_sizes.append(size) child.frame = cur_frame print("used size: " + str(used_sizes)) child.possible_size = list(set(hole_sizes) - set(used_sizes)) print( str(child.object) + " possible: " + str(child.possible_size)) backtracking(child) break print(str(node.object) + " return -2") if node.used_size != None: used_sizes.remove(node.used_size) if node.frame != None: selected_area.append(cur_frame) return -2
def OnCreate(self, e): if len(hole_sizes) < len(selected_area): self.text.SetValue("Too many selected area") return root = State(mm.list_selected_objects(remote)[0]) backtracking(root) print(final_result) if final_result: mm.select_objects(remote, [final_result]) pickle.dump(action_dict, open("action_dict.p", "wb")) self.text.SetValue("Success!") else: self.text.SetValue("Unable to assign holes")
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)
def scratch(remote): print(mm.list_selected_objects(remote)) return None
# selection examples: # - list selected objects # - list selected facegroups import mmapi from mmRemote import * import mm # initialize connection remote = mmRemote() remote.connect() # print list of selected object IDs selected_objects = mm.list_selected_objects(remote) print "selected objects: ", selected_objects # print list of selected group IDs (empty if no selection) groups_list = mm.list_selected_groups(remote) print "selected groups: ", groups_list #done! remote.shutdown()
# Demo sequence of commands: # - run Offset tool on current object # - separate new shell and set as Target # - 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")
def scriptButton(theEvent): print("!!!!!!!!!function blow hole!!!!!!!!!!!!") flag_done = 0 root = State(mm.list_selected_objects(remote)[0]) cur_state = root possible_size = root.possible_size remain_area = list(selected_area) used_sizes = list() print("area:" + str(len(remain_area)) + "," + str(remain_area)) while (len(possible_size) and len(remain_area)): print("###in while loop###") print("1: cur " + str(cur_state.object)) mm.select_objects(remote, [cur_state.object]) mm.begin_tool(remote, "duplicate") mm.accept_tool(remote) copy_object = mm.list_selected_objects(remote)[0] print("2:" + str(copy_object)) cur_frame = remain_area.pop() cur_state.frame = cur_frame print(["3:", cur_frame]) flag_done = 0 print("4: used " + str(used_sizes)) print("4: possi " + str(possible_size)) print("4: cur_possi " + str(cur_state.possible_size)) for size in possible_size: if not TestFit(copy_object, cur_frame, [size, size, size], 5): cur_state.possible_size.remove(size) else: print("5 select:" + str(size)) print("5: " + str( TestFit(copy_object, cur_frame, [size, size, size], 5))) print("6:" + str(cur_state.possible_size)) flag_done = 1 cur_state.possible_size.remove(size) print("6:" + str(cur_state.possible_size)) cur_state.used_size = size used_sizes.append(size) print("7:" + str(used_sizes)) create_ring(copy_object, cur_frame, [8, 2, 8]) drill_holes(copy_object, cur_frame, pipe_filename, [1, 0.5, 1], 0, 0) drill_holes(copy_object, cur_frame, hole_filename, [size, size, size], 5, 1) new_state = State(copy_object) print("9: new " + str(new_state.object)) new_state.parent = cur_state new_state.possible_size = list( set(hole_sizes) - set(used_sizes)) print("10:" + str(new_state.possible_size)) cur_state = new_state possible_size = cur_state.possible_size print("11:" + str(possible_size)) break if not cur_state.parent: possible_size = list() break if flag_done == 0: print("12: failed") new_state = cur_state.parent print("13: " + str(cur_state.frame)) remain_area.append(cur_state.frame) used_sizes.append(new_state.used_size) print("15: " + str(possible_size)) possible_size = cur_state.possible_size if not len(remain_area): print("done area:" + str(len(remain_area))) setStatusText("Success!") #selected_area=[] else: setStatusText("Unable to assign the holes")