vtool.util

Class Summary

StopWatch() Utility to check how long a command takes to run.
VectorBase
Vector2D([x, y])
Vector([x, y, z])
BoundingBox(btm_corner_vector, top_corner_vector) Convenience for dealing with bounding boxes
Variable([name]) Simple base class for variables on a node.
Part(name)
FindUniqueString(test_string)
QuickSort(list_of_numbers) Really fast method for sorting.

Function Summary

initialize_env(name) Initialize a new environment variable.
set_env(name, value) Set the value of an environment variable.
get_env(name) Get the value of an environment variable.
add_to_PYTHONPATH(path) Add a path to the python path, only if it isn’t present in the python path.
profiler_event(frame, event, arg[, indent])
activate_profiler() Activating the profiler will give extremely detailed information about what functions are running and in what order.
try_pass(function) Try a function and if it fails pass.
is_in_maya() Check to see if scope is in Maya.
has_shotgun_api() Check if the shotgun api is available.
has_shotgun_tank() Check if the shotgun tank api is available.
get_current_maya_location() Get where maya is currently running from.
is_in_nuke() Check to see if scope is in Nuke
is_linux() Check to see if running in linux
is_windows() Check to see if running in windows
get_maya_version() Get the version of maya that the scope is running in.
break_signaled() Check to see if Vetala break was signalled.
vector_multiply(vector, value)
param vector:3 value list
vector_divide(vector, value)
param vector:3 value list
vector_magnitude(vector) Get the magnitude of a vector.
vector_add(vector1, vector2)
param vector1:3 value list
vector_cross(vector1, vector2[, normalize])
param vector1:3 value list
rotate_x_at_origin(vector, value[, …]) Rotate a vector around its x axis.
rotate_y_at_origin(vector, value[, …]) Rotate a vector around its y axis.
rotate_z_at_origin(vector, value[, …]) Rotate a vector around its z axis.
get_axis_vector(axis_name) Convenience.
fade_sine(percent_value)
fade_cosine(percent_value)
fade_smoothstep(percent_value)
fade_sigmoid(percent_value)
set_percent_range(percent_value, new_min, …)
get_distance(vector1, vector2) Get the distance between two vectors.
get_distance_2D(vector1_2D, vector2_2D) Get the distance between two 2D vectors.
get_magnitude_2D(vector_2D)
param vector_2D:
 eg [0,0] vector
get_dot_product(vector1, vector2) Get the dot product of two vectors.
get_dot_product_2D(vector1_2D, vector2_2D) Get the dot product of two 2D vectors.
get_average(numbers)
param numbers:A list of floats.
get_midpoint(vector1, vector2) Get the mid vector between two vectors.
get_inbetween_vector(vector1, vector2[, percent]) Get a vector inbetween vector1 and vector2 at the percent
get_simple_center_vector(list_of_vectors)
is_the_same_number(number1, number2[, tolerance])
convert_to_sequence(variable[, sequence_type]) Easily convert to a sequence.
line_side(start_vector, end_vector, …) Find out what side a position_vector is on given a line defined by start_vector and end_vector.
closest_percent_on_line_3D(start_vector, …) Get how far a vector is on a line.
closest_percent_on_line_2D(start_vector, …) Get how far a vector is on a line.
closest_point_to_line_2D(start_vector, …)
convert_number_to_month(month_int)
get_current_time([date_and_time])
get_current_date()
get_first_number(input_string[, as_string])
get_last_number(input_string)
get_end_number(input_string[, as_string]) Get the number at the end of a string.
get_trailing_number(input_string[, …]) Get the number at the very end of a string.
search_first_number(input_string)
search_last_number(input_string) Get the last number in a string.
replace_last_number(input_string, replace_string) Replace the last number with something.
increment_first_number(input_string)
increment_last_number(input_string) Up the value of the last number by 1.
find_special(pattern, string_value, …)
param pattern:A regular expression pattern to search for.
replace_string(string_value, replace_string, …)
replace_string_at_end(line, …)
replace_string_at_start(line, …)
clean_file_string(string)
clean_name_string(string_value[, …])
show_list_to_string(*args)
show(*args)
warning(*args)
error(*args)
find_possible_combos(names[, sort, …])

Functions

initialize_env(name)

Initialize a new environment variable. If the variable already exists, does nothing, no environment variable is initialized.

Parameters:name (str) – Name of the new environment variable.
set_env(name, value)

Set the value of an environment variable.

Parameters:
  • name (str) – Name of the environment variable to set.
  • value (str) – If a number is supplied it will automatically be converted to str.
get_env(name)

Get the value of an environment variable.

Parameters:name (str) – Name of an environment variable.
Returns
str:
add_to_PYTHONPATH(path)

Add a path to the python path, only if it isn’t present in the python path.

