pymel.core.modeling.hasMetadata

hasMetadata(*args, **kwargs)

This command is used to query for the presence of metadata elements on a node, components, or scene. The command works at all levels of metadata presence, from the existence of any metadata at all on a node or scene right down to the presence of metadata values set on a particular metadata Stream index. 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 oneindexType- Only look for metadata using a particular Index type. Can have its scope narrowed by other filter flags as well.ignoreDefault- Treat any metadata that still has the default value (e.g. 0 for numerics, “” for strings) the same as metadata that isn’t present. This means that any metadata with default values will not be reported. It is useful for quickly finding values that you have changed. When this flag is set you can also use the memberNamefilter to narrow down the check to a particular member of the metadata Structure. Without that filter it will only skip over metadata where every member of the Structure has a non-default value.memberName- Only look at one particular Member in the metadata in a Structure. Only used when checking for non-default values as existence is based on the entire Structure, not any particular Member.Operation Flagsnormal mode- Return True for every specified location containing metadata. This combines with the filter flags as follows: no flag- True if there is any metadata at all on the node or scenechannelName- True if there is any metadata at all on the Channel with the given namestreamName- True if there is any metadata at all on the Stream with the given nameindex/startIndex/endIndex- An array of booleans ordered the same as the natural ordering of the Index values (i.e. specifying index 3, 2, and 4 in that order will still return booleans in the order for indices 2,3,4) where True means that there is metadata assigned at that Index. This form is better suited with the asListmodification since with that variation it is easier to tell exactly which indices have the metadata.asList- Adding this flag switches the return values from a single boolean or array of booleans to an array of strings indicating exactly which metadata elements have values. The return values of the command are changed to be the following: no flag- List of Channel names with metadatachannelName- List of Stream names in the Channel with metadatastreamName- List of Index values on the Stream with metadataindex/startIndex/endIndex- List of Index values with metadata, restricted to the set of specified Index values.

Flags:
Long name (short name) Argument Types Properties
asList (al) bool ../../../_images/create.gif
 

Use this flag when you want to return string values indicating where the metadata lives rather than boolean values. See the command description for more details on what this flag will return.

channelName (cn) unicode ../../../_images/create.gif ../../../_images/query.gif
 

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 ../../../_images/create.gif ../../../_images/query.gif
 
Obsolete - use the ‘channelName’ flag instead. In query mode, this flag can accept a value.
endIndex (eix) unicode ../../../_images/create.gif
 

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.

ignoreDefault (id) bool ../../../_images/create.gif
 

Use this flag when you want to skip over any metadata that has only default values. i.e. the metadata may exist but it hasn’t had a new value set yet (non-zero for numerics, non-empty strings, etc.) See the command description for more details on how this flag filters the search.

index (idx) unicode ../../../_images/create.gif ../../../_images/query.gif
 

In the typical case metadata is indexed using a simple integer value. Certain types of data may use other index types. e.g. a “vertexFace” component will use a “pair” index 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 ../../../_images/create.gif ../../../_images/query.gif
 

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 “vertexFace” channel is different, using a “pair” index type. In query mode, this flag can accept a value.

memberName (mn) unicode ../../../_images/create.gif
 

Name of the Structure member being checked. The names of the members are set up in the Structure definition, either through the description passed in through the “dataStructure” command or via the API used to create that Structure. As the assignment of metadata is on a per-structure basis this flag only needs to be specified when querying for non-default values. If you query for non-default values and omit this flag then it checks that any of the members have a non-default value.

scene (scn) bool ../../../_images/create.gif ../../../_images/query.gif
 

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 ../../../_images/create.gif
 

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 ../../../_images/create.gif ../../../_images/query.gif
 

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 appear in Create mode of commandFlag can have multiple arguments, passed either as a tuple or a list.

Derived from mel command maya.cmds.hasMetadata

Example:

import pymel.core as pm

import maya.cmds as cmds
pm.polyPlane( name='smcPlane', constructionHistory=False )
# Result: [nt.Transform(u'smcPlane')] #
# 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.select( 'smcPlaneShape', replace=True )
pm.addMetadata( structure='idStructure', streamName='idStream', channelName='vertex' )
# Result: [u'smcPlaneShape'] #
pm.addMetadata( structure='keyValueStructure', streamName='keyValueStream', channelName='key', indexType='string' )
# Result: [u'smcPlaneShape'] #
# Apply the metadata values to 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') #
# Verify existence of the three newly set metadata values at the node level
pm.select( 'smcPlaneShape', replace=True )
pm.hasMetadata()
# Result: [True] #
# Verify existence of the three newly set metadata values at the Channel level
pm.hasMetadata( channelName='vertex' )
# Result: [True, True] #
pm.hasMetadata( channelName='edge' )
# Result: [False] #
# Verify existence of the three newly set metadata values at the Stream level
pm.hasMetadata( channelName='vertex', streamName='idStream' )
# Result: [True] #
pm.hasMetadata( channelName='edge', streamName='someOtherStream' )
# Result: [False] #
# Verify existence of the three newly set metadata values at the Index level
pm.hasMetadata( channelName='vertex', streamName='idStream', index=['8','9'] )
# Result: [True, True] #
pm.hasMetadata( channelName='vertex', streamName='idStream', index=['8','9999'] )
# Result: [True, False] #
# Verify existence of default metadata values at the Index level. Since the
# index range was established to be 0-17 by assignment and the Stream
# defaults to returning default values for unassigned indices the lower index
# values "0" and "1" do have metadata (as default values) but the higher one
# "9999" in the above example does not.
pm.hasMetadata( channelName='vertex', streamName='idStream', index=['0','1'] )
# Result: [False, False] #
# Verify non-existence of non-default metadata values at the Index level
pm.hasMetadata( ignoreDefault=True, channelName='edge', streamName='idStream', memberName='ID', index=['0','1'] )
# Result: [False, False] #
# Get the list of Index values with assigned metadata on the object
pm.select( 'smcPlaneShape.vtx[8:20]', replace=True )
pm.hasMetadata( channelName='vertex', streamName='idStream', asList=True )
# Result: [u'8', u'9', u'10'] #
# Set metadata values using the complex index type='string'
pm.editMetadata( streamName='keyValueStream', memberName='value', stringValue='Starry Night', indexType='string', index='Title' )
# Result: nt.Mesh(u'smcPlaneShape') #
pm.editMetadata( streamName='keyValueStream', memberName='value', stringValue='Vincent Van Gogh', indexType='string', index='Artist' )
# Result: nt.Mesh(u'smcPlaneShape') #
# Verify existence of the complex index data
pm.hasMetadata( streamName='keyValueStream', memberName='value', channelName='key', index=['Title','Artist'], indexType='string', asList=True )
# Result: [u'Artist', u'Title'] #

Previous topic

pymel.core.modeling.hardenPointCurve

Next topic

pymel.core.modeling.illustratorCurves

Core

Core Modules

Other Modules

This Page