Itoo Software Forum

Author Topic: Expression Editor  (Read 5421 times)

ludwig

  • Newbie
  • *
  • Posts: 4
Expression Editor
« on: May 11, 2015, 08:52:18 AM »
Hello,

Is there any Tutorial about the specific functionality of the parameters contained in the Expression Editor. Let me give some examples:

1. How can I control the pitch of a segment? May the pitch be 5 grades at the start and 30    grades in the end
2. How can I control a segment in Z-direction on the spine?
3. Is there a possibility to create a ProCutter detail with RailClone, as you can do with 123D Make to get a file for CNC-application?

Sorry for eventually using the technical terms incorrectly,
even more i would be happy about helpful answers,
thanks.

Paul Roberts

  • iToo Software
  • Hero Member
  • *****
  • Posts: 2991
Re: Expression Editor
« Reply #1 on: May 11, 2015, 12:47:59 PM »
Hi,

There isn't currently a tutorial that systematically goes through each of the functions of the expressions editor, but you'll be pleased to know that we have plans to release a guide to expressions in the future. In the meantime it might be helpful to know that expressions use the same class as found elsewhere in max. You can read more about this in Autodesk's documentation here (with the exception of the predefined variables with variable values, which are not supported)

As well as these we have added the RailClone specific variables you see in the list on the right of the Expression editor. Clicking on each of these should give you a brief description but below is summary.
Inputs
Input1,2,3 etc These refer to any value wired into the Arithmetic nodes inputs. The number relates to the input slot counting from the top down.

Spline Variables
XSplineCoords,YSplineCoords Refers to the position of the current segment over the Spline on the local coordinates measured from the RailClone objects pivot point.  To access the value for a particular axis ,X axis for example, you must append a .x,.y,or .z to the end of the variable, e.g. XSplineCoords.x
XSectionLength, YSectionLength returns the length in scene units of the current section where a section is the path between two Start, End, Corner or Evenly segments.
XSplineLength, YSplineLength returns the length in scene units of the current spline.
XSplinePosition, YSplinePosition returns the position of the current segment on the spline. This is measured not as an absolute measurement in scene units but a decimal value between 0 and 1 that represents the position of the current segment along the spline.
XSectionPosition, YSectionPosition Like above but instead of returning the position along the spline, returns the position along the spline section  where a section is the path between two Start, End, Corner or Evenly segments.
XSplineType returns 0 if the spline is a line and 1 if it is a curve. Useful for conditional statements.
XSplineMatID returns the material ID applied to the current spline section.

X Vertex
XVertexType returns 0 if the current or previous vertex is of the type smooth, 1 if it is a corner, 2 if a Bezier, and 3 if it is a Bezier-Corner. Useful for conditional statements.
XVertexAngle returns the Angle between X Spline segments on the current vertex measured between 0 and PI radians. (0 - 180 degrees when converted)
XVertexWideAngle returns the angle between X Spline segments on current vertex  measured between 0 and 2*PI radians. (0 0 360 degress when converted)

Segments
SegmentXCounter, SegmentYCounter returns the current segment's index along the path. Note that there are two separate counters: one for default segments, and another for Start/End/Corner/Evenly combined.

By combining these built in variables with Max's expression functions we can create some interesting mathematical relationships within RailClone. For example, in your first question you would like to control the rotation based on the segments position along the path. If we look at the list above we can see that the XSplinePosition variable should help us here. Here's how:

  • First create a new transform operator between the Segment and the Generator. When using expressions, you will normally need to wire the node to a transform operator instead of directly to the Segment . This is to do with the order in which these node are evaluated.
  • Right click and export Y Fixed Rotation
  • Wire a new Arithmetic node to the Y Fixed Rotation input
  • Wire two new Numeric nodes to the Arithmetic operator. Rename them Start Angle and End Angle
  • Open the Expression editor and enter the following :

    Input1+((Input2-Input1)*XSplinePosition)

    Remember Input1 is the start rotation and input2 is the end rotation. So we're setting the angle for the beginning of the spline - Input1 -  and then finding the  difference between the start and end angle - +((Input2-Input1) - and finally multiplying the difference by the segments position on the spline (measured from 0.0 to 1.0) to gradually increment the angle.

    The final style looks like this:



The same sort of thing can be done for the Z Direction by exporting Z Fixed Translation from the Transform node. Take a look at the attached style which uses a sine wave to create an undulating pattern.

Quote
Is there a possibility to create a ProCutter detail with RailClone, as you can do with 123D Make to get a file for CNC-application?

RailClone isn't really designed for this purpose so there's not an easy way to produce the splines required for laser cutting or CNC fabrication. Having said that, RailClone outputs an editable poly so you should be able to use one of the many scripts available for this purpose. I've tested this one and it works fine but there may be others.

However, I suspect that you'll need a watertight mesh if you intend to fabricate from 3d models, so in RailClone you'll probably want to take a few precautions to ensure that vertices are welded correctly. To do this:

  • Go to the Display Rollout and set Display mode to Mesh
  • Turn Off Display > Use Instancing Engine
  • Go to the style rollout and set the slice mode to operate on Quads

  • Turn on Vertex Weld and adjust the Threshold until verts are welded correctly. If the spline is curved you may find it's necessary to increase the Curve Steps for a smoother deformation

I hope that helps, I've attached the examples discussed above for you take a look at. Please let me know if you have further questions.

Many thanks,

Paul
« Last Edit: May 11, 2015, 01:05:40 PM by Paul Roberts »
Paul Roberts
iToo Software

ludwig

  • Newbie
  • *
  • Posts: 4
Re: Expression Editor
« Reply #2 on: May 19, 2015, 09:36:20 PM »
Many cordial thanks for the very helpful and fast answer. I am very happy about the comprehensive and detailed help