Go to: Synopsis. Return value. Keywords. Related. Flags. Python examples.
hasMetadata([asList=boolean], [channelName=string], [channelType=string], [endIndex=string], [ignoreDefault=boolean], [index=string], [indexType=string], [memberName=string], [scene=boolean], [startIndex=string], [streamName=string])
Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.
hasMetadata is NOT undoable, NOT queryable, and NOT editable.
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 Flags
- channelName - Only look for metadata on one particular Channel type
- streamName - Only look for metadata on one particular named Stream. When
used in conjunction with channelName then ignore Streams with a matching
name but a different Channel type
- index - Only look for metadata on one or more specific Index values of
a Stream. Requires use of the streamName flag. Does not require the
indexType flag as that will be inferred by the streamName.
- startIndex/endIndex - Same as index but using an entire range of
Index values rather than a single one
- indexType - 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 memberName filter 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 Flags
- normal 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 scene
- channelName - True if there is any metadata at all on the Channel
with the given name
- streamName - True if there is any metadata at all on the Stream
with the given name
- index/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 asList modification 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 metadata
- channelName - List of Stream names in the Channel with metadata
- streamName - List of Index values on the Stream with metadata
- index/startIndex/endIndex - List of Index values with metadata,
restricted to the set of specified Index values.
string[] | List of indexes in the filtered list which contain metadata |
boolean[] | List of answers to whether the specified item(s) have metadata |
metadata, component, stream, channel, association
addMetadata, applyMetadata, dataStructure, editMetadata, getMetadata
asList, channelName, channelType, endIndex, ignoreDefault, index, indexType, memberName, scene, startIndex, streamName
Long name (short name) |
Argument types |
Properties |
asList(al)
|
boolean
|
|
|
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.
|
|
ignoreDefault(id)
|
boolean
|
|
|
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.
|
|
memberName(mn)
|
string
|
|
|
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.
|
|
channelName(cn)
|
string
|
|
|
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)
|
string
|
|
|
Obsolete - use the 'channelName' flag instead.
In query mode, this flag can accept a value.
|
|
endIndex(eix)
|
string
|
|
|
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 startIndex flag to specify a range
of indices from which to retrieve the metadata. It is an error to have the
value of startIndex be greater than that of endIndex.
See also the index flag 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)
|
string
|
|
|
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 index flag takes a string, formatted in the way the
specified indexType requires. All uses of the
index flag 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)
|
string
|
|
|
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.
|
|
scene(scn)
|
boolean
|
|
|
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)
|
string
|
|
|
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 endIndex flag to specify a range of
indices from which to retrieve the metadata. It is an error to have the value
of startIndex be greater than that of endIndex.
See also the index flag 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)
|
string
|
|
|
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 command
|
Flag can appear in Edit mode of command
|
Flag can appear in Query mode of command
|
Flag can have multiple arguments, passed either as a tuple or a list.
|
import maya.cmds as cmds
import maya.cmds as cmds
cmds.polyPlane( name='smcPlane', constructionHistory=False )
# Result: smcPlane #
# Create structures
cmds.dataStructure( format='raw', asString='name=idStructure:int32=ID' )
# Result: idStructure #
cmds.dataStructure( format='raw', asString='name=keyValueStructure:string=value' )
# Result: keyValueStructure #
# Apply structures to plane
cmds.select( 'smcPlaneShape', replace=True )
cmds.addMetadata( structure='idStructure', streamName='idStream', channelName='vertex' )
cmds.addMetadata( structure='keyValueStructure', streamName='keyValueStream', channelName='key', indexType='string' )
# Apply the metadata values to three of the components by selection
cmds.select( 'smcPlaneShape.vtx[8:10]', replace=True )
cmds.editMetadata( streamName='idStream', memberName='ID', value=7 )
# Result: 3 #
# Verify existence of the three newly set metadata values at the node level
cmds.select( 'smcPlaneShape', replace=True )
cmds.hasMetadata()
# Result: [True] #
# Verify existence of the three newly set metadata values at the Channel level
cmds.hasMetadata( channelName='vertex' )
# Result: [True] #
cmds.hasMetadata( channelName='edge' )
# Result: [False] #
# Verify existence of the three newly set metadata values at the Stream level
cmds.hasMetadata( channelName='vertex', streamName='idStream' )
# Result: [True] #
cmds.hasMetadata( channelName='edge', streamName='someOtherStream' )
# Result: [False] #
# Verify existence of the three newly set metadata values at the Index level
cmds.hasMetadata( channelName='vertex', streamName='idStream', index=['8','9'] )
# Result: [True, True] #
cmds.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.
cmds.hasMetadata( channelName='vertex', streamName='idStream', index=['0','1'] )
# Result: [True, True] #
# Verify non-existence of non-default metadata values at the Index level
cmds.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
cmds.select( 'smcPlaneShape.vtx[8:20]', replace=True )
cmds.hasMetadata( channelName='vertex', streamName='idStream', asList=True )
# Result: [u'8', u'9', u'10'] #
# Set metadata values using the complex index type='string'
cmds.editMetadata( streamName='keyValueStream', memberName='value', stringValue='Starry Night', indexType='string', index='Title' )
cmds.editMetadata( streamName='keyValueStream', memberName='value', stringValue='Vincent Van Gogh', indexType='string', index='Artist' )
# Verify existence of the complex index data
cmds.hasMetadata( streamName='keyValueStream', memberName='value', channelName='key', index=['Title','Artist'], indexType='string', asList=True )
# Result: [u'Artist', u'Title'] #