pymel.core.modeling.getMetadata¶
- getMetadata(*args, **kwargs)¶
This command is used to retrieve the values of metadata elements from a node or scene. It is restricted to returning a single structure member at a time. For convenience the detail required is only enough to find a single Member of a single Structure on a single metadata Channel. In the simplest case if there is a single Stream on one metadata Channel which uses a Structure with only one Member then all that is required is the name of the object containing the metadata. In the most complex case the ‘channelName’, ‘streamName’, and ‘memberName’ are all required to narrow down the metadata to a single unique Member. In general for scripting it’s a good idea to use all flags anyway since there could be metadata added anywhere. The shortcuts are mainly for quick entry when entering commands directly in the script editor or command line. When an Index is specified where data is not present the command fails with a message telling you which Index or Indices didn’t have values. Use the hasMetadatacommand first to determine where metadata exists if you need to know in advance where to find valid metadata. Filter FlagschannelName- Only look for metadata on one particular Channel typestreamName- Only look for metadata on one particular named Stream. When used in conjunction with channelNamethen ignore Streams with a matching name but a different Channel typeindex- Only look for metadata on one or more specific Index values of a Stream. Requires use of the streamNameflag. Does not require the indexTypeflag as that will be inferred by the streamName.startIndex/endIndex- Same as indexbut using an entire range of Index values rather than a single one. Not valid for index types not supporting ranges (e.g. strings)indexType- Only look for metadata using a particular Index type. Can have its scope narrowed by other filter flags as well.memberName- The particular Member in the metadata in a Structure to retrieve. If this is not specified the Structure can only have a single Member.Metadata on meshes is special in that the Channel types vertex, edge, face, and vertexFaceare directly connected to the components of the same name. To make getting these metadata Channels easier you can simply select or specify on the command line the corresponding components rather than using the channelNameand index/startIndex/endIndexflags. For example the selection myMesh.vtx[8:10]corresponds to channelName = vertexand either index = 8, 9, 10as a multi-use flag or setIndex = 8, endIndex=10. Only a single node or scene and unique metadata Structure Member are allowed in a single command. This keeps the data simple at the possible cost of requiring multiple calls to the command to get more than one Structure Member’s value. When the data is returned it will be in Index order with an entire Member appearing together. For example if you were retrieving float[3] metadata on three components you would get the nine values back in the order: index[0]-float[0], index[0]-float[1], index[0]-float[2], index[1]-float[0], index[1]-float[1], index[1]-float[2], index[2]-float[0], index[2]-float[1], index[2]-float[2]. In the Python implementation the float[3] values will be an array each so you would get back three float[3] arrays.
Flags:
Long Name / Short Name Argument Types Properties channelName / cn unicode Filter the metadata selection to only recognize metadata belonging to the specified named Channel (e.g. vertex). This flag is ignored if the components on the selection list are being used to specify the metadata of interest. In query mode, this flag can accept a value. channelType / cht unicode Obsolete - use the ‘channelName’ flag instead. In query mode, this flag can accept a value. dataType / dt bool Used with the flag ‘streamName’ and ‘memberName’ to query the dataType of the specfied member. endIndex / eix unicode The metadata is stored in a Stream, which is an indexed list. If you have mesh components selected then the metadata indices are implicit in the list of selected components. If you select only the node or scene then this flag may be used in conjunction with the startIndexflag to specify a range of indices from which to retrieve the metadata. It is an error to have the value of startIndexbe greater than that of endIndex. See also the indexflag for an alternate way to specify multiple indices. This flag can only be used on index types that support a range (e.g. integer values - it makes no sense to request a range between two strings) In query mode, this flag can accept a value. index / idx unicode In the typical case metadata is indexed using a simple integer value. Certain types of data may use other index types. e.g. a vertexFacecomponent will use a pairindex type, which is two integer values; one for the face ID of the component and the second for the vertex ID. The indexflag takes a string, formatted in the way the specified indexTyperequires. All uses of the indexflag have the same indexType. If the type was not specified it is assumed to be a simple integer value. In query mode, this flag can accept a value. indexType / idt unicode Name of the index type the new Channel should be using. If not specified this defaults to a simple integer index. Of the native types only a mesh vertexFacechannel is different, using a pairindex type. In query mode, this flag can accept a value. listChannelNames / lcn bool Query the channel names on the shape. This flag can be used with some flags to filter the results. It can be used with the flag ‘streamName’ to get the channel with the specfied stream and the flag ‘memberName’ to get the channel in which the stream contains the specified member. It cannot be used with the flag ‘channelName’. listMemberNames / lmn bool Query the member names on the shape. This flag can be used with some flags to filter the results. It can be used with ‘streamName’ to get the member which is in the specified stream and the flag ‘channelName’ to get the member which is used in the specfied channel. It cannot be used with the flag ‘memberName’. listStreamNames / lsn bool Query the stream names on the shape. This flag can be used with some flags to filter the results. It can be used with the flag ‘channelName’ to get the stream names on the specified channel and the flag ‘memberName’ to get the stream names which has the specified member. It cannot be used with the flag ‘streamName’. memberName / mn unicode Name of the Structure member being retrieved. The names of the members are set up in the Structure definition, either through the description passed in through the dataStructurecommand or via the API used to create that Structure. This flag is only necessary when selected Structures have more than one member. scene / scn bool Use this flag when you want to add metadata to the scene as a whole rather than to any individual nodes. If you use this flag and have nodes selected the nodes will be ignored and a warning will be displayed. startIndex / six unicode The metadata is stored in a Stream, which is an indexed list. If you have mesh components selected then the metadata indices are implicit in the list of selected components. If you select only the node or scene then this flag may be used in conjunction with the endIndexflag to specify a range of indices from which to retrieve the metadata. It is an error to have the value of startIndexbe greater than that of endIndex. See also the indexflag for an alternate way to specify multiple indices. This flag can only be used on index types that support a range (e.g. integer values - it makes no sense to request a range between two strings) In query mode, this flag can accept a value. streamName / stn unicode Name of the metadata Stream. Depending on context it could be the name of a Stream to be created, or the name of the Stream to pass through the filter. In query mode, this flag can accept a value.Flag can have multiple arguments, passed either as a tuple or a list. Derived from mel command maya.cmds.getMetadata
Example:
import pymel.core as pm import maya.cmds as cmds pm.polyPlane( name='smcPlane', constructionHistory=False ) # Result: [nt.Transform(u'smcPlane')] # pm.pickWalk( d='down' ) # Result: [u'smcPlaneShape'] # # Create structures pm.dataStructure( format='raw', asString='name=idStructure:int32=ID' ) # Result: u'idStructure' # pm.dataStructure( format='raw', asString='name=keyValueStructure:string=value' ) # Result: u'keyValueStructure' # # Apply structures to plane pm.addMetadata( structure='idStructure', streamName='idStream', channelName='vertex' ) # Result: [u'smcPlaneShape'] # pm.addMetadata( structure='keyValueStructure', streamName='keyValueStream', channelName='key', indexType='string' ) # Result: [u'smcPlaneShape'] # # Set the metadata values on three of the components by selection pm.select( 'smcPlaneShape.vtx[8:10]', replace=True ) pm.editMetadata( streamName='idStream', memberName='ID', value=7 ) # Result: nt.Mesh(u'smcPlaneShape') # # Retrieve the three newly set metadata values pm.select( 'smcPlaneShape', replace=True ) pm.getMetadata( streamName='idStream', memberName='ID', channelName='vertex', index=['8','9','10'] ) # Result: [7, 7, 7] # # Get metadata from a larger group of indices all at once. # Note that unassigned metadata values assume the default (0 for numbers). pm.select( 'smcPlaneShape.vtx[7:10]', replace=True ) pm.getMetadata( streamName='idStream', memberName='ID' ) [[0], [7], [7], [7]] # Set metadata values using the complex index type stream pm.editMetadata( streamName='keyValueStream', memberName='value', stringValue='Starry Night', index='Title' ) True pm.editMetadata( streamName='keyValueStream', memberName='value', stringValue='Vincent Van Gogh', index='Artist' ) True # Retrieve the complex index data (note return is in alphabetical order of index) pm.getMetadata( streamName='keyValueStream', memberName='value', channelName='key', index=['Title', 'Artist'], indexType='string' ) [['Vincent Van Gogh'], ['Starry Night']]