MaxLINQ - LINQ functions for maxScripters

5 votes
Version: 
1.02
Date Updated: 
02/22/2017
Author Name: 
Andrés Fernández Cruz

MaxLINQ tool is intended to be a way to use inside maxscript language sweet predefined functions, similar to those in C# LINQ, through an easy lambda-style expressions syntax, concatenating functions after functions.

You can query arrays, strings, maxscript enumerables (objectSet, bitArray, groups, pathnames...) and DotNet IEnumerables.Moreover, it includes  specific functions for maxObjects.

It can be used both in your own scripts or directly in the 3dsMax Listener.

Some intuitive simple examples are:

maxLINQ

Copy the maxscript file into your scripts startup folder and enjoy with more than 50 sweet functions to query arrays of any type, strings, max enumerables (bitArrays, objectSets, pathNames...) and dotNet IEnumerables.

For a general overview, help and examples, key in the listener:

  • maxLINQ.Help()--General overview and list of functions
  • maxLINQ.helpFN "<function name>": --help on each maxLINQ function and examples
  • maxLINQ.helpFN "LA"--help on LambdExpressions syntax
  • maxLINQ.helpMAN()--help on maxLINQ Manager Functions

----------------------------------------------

The list of available functions is as follows:

QUERY FUNCTIONS:(Use a Boolean Lambda Expression. Don't affect to array elements values. Allow further queries)

  • _Where: Selects the array elements that satisfy a Boolean Lambda Expression.
  • W: same than _Where.
  • mappedProperty: Collects the 'mapped property' of the MaxObject_elements in the array that satisfy the Boolean Lambda Expression.
  • mappedProp: same than mappedProperty.
  • mappedGeometry: Collects the 'Geometry' of the Geometry_Objects in the array that satisfy the Boolean Lambda Expression.
  • mappedGeom: same than mappedGeometry.
  • DotNetIterator: Collects the Items of a 'Dotnet Iteratable Collection' that satisfy the Boolean Lambda Expression.
  • TakeWhile: Returns the array elements as long as the Boolean Lambda Expression is true
  • SkipWhile: Bypasses elements in the array as long as the Boolean Lambda Expression is true and then returns the remaining elements

FILTER FUNCTIONS:(Most use a Lambda Expression for projecting array values. Array values change for 'Select'=='Apply' functions. Allow further queries)

  • DotNetIteratorGet: Collects a value/property from the Items of a 'Dotnet Iteratable Collection' applying the Lambda Expression to the Item.
  • Select: Creates a new array by applying a Lambda Expression to the array elements.
  • Apply: same as Select
  • GroupBy: Creates a new array by grouping the array elements that evaluate to the same value when applying to them the Lambda Expression
  • MakeUnique: Creates a new array with unique elements.
  • Distinct: same than MakeUnique.
  • Intersect: Creates a new array with the common elements in a second array.
  • Except: Creates a new array with the elements of the array that are not in a second Array.
  • Union: Creates a new array with all unique elements of the array and a second array.
  • Concat: Creates a new array concatenating all elements of the array and a second array.
  • flatten: Flattens one level of the array
  • flattenAll: Flattens all levels of the array. The result array is a one dimension array.
  • Sort: Returns the sorted array.
  • orderBy: same than Sort.
  • ReOrder: Returns a reordered array based on an arrayIndex order
  • Reverse: Reverses the order of the array
  • Take: Returns the specified number of contiguous elements from the start of the array
  • Skip: Bypasses the specified number of contiguous elements from the start of the array and then returns the remaining elements
  • Replace: Replaces all occurrences of a given value in the array with another value.
  • ReplaceAt: Replaces the occurrence of a given value at a given index position with another value if the match is true
  • Remove: Removes all occurrences of a given value in the array.
  • RemoveAt: Removes the occurrence of a given value at a given index position if the match is true
  • Save: Saves the temporary query result to an existing variable name in the actual scope
  • Debug: Prints the temporary query result to Listener
  • OfType: selects the array elements that are of the indicated maxClass type.
  • Split: Splits a String into substrings based on the strings in a 'stringArray'. This function is only valid for 'String maxLINQ'.
  • Trim: Removes all leading and trailing occurrences of the set of characters specified in a given String. This function is only valid for 'String maxLINQ'.
  • TrimEnd: Removes all trailing occurrences of the set of characters specified in a given String. This function is only valid for 'String maxLINQ'.
  • TrimStart: Removes all leading occurrences of the set of characters specified in a given String. This function is only valid for 'String maxLINQ'.

FINAL FUNCTIONS: (they are the last function in the global query)

  • Show: Returns the result array after previous Query and Filter functions.
  • ToArray: Same as Show for Array Queries. For String Queries, splits the string into a character array.
  • ToString: Converts the result array to a string array
  • ToFile: Writes the result array to the specified File, one array element by line.
  • Count: Returns the number of elements in the result array
  • Sum: Returns the addition of the array elements
  • Average: Returns the average value of the array elements
  • _min: Returns the minimum value of the array elements
  • _max: Returns the maximum value of the array elements
  • All: Returns TRUE if all the array elements satisfy the Boolean Lambda Expression, FALSE otherwise
  • Any: Returns TRUE if at least one of the array elements satisfy the Boolean Lambda Expression, FALSE otherwise
  • First: Selects the first array element that satisfy the Boolean Lambda Expression.
  • Last: Selects the last array element that satisfy the Boolean Lambda Expression.
  • Contains: Determines whether an array contains a specified value. 
  • SequenceEqual: Determines whether two sequences are equal by comparing the elements.
  • Compare: Compares two arrays by comparing the result after applying a Lambda expression to each array. The result must be comparable
  • isEmpty: Determines if the array is empty.
  • updateObjects: updates GeometryClass objects in case of previous queries using mappedProp or mappedGeom on GeometryClass objects

------------------------------------------------------------------------------------------------------

MANAGER FUNCTIONS:

  • maxLINQ.help(): shows this message (summary of functions)
  • maxLINQ.helpFN \"<function name>\": for help on each maxLINQ function
  • maxLINQ.helpFN \"LA\": for help on LambdExpressions syntax
  • maxLINQ.helpMAN(): for help on maxLINQ Manager Functions
  • maxLINQ.isInstance <qarray>: checks if <qarray> is a maxLINQ instance
  • maxLINQ.dispose <[&]qarray>: voids <qarray> maxLINQ instance
  • maxLINQ.createInstance <array>: creates a maxLINQ instance from array
  • maxLINQ.Show <qarray>: returns the value of a maxLINQ instance

MANAGER UTILITIES:

  • maxLINQ.NRange <valuePair|valueTriple>: Generates a sequence of numbers within a specified range.
  • maxLINQ.SRange <valuePair>: Generates a string with a sequence of especified ASCII characters
  • maxLINQ.Repeat <valuePair>: Generates a sequence that contains one repeated value a specified number of times.
  • maxLINQ.maxInstances MAXClassType: Returns a maxLINQ instance whose value is an array with all the MaxClassType instances in the scene.
  • maxLINQ.readFile filename: Returns a maxLINQ instance whose value is a string array where each element corresponds to a line of the specified File
  • maxLINQ.HWND word: Returns all the child windows which name contains the given word. The search is case insensitive
  • maxLINQ.toArray enumerable: Returns the enumerable collection as array (valid for ObjectSet, String, Name, PathName, bitArray, ArrayParameter, SelectionSet, DotNet Enumerables...)
  • maxLINQ.toLookUp <Key: Value: Count:> : Creates a 'LookUp' struct whith the optionals input 'key', 'value' and 'dimension'.
  • maxLINQ.toSelSet <valuePair>: Creates a 'SelSet' struct for querying geometries of Editable_Meshes, Editable_Polys and Trimeshes

You can dowload the script from: http://www.proin3d.org/pathscripts/DOWNLOAD/maxLINQ/MaxLINQ_V102.ms
or see the code in GitHub: https://github.com/aaandres/maxLINQ

 
Hope you enjoy with it!

 

Version Requirement: 
Tested on Max 2014. Should be valid from 2010 to 2017

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
fajar's picture

It shame that 3dsmax script

It shame that 3dsmax script editor did'nt have autocomplete system from external source at system created/edited, kind of like visual studio editor. Keep it up Aaandres. It should be good enough if your wrapper include background worker too.

Thanks

P3D_PathScripts's picture

Updated Version V1.02

New version V1.02 with five new functions:

  • OfType: selects the array elements that are of the indicated maxClass type.
  • Split: Splits a String into substrings based on the strings in a 'stringArray'. This function is only valid for 'String maxLINQ'.
  • Trim: Removes all leading and trailing occurrences of the set of characters specified in a given String. This function is only valid for 'String maxLINQ'.
  • TrimEnd: Removes all trailing occurrences of the set of characters specified in a given String. This function is only valid for 'String maxLINQ'.
  • TrimStart: Removes all leading occurrences of the set of characters specified in a given String. This function is only valid for 'String maxLINQ'.

Some examples of use:

Proin3D_PathScripts
Andrés Fernández Cruz

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.