Feedback

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

Friday, 10 June 2011

LScript - Modeler_2PointPolyChain


LScript (Modeler) to produces a 2 point polychain between two selected 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 - 2PointPolyChain

    Modeler_2PointPolyChain.ls

*/

@version 2.2
@warnings
@script modeler
@name *2 Point Poly Chain

    // Title
    sTitle = "*2 Point Poly Chain";

    // Version
    sVersion = "v1.0";

    ctrl_c0;

main
{

    // Recall
    iNumber = recall("iNumber",10);

    reqbegin(sTitle + " " + sVersion);

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

    // Control
    ctrl_c0 = ctlinteger("Number",iNumber);

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

    return if !reqpost();

    iNumber = getvalue(ctrl_c0);

    // Store
    store("iNumber",iNumber);

    // Selection - Point (GLOBAL)
    selmode(GLOBAL);
    iPointCountBefore = pointcount();

    // Selection - Point (DIRECT)
    selmode(DIRECT);
    iPointCount = pointcount();
    if(iPointCount <= 1) error("Select two points.");
    if(iPointCount > 2) error("Select two points.");

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

        editbegin();

            vStart = pointinfo(points[1]);
            vEnd = pointinfo(points[2]);

            nDistance = distance3D(vStart,vEnd);
            if(iNumber <> 0.0){vOffset = (vEnd - vStart) / iNumber;}else{vOffset = <0.0,0.0,0.0>;}
           
            for(n = 1; n <= iNumber; n++)
              {
              aPoints[1] = addpoint(vStart + (vOffset * (n - 1)));
              aPoints[2] = addpoint(vStart + (vOffset * n));
              addpolygon(aPoints);

              monstep(); // Progress Monitor
              } 

        editend();

    monend(); // Progress Monitor

    // Selection - Point (GLOBAL)
    selmode(GLOBAL);
    iPointCountAfter = pointcount();
    if((iPointCountAfter - iPointCountBefore) > 0)
      {
      for(s = 1; s <= (iPointCountAfter - iPointCountBefore) ; s++){aSelection[s] = s + iPointCountBefore;}
      selmode(USER);
      selpoint(SET, POINTNDX, aSelection);

      mergepoints(0.0); // Merge Points
      }
}

button_reset
{
    setvalue(ctrl_c0,10); // Number
}

// VECTOR 3D

distance3D: v1, v2 // n
{
    // Vector
    return(sqrt(((v2.x - v1.x) * (v2.x - v1.x)) +
                ((v2.y - v1.y) * (v2.y - v1.y)) + 
                ((v2.z - v1.z) * (v2.z - v1.z))));
}
All scripts available at my Google Drive at
https://drive.google.com/open?id=1cR_q2GVUAJHumic1-A3eXV16acQnVTWs

1 comment:

  1. Thanks for this handy tool, it allows me a comfortable way to perform several advanced techniques in both a flexible and efficient manner.

    ReplyDelete