pymel.core.effects.emit

emit(*args, **kwargs)

The emitaction allows users to add particles to an existing particle object without the use of an emitter. At the same time, it allows them to set any per-particle attribute for the particles that are created with the action.The particles created do not become a part of the initial state for the particle object, and will disappear when the scene is rewound unless they are saved into the initial state by the user explicitly. In addition, a particle object will accept particles from an emit action ONLY at frames greater than or equal to its start frame. For example, if you want to use the emit action to create particles at frame -5, you must set startFrame for that particle shape to -5 or less.Unlike many commands or actions, the emit action uses the order of its flags as important information as to how it works. The -objectand -positionflags can appear anywhere in the argument list. The -attributeand the value flags are interpreted based on their order. Any value flags after an -attribute flag and before the next -attribute flag will set the values for the attribute specified by the closest -attribute flag before them in the argument list. See the Examplessection below for more detail on how these flags work.Currently, no creation expression is executed for the new particles unless they are created from within a particle expression defined with the dynExpressioncommand or the Expression Editor. If you want any particular values put into the particles at the time they are created, then those values should be set using the -attribute, -vectorValue, and -floatValueflags.

Flags:
Long name (short name) Argument Types Properties
attribute (at) unicode ../../../_images/create.gif
 

Specifies the attribute on the particle object that any value flags following it and before the next -attribute flag will be associated with. The same attribute can be specified later in the command to pick up where the first one left off. The attributes used must be per-particle attributes. This will accept both long and short names for the attributes. Note the per-particle attribute must already exist on the particle object prior to being specified via this command flag.

floatValue (fv) float ../../../_images/create.gif
 

Sets the float value to be used for the “current” attribute of the “current” particle. By current attribute, it is meant the attribute specified by the most recent -attribute flag. By current particle, it is meant the particle in the list of -position flags that corresponds to the number of values that have been set for the “current” attribute. If the current attribute is a vector-per-particle attribute, then the float value specified will be used for all three components of the vector.Flag can appear in Create mode of commandFlag can have multiple arguments, passed either as a tuple or a list.

object (o) unicode ../../../_images/create.gif
 

This flag takes the name of a particleShape or the transform directly above it in the DAG as its parent. It specifies which object to add the particles to. This flag must be passed, as the selection list is ignored for this action.

position (pos) float, float, float ../../../_images/create.gif
 

Specifies the positions in the particle object’s space (usually world space) where the particles are to be created. One particle is created for each occurence of this flag.

vectorValue (vv) float, float, float ../../../_images/create.gif
 

Sets the vector value to be used for the “current” attribute of the “current” particle. By current attribute, it is meant the attribute specified by the most recent -attribute flag. By current particle, it is meant the particle in the list of -position flags that corresponds to the number of values that have been set for the “current” attribute. If the current attribute is a float-per-particle attribute, then the length of the vector described by this flag will be used. The length is described as SQR( xVal2+ yVal2+ zVal2.

Derived from mel command maya.cmds.emit

Example:

import pymel.core as pm

import maya.cmds as cmds

pm.particle()
pm.emit( object='particle1', position=(1, 1, 1) )

# This will create one particle at position ""1,1,1"" in the
# already-existing particle object "i"particle1"/i".
#

pm.particle()
pm.emit( object='particle1', position=((1, 1, 1), (2, 2, 2)), attribute=('velocity', 'rgbPP'), vectorValue=((1, 2, 3), (2, 3, 4), (.5, 1, 0)), floatValue=.1 )

# This will create two particles at positions ""1,1,1"" and ""2,2,2"" in
# the already-existing particle object "i"particle1"/i".  Then the velocity
# attribute of those particles is set to ""1,2,3"" and ""2,3,4"",
# respectively.  Also, the rgbPP values are set to "".5,1,0"" and
# "".1,.1,.1"", respectively.  Notice that the rgbPP value for the
# second particle was set with the -floatValue flag, even though rgbPP
# is a vector attribute.  The single value was converted into a vector.

pm.particle()
pm.emit( object='particle1', position=((1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5)), attribute=('velocity', 'mass', 'velocity'), vectorValue=((1, 2, 3), (2, 3, 4), (.1, .2, .3), (3, 4, 5)), floatValue=.5)

# This will create five particles in "i"particle1"/i".  The values
# for their attributes are:
#
# Attribute  Particle1   Particle2   Particle3   Particle4   Particle5
# ----------+-----------+-----------+-----------+-----------+---------
# position   """"1,1,1""""   """"2,2,2""""   """"3,3,3""""   """"4,4,4""""   """"5,5,5""""
# velocity   """"1,2,3""""   """"2,3,4""""   """"3,4,5""""   "b"""""3,4,5""""   """"3,4,5"""""/b"
# mass     .5          .3742       "b".3742       .3742       .3742"/b"
#
# Notice that the second value for mass was seet with the -vectorValue
# flag, even though mass is a float attribute.  The vector was
# converted into a float by taking its length.  Also, notice the "b"bold"/b"
# values in the table.  The values for those attribute values were not
# explicitly set in the command.  If there are fewer values given for
# an attribute than there are position flags, the remaining unset
# values are set to the last value set for that attribute.  This
# allows the user to set many of the values to be the same without
# having to use multiple value flags.  One last note.  Notice that the
# attribute flag was passed twice for the attribute velocity.  The value
# flags for repeated attributes pick up where the previous ones left
# off.

x = rand(1)
y = rand(1)
z = rand(1)
p = sphrand(5)
pm.emit( object='particle1', pos=((x, y, z), ('($p.x)', '($p.y)', '($p.z)')) )

# This is a piece of Python code that could be put in a script or
# even in an expression.  It adds a random number of particles
# to the already-existing particle object "i"particle1"/i".  Since
# the number of particles as well as the positions and velocities
# of the particles are random, it would be impossible to just have
# the emit action itself in the expression or script.  It must be
# built as a string and then sent to the command processor with the
# "b"eval"/b" or "b"evalEcho"/b" commands.  Notice that when appending
# the vector variables to the string, it is not necessary to append
# each component of the vectors separately.  When they are converted
# from a vector to a string, the three components get separated with
# a space automatically, thus formatting them in the desired way.
# An example of a possible result from this "script" could be:

pm.emit( object='particle1', pos=((1.899864198, -6.721569708, 0.585203937), (8.103957656, -4.042442985, 2.047724209), (-1.392914569, -0.109724376, 8.62265813), (1.960103537, -3.203145195, -7.6892516), (2.564072614, -6.049536895, 1.334818295), (-5.603376821, 4.33595058, 6.952385447), (-2.478591746, 6.286855715, 6.851659059), (2.424670276, -4.083412217, 6.320538621), (6.440800453, 3.405519296, 5.462135819), (2.445192551, 1.397203422, 3.443755853)), at='velocity', vv=((-2.348796409, 4.022130218, 0.5316172944), (4.149667117, -1.023146404, 1.97965556), (-0.08429132578, -0.5518495233, 1.591812495), (2.597930963, 1.033536331, -1.398351383), (-3.102859272, 3.423569856, 0.7895603241), (-2.519331228, -2.5684916, -1.530779154), (-2.645169119, -0.3186551381, 0.9164776099), (-0.6183816487, -1.060784068, -0.8748223942), (-0.2460372256, 3.567980747, -2.007567372), (1.735044809, -3.660099445, -1.765401859)) )

# The spacing in the string is just for formatting reasons and does
# not affect how the action executes or compiles.

Previous topic

pymel.core.effects.dynPref

Next topic

pymel.core.effects.emitter

Core

Core Modules

Other Modules

This Page