Parameters:path (str) – The path to add to the python path.
profiler_event(frame, event, arg, indent=[0])
activate_profiler()

Activating the profiler will give extremely detailed information about what functions are running and in what order.

try_pass(function)

Try a function and if it fails pass. Used as a decorator. Usage: @try_pass def myFunction():

print ‘something’
is_in_maya()

Check to see if scope is in Maya.

Returns:
Return type:bool
has_shotgun_api()

Check if the shotgun api is available.

Returns:
Return type:bool
has_shotgun_tank()

Check if the shotgun tank api is available.

Returns:
Return type:bool
get_current_maya_location()

Get where maya is currently running from.

is_in_nuke()

Check to see if scope is in Nuke

Returns:
Return type:bool
is_linux()

Check to see if running in linux

Returns:
Return type:bool
is_windows()

Check to see if running in windows

Returns:
Return type:bool
get_maya_version()

Get the version of maya that the scope is running in.

Returns:The date of the Maya version.
Return type:int
break_signaled()

Check to see if Vetala break was signalled.

Returns:
Return type:bool
vector_multiply(vector, value)
Parameters:
  • vector (list) – 3 value list
  • value (float) – value to multiply the vector by
Returns:

3 value list

Return type:

list

vector_divide(vector, value)
Parameters:
  • vector (list) – 3 value list
  • value (float) – value to divide the vector by
Returns:

3 value list

Return type:

list

vector_magnitude(vector)

Get the magnitude of a vector. Good to see if there is any distance before doing a full distance calculation.

Parameters:
  • vector (list) – 3 value list
  • value (float) – value to divide the vector by
Returns:

Return type:

float

vector_add(vector1, vector2)
Parameters:
  • vector1 (list) – 3 value list
  • vector2 (list) – 3 value list
Returns:

3 value list

Return type:

list

vector_cross(vector1, vector2, normalize=True)
Parameters:
  • vector1 (list) – 3 value list
  • vector2 (list) – 3 value list
  • normalize (bool) – make the result a unit vector that has values from 0 - 1
Returns:

3 value list

Return type:

list

rotate_x_at_origin(vector, value, value_in_radians=False)

Rotate a vector around its x axis.

Parameters:
  • vector (list) – 3 value list
  • value (float) – amount to rotate
  • value_in_radians (bool) – If the value is in radians, if not in degrees.
Returns:

3 value list that is the result of the rotation.

Return type:

list

rotate_y_at_origin(vector, value, value_in_radians=False)

Rotate a vector around its y axis.

Parameters:
  • vector (list) – 3 value list
  • value (float) – amount to rotate
  • value_in_radians (bool) – If the value is in radians, if not in degrees.
Returns:

3 value list that is the result of the rotation.

Return type:

list

rotate_z_at_origin(vector, value, value_in_radians=False)

Rotate a vector around its z axis.

Parameters:
  • vector (list) – 3 value list
  • value (float) – amount to rotate
  • value_in_radians (bool) – If the value is in radians, if not in degrees.
Returns:

3 value list that is the result of the rotation.

Return type:

list

get_axis_vector(axis_name)

Convenience. Good for multiplying against a matrix.

Parameters:axis_name (str) – ‘X’ or ‘Y’ or ‘Z’
Returns:vector eg. (1,0,0) for ‘X’, (0,1,0) for ‘Y’ and (0,0,1) for ‘Z’
Return type:tuple
fade_sine(percent_value)
fade_cosine(percent_value)
fade_smoothstep(percent_value)
fade_sigmoid(percent_value)
set_percent_range(percent_value, new_min, new_max)
get_distance(vector1, vector2)

Get the distance between two vectors.

Parameters:
  • vector1 (list) – eg. [0,0,0] vector
  • vector2 (list) – eg. [0,0,0] vector
Returns:

The distance between the two vectors.

Return type:

float

get_distance_2D(vector1_2D, vector2_2D)

Get the distance between two 2D vectors.

Parameters:
  • vector1_2D (list) – eg. [0,0] vector
  • vector2_2D (list) – eg. [0,0] vector
Returns:

The distance between the two 2D vectors.

Return type:

float

get_magnitude_2D(vector_2D)
Parameters:vector_2D (list) – eg [0,0] vector
Returns:The magnitude of the vector.
Return type:float
get_dot_product(vector1, vector2)

Get the dot product of two vectors. Good for calculating angles.

Parameters:
  • vector1 (list) – eg. [0,0,0] vector
  • vector2 (list) – eg. [0,0,0] vector
Returns:

The dot product between the two vectors.

Return type:

float

get_dot_product_2D(vector1_2D, vector2_2D)

Get the dot product of two 2D vectors. Good for calculating angles.

