Feedback

Please leave feedback and comments. I am always interested to hear how people get on using these LScripts!

Saturday, 3 March 2018

LScript - Modeler_Converge


LScript (Modeler) to align points based on last or previous selected or average points.

Compatible with Newtek LightWave 9.6 and above.

// LScript Modeler - www.StephenCulley.co.uk
//
// web   address: http://www.stephenculley.co.uk
// email address: email@stephenculley.co.uk

/*  
    LScript Modeler - Converge

    Modeler_Converge.ls

*/

@version 2.2
@warnings
@script modeler
@name *Converge

    // Title
    sTitle = "*Converge";

    // Version
    sVersion = "v1.0";
    
    ctrl_c0, ctrl_c1, ctrl_c2, ctrl_c3;

main
{

    // Store
    bAxisX = recall("bAxisX",true);
    bAxisY = recall("bAxisY",false);
    bAxisZ = recall("bAxisZ",false);
    iSelected = recall("iSelected",1);

    reqbegin(sTitle + " " + sVersion);

    // Reset
    ctrl_res0 = ctlbutton("Reset",50,"button_reset"); // Button Reset
    ctlsep();

    // Control
    ctrl_c0 = ctlcheckbox("X", bAxisX);
    ctrl_c1 = ctlcheckbox("Y", bAxisY);
    ctrl_c2 = ctlcheckbox("Z", bAxisZ);
    ctrl_c3 = ctlchoice("Selected",iSelected,@"First","Last","Average"@);

    // Developer
    ctlsep();
    ctrl_dev0 = ctltext("","developer: Stephen Culley","http://www.stephenculley.co.uk");

    return if !reqpost();

    bAxisX = getvalue(ctrl_c0); // X
    bAxisY = getvalue(ctrl_c1); // Y
    bAxisZ = getvalue(ctrl_c2); // Z
    iSelected = getvalue(ctrl_c3); // Selected

    // Store
    store("bAxisX",bAxisX); // X
    store("bAxisY",bAxisY); // Y
    store("bAxisZ",bAxisZ); // Z
    store("iSelected",iSelected);

    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount <= 1) error("None or not enough points selected.");

    undogroupbegin(); // Undo

    moninit(iPointCount,"Processing...");  // Progress Monitor

    editbegin();

        if(iSelected == 1) vConvergePoint = pointinfo(points[1]); // First
        if(iSelected == 2) vConvergePoint = pointinfo(points[iPointCount]); // Last
        if(iSelected == 3) // Average
          {
          vConvergePoint = <0 .0="">;
          for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
            {
            vConvergePoint += pointinfo(points[iCurrentPoint]);  
            }
          // Resize by points
          vConvergePoint *= 1 / (iPointCount - 1);
          } 

        for(iCurrentPoint = 1; iCurrentPoint <= iPointCount; iCurrentPoint++)
          {
          vPoint = pointinfo(points[iCurrentPoint]);
          if(bAxisX) vPoint.x = vConvergePoint.x; // X
          if(bAxisY) vPoint.y = vConvergePoint.y; // Y
          if(bAxisZ) vPoint.z = vConvergePoint.z; // Z
          pointmove(points[iCurrentPoint],vPoint); // Move point           

          monstep(); // Progress Monitor
          }

    editend();

    undogroupend(); // Undo
}

button_reset
{
    setvalue(ctrl_c0,true); // X
    setvalue(ctrl_c1,false); // Y
    setvalue(ctrl_c2,false); // Z
    setvalue(ctrl_c3,1); // Selected
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs