[PYTHON] What's in the parameter? Edit String & Expression

This article is the second day of Houdini Advent Calendar 2016.

Values are not the only parameters

Isn't a parameter just a value? I don't know why it doesn't have a value or it turns green!

Expression Green is the state where the parameters are controlled by Expression. ▼ $ F as an example 00.png

Immediately after entering the Expression, a whitish gray color will be added after the Label ("Size" in the above figure). This indicates that the calculated value has been switched to the Expression display. Expression → Click Label to make it a calculated value (Right click and Toggle Expression is also possible) ▼ Left: Calculated value Right: Expression 1.6.png

▼ As a supplement ... Toggle Expression is possible even if it is not an expression or variable. Watch out for floating point errors. 1.7.png

▼ From about Houdini 15 @ can also be used as a parameter (However, the types of attributes that can be used differ depending on the node. For example, only the Detail attribute can be used in the transform node. On the other hand, for the point node that is executed for each point, the point such as @Px attribute is available) 2s.png

The default is HScript (green), you can change it to Python. If you change the H mark next to the gear mark to Python, it will turn red instead of green. I see, Python is red! Don't think. It hasn't changed yet. You can only get Python by right-clicking on a parameter and doing Change Language Python. Yes, green and red were the colors to find the HScript mark displayed in the upper right, or the one corresponding to the Python mark. ▼ In python, local variables can be used like lvar ("TX2"). (Exceptionally, the hou. Prefix can be omitted) 5s.png

Edit Expression with multiple lines

If you want to put multiple lines in the parameter, enter it with ctrl + E or right-click and Edit Expression. But without thinking If you enter the following, an error will occur. ▼ For example, if you want to give a value of 1 only in one frame

if($F==1){
    return 1;
}

3.1.png

The reason for the error is that there is no {} to enclose the whole thing. Therefore

{
 if($F==1){
     return 1;
 }
}

This will work.

Edit String Some parameters do not require parentheses. That is the String parameter. Frequently used String parameters For example, group, file, Wrangle. 4.1.png

However, there are times when you want to use Expression with String as well. In that case, use \ {} \. Even if it is a String type, the part enclosed in \ `(backticks) functions as an Expression. ▼ Zero padding when outputting a file

$HIP/file_`padzero(4, $F)`.bgeo

▼ When you want to generate group (Hello) only at 1 frame

`{
 if($F==1){
  string foo = "Hello";
  return foo;
 }
}`

One last. When will you use it! It feels like, but another conversion is required to put a value in the expression parameter by forcibly using backticks.

atof("`{return 1;}`")

Frequently used Expression Function

http://www.andynicholas.com/?p=1344 Is referred to.

function Description
ch(parameter path) Get the current value of the parameter
chf(parameter path,flame) 特定のflameでパラメータの値を取得します
stamp(copySOP path,Stamp variable,Default value) Stamp variableの現在の値を取得
point(SOP path,Point number,attribute,index) Get point attribute
prim(SOP path,Point number,attribute,index) Get primitive attribute
clamp(value,min,max) Value within the range of minimum and maximum values
fit(value,min,max,newmin,newmax) Remap old range values to new range and clamp
fit01(value,newmin,newmax) fit()Same as, value is 0 to 1
smooth(value,min,max) Value smoothed between 0 and 1 from minimum to maximum
noise(x,y,z) noise
rand(seed) random number
length(x,y,z) Vector length
distance(x1,y1,z1,x2,y2,z2) Distance between two points
bbox(SOP path,dimension type) Bounding box(dimension type:D_XMIN, D_YMIN, D_ZMIN, D_XMAX, D_YMAX, D_ZMAX, D_XSIZE, D_YSIZE, D_ZSIZE)

Other sin, cos, tan, asin, acos, atan, atan2, abs, pow, sqrt, ceil, floor, atof, dot, cross, deg, rad, exp, frac, hsv, rgb, min, max, log, log10, round, substr, strreplace

Is available.

Frequently used Expression Local Variables

variable Description
$PT Point number
$PR Primitive number
$CY Current copy number
$TX,$TY,$TZ Point position
$NX,$NY,$NZ point/Primitive normal
$CR,$CG,$CB,$CA point/Primitive color
$VX,$VY,$VZ Point speed
$BBX,$BBY,$BBZ Normalized (0-1) positions of points in the bounding box
$CEX,$CEY,$CEZ Center of gravity of geometry
$AGE The number of seconds a particle is alive
$LIFE Normalized age of particles (0-1)
$XMIN,$XMAX,$YMIN,$YMAX,$ZMIN,$ZMAX Bounding box range
$SIZEX,$SIZEY,$SIZEZ Bounding box size
$TX2,$TY2,$TZ2 The position of the point coming from the second input

Expression is convenient, but local variables are slow, so it is better to use VEX if possible. that's all

Recommended Posts

What's in the parameter? Edit String & Expression
Get the query string (query string) in Django
Escape curly braces in the format string
Find it in the procession and edit it
The eval () function that calculates a string as an expression in python
json.dumping None in python returns the string null
Check if the string is a number in python
Shift the alphabet string by N characters in Python
Extract the element by deleting the tag contained in the string
Edit fonts in Python
Regular expression in regex.h
String manipulation in python
What's new in Python 3.5
Regular expression in Python
Regular expression in Python
What's new in Python 3.6
I was in trouble because the character string in the PDF was strange
Find out the apparent width of a string in python
Python --Find out number of groups in the regex expression
Sort the string array in order of length & Japanese syllabary
In omegaconf, let's pass the direct parameter file to the function
Find out how many each character is in the string.
In Django, how to abbreviate the long displayed string as ....
Reproduce the Python regular expression r'\ w (? U)' in JavaScript