Parameters:
  • vector1_2D (list) – eg. [0,0] vector
  • vector2_2D (list) – eg. [0,0] vector
Returns:

The dot product between the two 2D vectors.

Return type:

float

get_average(numbers)
Parameters:numbers (list) – A list of floats.
Returns:The average of the floats in numbers list.
Return type:float
get_midpoint(vector1, vector2)

Get the mid vector between two vectors.

Parameters:
  • vector1 (list) – eg. [0,0,0] vector
  • vector2 (list) – eg. [0,0,0] vector
Returns:

eg. [0,0,0] the midpoint vector between vector1 and vector2

Return type:

list

get_inbetween_vector(vector1, vector2, percent=0.5)

Get a vector inbetween vector1 and vector2 at the percent

Parameters:
  • vector1 (list) – eg. [0,0,0] vector
  • vector2 (list) – eg. [0,0,0] vector
  • percent (float) – The percent the vector should be between vector1 and vector2.
  • percent will be exactly on vector1. (0) –
  • percent will be exactly on vector2. (1) –
  • percent will be exactly the midpoint between vector1 and vector2. (0.5) –
Returns:

eg. [0,0,0] the vector that represents the vector at the percentage between vector1 and vector2

Return type:

list

get_simple_center_vector(list_of_vectors)
is_the_same_number(number1, number2, tolerance=1e-05)
convert_to_sequence(variable, sequence_type=<type ‘list’>)

Easily convert to a sequence. If variable is already of sequence_type, pass it through. If variable is a list and sequence_type is tuple, convert to tuple. If variable is a tuple and sequence_type is list, convert to list. If variable is not a list or tuple, than create a sequence of sequence type.

Basically insures that a variable is a list or a tuple.

Parameters:
  • variable – Any variable.
  • sequence_type – Can either be python list or python tuple. Needs to be the type ojbect, which means pass it list or tuple not as a string.
Returns:

Returns list or tuple depending on the sequence_type.

Return type:

list, tuple

line_side(start_vector, end_vector, position_vector)

Find out what side a position_vector is on given a line defined by start_vector and end_vector.

Parameters:
  • start_vector (list) – eg. [0,0,0] vector end_vector (list): eg. [0,0,0] vector
  • position_vector (list) – eg. [0,0,0] vector
Returns:

If positive it’s on one side of the line, if negative its on the other side.

Return type:

float

closest_percent_on_line_3D(start_vector, end_vector, position_vector, clamp=True)

Get how far a vector is on a line. If the vector is on start_vector, return 0. If vector is on end vector, return 1. If vector is half way between start and end return 0.5.

closest_percent_on_line_2D(start_vector, end_vector, position_vector, clamp=True)

Get how far a vector is on a line. If the vector is on start_vector, return 0. If vector is on end vector, return 1. If vector is half way between start and end return 0.5.

closest_point_to_line_2D(start_vector, end_vector, position_vector, clamp=True, return_percent=False)
convert_number_to_month(month_int)
get_current_time(date_and_time=True)
get_current_date()
get_first_number(input_string, as_string=False)
get_last_number(input_string)
get_end_number(input_string, as_string=False)

Get the number at the end of a string.

Parameters:input_string (str) – The string to search for a number.
Returns:The number at the end of the string.
Return type:int
get_trailing_number(input_string, as_string=False, number_count=-1)

Get the number at the very end of a string. If number not at the end of the string return None.

search_first_number(input_string)
search_last_number(input_string)

Get the last number in a string.

Parameters:input_string (str) – The string to search for a number.
Returns:The last number in the string.
Return type:int
replace_last_number(input_string, replace_string)

Replace the last number with something.

Parameters:
  • input_string (str) – A string to search for the last number.
  • replace_string (str) – The string to replace the last number with.
Returns:

The new string after replacing.

Return type:

str

increment_first_number(input_string)
increment_last_number(input_string)

Up the value of the last number by 1.

Parameters:input_string (str) – The string to search for the last number.
Returns:The new string after the last number is incremented.
Return type:str
find_special(pattern, string_value, position_string)
Parameters:
  • pattern (str) – A regular expression pattern to search for.
  • string_value (str) – The string to search in.
  • position_string (str) – ‘start’,’end’,’first’,’last’,’inside’ Where the pattern should search.
Returns:

(start_int, end_int) The start and end index of the found pattern. Returns (None,None) if nothing found.

Return type:

tuple

replace_string(string_value, replace_string, start, end)
replace_string_at_end(line, string_to_replace, replace_string)
replace_string_at_start(line, string_to_replace, replace_string)
clean_file_string(string)
clean_name_string(string_value, clean_chars=’_’, remove_char=’_’)
show_list_to_string(*args)
show(*args)
warning(*args)
error(*args)
find_possible_combos(names, sort=False, one_increment=False)