Python pymel.core.selected() Examples
The following are 30
code examples of pymel.core.selected().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pymel.core
, or try the search function
.

Example #1
Source File: render.py From anima with MIT License | 6 votes |
def export_shader_attributes(cls): """exports the selected shader attributes to a JSON file """ # get data data = [] nodes = pm.ls(sl=1) for node in nodes: node_attr_data = {} attrs = node.listAttr() for attr in attrs: try: value = attr.get() if not isinstance(value, pm.PyNode): node_attr_data[attr.shortName()] = value except TypeError: continue data.append(node_attr_data) # write data import json with open(cls.node_attr_info_temp_file_path, 'w') as f: json.dump(data, f)
Example #2
Source File: pickWalk.py From mgear_core with MIT License | 6 votes |
def controllerWalkUp(node, add=False): """Walk up in the hierachy using the controller tag Arguments: node (dagNode or list of dagNode): Node with controller tag add (bool, optional): If true add to selection """ oParent = [] if not isinstance(node, list): node = [node] for n in node: tag = getWalkTag(n) if tag: cnx = tag.parent.connections() if cnx: oParent.append(cnx[0]) else: pm.displayWarning("The selected object: %s without Controller tag " "will be skipped" % n.name()) if oParent: pm.select(_getControllerWalkNodes(oParent), add=add) else: pm.displayWarning("No parent to walk Up.")
Example #3
Source File: sqSpaceSwitcher.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def _event_cbSys_selChanged(self, _iIdx): """ Manage the system change with the combo box. select the node related to the system selected in the combo box """ # Prevent a node selection when the comboBox index changed during selection changed callback if not self.bInSelChanged: if _iIdx > 0: pCurSys = self.aSceneSpaceSwitch[_iIdx - 1] pymel.select(pCurSys.nDriven) else: # If the no system index is selected, but a node is selected in the scene, put back the selected system for i, pSp in enumerate(self.aSceneSpaceSwitch): if pSp.nDriven == self.nSelDriven: # Change the index, but prevent the event to select back the node self.bInSelChanged = True self.ui.cbSysList.setCurrentIndex(i + 1) self.bInSelChanged = False break
Example #4
Source File: sqSpaceSwitcher.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def _update_lstParent(self, pSpData): """ Update the parent list for the selected system """ self.createModel.clear() if pSpData: self.ui.lstParent.setEnabled(True) self.createModel.appendRow(self.parentItem) for iIdx, nParentInfo in enumerate(pSpData.aDrivers): newParentItem = QtGui.QStandardItem(nParentInfo.name()) newParentItem.setEditable(False) # Prevent any delete action when the sysem is referenced if pymel.referenceQuery(self.pSelSpSys.nSwConst, isNodeReferenced=True): newParentItem.setCheckable(False) else: newParentItem.setCheckable(True) self.createModel.appendRow(newParentItem) else: self.ui.lstParent.setEnabled(False) self.createModel.appendRow(self.parentItem)
Example #5
Source File: render.py From anima with MIT License | 6 votes |
def randomize_light_intensity(cls, min_field, max_field): """Randomizes the intensities of selected lights :param min: :param max: :return: """ min = pm.floatField(min_field, q=1, v=1) max = pm.floatField(max_field, q=1, v=1) cls.randomize_attr( [node.getShape() for node in pm.ls(sl=1)], 'aiExposure', min, max, 0.1 )
Example #6
Source File: render.py From anima with MIT License | 6 votes |
def randomize_light_color_temp(cls, min_field, max_field): """Randomizes the color temperature of selected lights :param min: :param max: :return: """ min = pm.floatField(min_field, q=1, v=1) max = pm.floatField(max_field, q=1, v=1) cls.randomize_attr( [node.getShape() for node in pm.ls(sl=1)], 'aiColorTemperature', min, max, 1 )
Example #7
Source File: animation.py From anima with MIT License | 6 votes |
def smooth_selected_keyframes(cls, iteration=10): """smooths the selected keyframes :param iteration: :return: """ from anima.utils import smooth_array node = pm.keyframe(q=1, sl=1, n=1)[0] keyframe_indices = pm.keyframe(q=1, sl=1, iv=1) keyframe_values = pm.keyframe(q=1, sl=1, vc=1) for i in range(iteration): keyframe_values = smooth_array(keyframe_values) # restore the keyframe values for i, v in zip(keyframe_indices, keyframe_values): pm.keyframe(node, e=1, index=i, vc=v)
Example #8
Source File: attribute.py From mgear_core with MIT License | 6 votes |
def smart_reset(*args): """Reset the SRT or the selected channels Checks first if we have channels selected. If not, will try to reset SRT Args: *args: Dummy """ attributes = getSelectedChannels() if attributes: reset_selected_channels_value(objects=None, attributes=attributes) else: reset_SRT() ########################################################## # GETTERS ##########################################################
Example #9
Source File: attribute.py From mgear_core with MIT License | 6 votes |
def getSelectedChannels(userDefine=False): """Get the selected channels on the channel box Arguments: userDefine (bool, optional): If True, will return only the user defined channels. Other channels will be skipped. Returns: list: The list of selected channels names """ # fetch core's main channelbox attrs = pm.channelBox(get_channelBox(), q=True, sma=True) if userDefine: oSel = pm.selected()[0] uda = oSel.listAttr(ud=True) if attrs: attrs = [x for x in attrs if oSel.attr(x) in uda] else: return None return attrs
Example #10
Source File: attribute.py From mgear_core with MIT License | 6 votes |
def getSelectedObjectChannels(oSel=None, userDefine=False, animatable=False): """Get the selected object channels. Arguments: oSel (None, optional): The pynode with channels to get userDefine (bool, optional): If True, will return only the user defined channels. Other channels will be skipped. animatable (bool, optional): If True, only animatable parameters will be return Returns: list: The list of the selected object channels names """ if not oSel: oSel = pm.selected()[0] channels = [x.name().rsplit(".", 1)[1] for x in oSel.listAttr(ud=userDefine, k=animatable)] return channels ########################################################## # UTIL ##########################################################
Example #11
Source File: render.py From anima with MIT License | 6 votes |
def open_node_in_browser(cls): # get selected nodes node_attrs = { 'file': 'fileTextureName', 'aiImage': 'filename', 'aiStandIn': 'dso', } import os from anima.utils import open_browser_in_location for node in pm.ls(sl=1): type_ = pm.objectType(node) # special case: if transform use shape if type_ == 'transform': node = node.getShape() type_ = pm.objectType(node) attr_name = node_attrs.get(type_) if attr_name: # if any how it contains a "#" character use the path path = node.getAttr(attr_name) if "#" in path: path = os.path.dirname(path) open_browser_in_location(path)
Example #12
Source File: render.py From anima with MIT License | 6 votes |
def assign_random_material_color(cls): """assigns a lambert with a random color to the selected object """ selected = pm.selected() # create the lambert material lambert = pm.shadingNode('lambert', asShader=1) # create the shading engine shading_engine = pm.nt.ShadingEngine() lambert.outColor >> shading_engine.surfaceShader # randomize the lambert color import random h = random.random() # 0-1 s = random.random() * 0.5 + 0.25 # 0.25-0.75 v = random.random() * 0.5 + 0.5 # 0.5 - 1 from anima.utils import hsv_to_rgb r, g, b = hsv_to_rgb(h, s, v) lambert.color.set(r, g, b) pm.sets(shading_engine, fe=selected) pm.select(selected)
Example #13
Source File: rigging.py From anima with MIT License | 6 votes |
def create(self): # reverse_foot_controller = pm.selected()[0] # foot_ik_ankle_joint = pm.selected()[0] # foot_ik_ball_joint = pm.selected()[0] # foot_ik_tip_joint = pm.selected()[0] # # attrs = [ # 'tipHeading', # 'tipRoll', # 'tipBank', # 'ballRoll', # 'ballBank' # ] # # # for attr in attrs: # pm.addAttr(reverse_foot_controller, ln=attr, at='float', k=1) # # reverse_foot_controller.tipHeading >> foot_ik_tip_joint.ry # reverse_foot_controller.tipRoll >> foot_ik_tip_joint.rx # reverse_foot_controller.tipBank >> foot_ik_tip_joint.rz # # reverse_foot_controller.ballRoll >> foot_ik_ball_joint.rx # reverse_foot_controller.ballBank >> foot_ik_ball_joint.rz pass
Example #14
Source File: auxiliary.py From anima with MIT License | 6 votes |
def rivet_per_face(): """creates hair follicles per selected face """ sel_list = pm.ls(sl=1, fl=1) follicles = [] locators = [] for face in sel_list: # use the center of the face as the follicle position p = reduce(lambda x, y: x + y, face.getPoints()) / face.numVertices() obj = pm.spaceLocator(p=p) locators.append(obj) shape = face.node() uv = face.getUVAtPoint(p, space='world') follicle_transform, follicle = create_follicle(shape, uv) pm.parent(obj, follicle_transform) follicles.append(follicle) return follicles, locators
Example #15
Source File: auxiliary.py From anima with MIT License | 6 votes |
def create_bbox(nodes, per_selection=False): """creates bounding boxes for the selected objects :param bool per_selection: If True will create a BBox for each given object """ if per_selection: for node in nodes: return cube_from_bbox(node.boundingBox()) else: bbox = pm.dt.BoundingBox() for node in nodes: bbox.expand(node.boundingBox().min()) bbox.expand(node.boundingBox().max()) return cube_from_bbox(bbox)
Example #16
Source File: rigging.py From anima with MIT License | 6 votes |
def reset_tweaks(cls): """Resets the tweaks on the selected deformed objects """ for obj in pm.ls(sl=1): for tweak_node in pm.ls(obj.listHistory(), type=pm.nt.Tweak): try: for i in tweak_node.pl[0].cp.get(mi=1): tweak_node.pl[0].cv[i].vx.set(0) tweak_node.pl[0].cv[i].vy.set(0) tweak_node.pl[0].cv[i].vz.set(0) except TypeError: try: for i in tweak_node.vl[0].vt.get(mi=1): tweak_node.vl[0].vt[i].vx.set(0) tweak_node.vl[0].vt[i].vy.set(0) tweak_node.vl[0].vt[i].vz.set(0) except TypeError: pass
Example #17
Source File: render.py From anima with MIT License | 5 votes |
def import_gpu_content(self): """imports the selected GPU content """ import os imported_nodes = [] for node in pm.ls(sl=1): gpu_node = node.getShape() gpu_path = gpu_node.getAttr('cacheFileName') new_nodes = pm.mel.eval( 'AbcImport -mode import -reparent "%s" "%s";' % (node.fullPath(), os.path.expandvars(gpu_path)) ) # get imported nodes new_nodes = node.getChildren() new_nodes.remove(gpu_node) imported_node = None # filter material node for n in new_nodes: if n.name() != 'materials': imported_node = n else: pm.delete(n) if imported_node: imported_node.t.set(0, 0, 0) imported_node.r.set(0, 0, 0) imported_node.s.set(1, 1, 1) pm.parent(imported_node, world=1) imported_nodes.append(imported_node) pm.select(imported_nodes)
Example #18
Source File: render.py From anima with MIT License | 5 votes |
def connect_placement2d_to_file(cls): """connects the selected placement node to the selected file textures """ attr_lut = [ 'coverage', 'translateFrame', 'rotateFrame', 'mirrorU', 'mirrorV', 'stagger', 'wrapU', 'wrapV', 'repeatUV', 'offset', 'rotateUV', 'noiseUV', 'vertexUvOne', 'vertexUvTwo', 'vertexUvThree', 'vertexCameraOne', ('outUV', 'uvCoord'), ('outUvFilterSize', 'uvFilterSize') ] # get placement and file nodes placement_node = pm.ls(sl=1, type=pm.nt.Place2dTexture)[0] file_nodes = pm.ls(sl=1, type=pm.nt.File) for file_node in file_nodes: for attr in attr_lut: if isinstance(attr, str): source_attr_name = attr target_attr_name = attr elif isinstance(attr, tuple): source_attr_name = attr[0] target_attr_name = attr[1] placement_node.attr(source_attr_name) >> \ file_node.attr(target_attr_name)
Example #19
Source File: render.py From anima with MIT License | 5 votes |
def convert_to_linear(cls): """adds a gamma_gain node in between the selected nodes outputs to make the result linear """ # # convert to linear # selection = pm.ls(sl=1) for file_node in selection: # get the connections outputs = file_node.outputs(plugs=True) if not len(outputs): continue # and insert a mip_gamma_gain gamma_node = pm.createNode('mip_gamma_gain') gamma_node.setAttr('gamma', 2.2) gamma_node.setAttr('reverse', True) # connect the file_node to gamma_node try: file_node.outValue >> gamma_node.input file_node.outValueA >> gamma_node.inputA except AttributeError: file_node.outColor >> gamma_node.input # do all the connections from the output of the gamma for output in outputs: try: gamma_node.outValue >> output except RuntimeError: gamma_node.outValueA >> output pm.select(selection)
Example #20
Source File: render.py From anima with MIT License | 5 votes |
def standin_to_polywire(cls): """convert the selected stand-in nodes to bbox """ [node.mode.set(2) for node in pm.ls(sl=1) if isinstance(node.getShape(), pm.nt.AiStandIn)]
Example #21
Source File: render.py From anima with MIT License | 5 votes |
def vertigo_setup_vertigo(cls): """sets up a Vertigo effect for the selected camera """ from anima.env.mayaEnv import vertigo cam = pm.ls(sl=1)[0] vertigo.setup_vertigo(cam)
Example #22
Source File: render.py From anima with MIT License | 5 votes |
def vertigo_setup_look_at(cls): """sets up a the necessary locator for teh Vertigo effect for the selected camera """ from anima.env.mayaEnv import vertigo cam = pm.ls(sl=1)[0] vertigo.setup_look_at(cam)
Example #23
Source File: general.py From anima with MIT License | 5 votes |
def rename_unique(cls): """renames the selected nodes with unique names """ import re [node.rename(re.sub('[\d]+', '#', node.name())) for node in pm.selected()]
Example #24
Source File: rigging.py From anima with MIT License | 5 votes |
def select(self): """selects the joint that is selected in the list in the scene """ pm.select(pm.ls(sl=1, type="joint"), d=1) selected_item = self.get_selected_item_in_list() pm.select(selected_item, add=1) # change the skin influence to current selection if selected_item != "": pm.mel.eval("setSmoothSkinInfluence %s" % selected_item.name())
Example #25
Source File: modeling.py From anima with MIT License | 5 votes |
def transfer_uvs(cls, sample_space=4): """transfer uvs between selected objects. It can search for hierarchies both in source and target sides. :parm sample_space: The sampling space: 0: World 1: Local 2: UV 3: Component 4: Topology """ selection = pm.ls(sl=1) pm.select(None) source = selection[0] target = selection[1] # auxiliary.transfer_shaders(source, target) # pm.select(selection) lut = auxiliary.match_hierarchy(source, target) for source, target in lut['match']: pm.transferAttributes( source, target, transferPositions=0, transferNormals=0, transferUVs=2, transferColors=2, sampleSpace=sample_space, sourceUvSpace='map1', targetUvSpace="map1", searchMethod=0, flipUVs=0, colorBorders=1 ) # restore selection pm.select(selection)
Example #26
Source File: rigging.py From anima with MIT License | 5 votes |
def squash_stretch_bend_rigger(cls): """Creates Squash/Stretch/Bend rig for the selected geometry """ geo = pm.selected()[0] ssbr = SquashStretchBendRigger(geo) ssbr.setup()
Example #27
Source File: rigging.py From anima with MIT License | 5 votes |
def mirror_transformation(cls): """Mirrors transformation from first selected object to the second selected object """ # TODO: This needs more generalization import math sel_list = pm.selected() source_node = sel_list[0] target_node = sel_list[1] m = source_node.worldMatrix.get() local_y_axis = pm.dt.Vector(m[1][0], m[1][1], m[1][2]) local_z_axis = pm.dt.Vector(m[2][0], m[2][1], m[2][2]) # reflection reflected_local_y_axis = local_y_axis.deepcopy() reflected_local_y_axis.x *= -1 reflected_local_z_axis = local_z_axis.deepcopy() reflected_local_z_axis.x *= -1 reflected_local_x_axis = reflected_local_y_axis.cross( reflected_local_z_axis) reflected_local_x_axis.normalize() wm = pm.dt.TransformationMatrix() wm[0, :3] = reflected_local_x_axis wm[1, :3] = reflected_local_y_axis wm[2, :3] = reflected_local_z_axis pm.xform(target_node, ws=1, ro=map(math.degrees, wm.eulerRotation())) # pm.makeIdentity( # target_node, apply=1, t=False, r=False, s=False, n=False, # jointOrient=True # )
Example #28
Source File: rigging.py From anima with MIT License | 5 votes |
def create_joints_on_curve_ui(cls): """Creates joints on selected curve """ from anima.env import mayaEnv main_window = mayaEnv.get_maya_main_window() jocd = JointOnCurveDialog(parent=main_window) jocd.show()
Example #29
Source File: render.py From anima with MIT License | 5 votes |
def enable_subdiv_on_selected(cls, fixed_tes=False, max_subdiv=3): """enables subdiv on selected objects :param fixed_tes: Uses fixed tessellation. :param max_subdiv: The max subdivision iteration. Default 3. """ # # Set SubDiv to CatClark on Selected nodes # for node in pm.ls(sl=1): cls.enable_subdiv(node, fixed_tes=fixed_tes, max_subdiv=max_subdiv)
Example #30
Source File: general.py From anima with MIT License | 5 votes |
def remove_pasted(cls): """removes the string 'pasted__' from selected object names """ rmv_str = "pasted__" [ obj.rename(obj.name().split('|')[-1].replace(rmv_str, '')) for obj in pm.ls(sl=1) if rmv_str in obj.name() ]