Lscript Question

Ok, another question...

Both selPoint() and selPolygon() have a minor parameter of POINTNDX and POLYNDX, respectively.

What is this? What array am I supplying indices to the selection command? Is this global, or relative to the selection I may be working with? I'm more curious than anything...

I mean, I get POINTID and POLYID, and I normally use these all the time, inside an editbegin() and editend() pair. So what are these poly and point indices?
 
I believe is it the id of the point/polygon. I would assume it's global to the model since ids don't change dynamically.
 
Points can be identified by index (starting from 0..point_count-1) or by LWPntID pointer.
Polygons can be identified by index (starting from 0...poly_count-1) or by LWPolID pointer.
If you have address (i.e. outside of 0..count-1) it's the second one.
 
This is not an exhaustive list, but this is a scratch pad of some poly / point stuff (it's not a script you can run as is, just a collection of stuff) that I kept lying around, might help.

Code:
@version 2.13
@warnings
@name "Point and Polygon Routines"

main
{
    // Selected including nothing selected = all selected rule
    selmode( USER );

    // Direct selections only
    selmode(DIRECT);

    // Selected everything regardless of selection
    selmode( GLOBAL );

    // 0 = Point / 1 = Poly / 2 = Volume / 3 = Edge
    selection_mode = getmode("SELECTION");

    // 0 = Off / 1 = On
    symmetry_mode = getmode("SYMMETRY");

    // 0 = Mouse / 1 = Pivot / 2 = Selection / 3 = Pivot
    action_center_mode = getmode("ACTIONCENTER");

    // Get the point count
    point_count = pointcount();

    // Need minimum of two points
    if(point_count < 2)
    {
        error("You need to select at least 2 points");
    }

    // Get selected poly information
    selectedPolys = polycount();

    // Total number of selected polygons
    selectedTotalPolys = selectedPolys[1];

    // Total number of selected polygons with 1 point
    selected1PointPolys = selectedPolys[2];

    // Total number of selected polygons with 2 points
    selected2PointPolys = selectedPolys[3];

    // Total number of selected polygons with 3 points
    selected3PointPolys = selectedPolys[4];

    // Total number of selected polygons with 4 points
    selected4PointPolys = selectedPolys[5];

    // Total number of selected polygons more than 4 points
    selectedMoreThan4PointPolys = selectedPolys[6];



    // Storing polygon information
    var polyIDs         = nil;
    var polyTypes       = nil;
    var polyPartTags    = nil;

    editbegin();
    foreach(poly, polygons)
    {
        polyIDs         += poly;
        polyTypes       += poly.type();
        polyPartTags    += poly.tag("PART");
    }
    editend();


@script modeler
@warnings
@name "Part Name"

main
{
    selmode(DIRECT);
    selectedItems = polycount();

    if(selectedItems[1] == 0)
    {
        error("Nothing Selected");
    }

    editbegin();
        for(loop = 1; loop <= selectedItems[1]; loop++)
        {
            partName = polygons[loop].tag("PART");

            info("Part Name: ", partName);
        }
    editend();
}


    // Inspecting polygon information
    var polyNumber = 1;

    editbegin();
    // Get ID of polygon
    polyID              = polygons[polyNumber];

    // Number of points that make up the poly
    numPointsInPoly     = polypointcount( polygons[polyNumber] );

    // The vector for the poly normal
    polyNormal          = polynormal( polygons[polyNumber] );

    // Get the surface assigned to the poly
    polyInformation     = polyinfo( polygons[polyNumber] );
    polySurface         = polyInformation[1];

    // Store point IDs and positions for polygon
    // Starts at 2 because the surface name is the first entry in the array that polyinfo() returns
    // Every entry in the array after that is the point ID
    for(loop = 2; loop <= numPointsInPoly; loop++)
    {
        polyPointIDArray    += polyInformation[loop];

        // Point into gets the points XYZ location
        polyPointPosArray   += pointinfo(polyInformation[loop]);
    }

    editend();



    // Selecting and deselecting poly selections

    // Select a poly by its ID
    selpolygon( SET, POLYID, polyIDs[1] );

    // Select all polys by their ID using a custom function
    select_poly_ids( polyIDs );

    // Select all polys
    selpolygon( SET );

    // Deselect a poly by its ID
    selpolygon( CLEAR, POLYID, polyIDs[1] );

    // Deselect all polys by their ID using a custom function
    deselect_poly_ids( polyIDs );

    // Clear all polys
    selpolygon( CLEAR );

    // Invert selections
    selinvert();

    // Hiding selected polys
    selhide( SELECTED  );

    // Hiding unselected polys
    selhide( UNSELECTED  );

    // Unhiding hidden polys
    selunhide();



    // Selecting and deselecting point selections

    // Select a point by its ID
    selpoint( SET, POLYID, polyPointIDArray[1] );

    // Select all points by their ID using a custom function
    select_point_ids( polyPointIDArray );

    // Select all points
    selpoint( SET );

    // Deselect a point by its ID
    selpoint( CLEAR, POINTID, polyPointIDArray[1] );

    // Deselect all points by their ID using a custom function
    deselect_point_ids( polyPointIDArray );

    // Clear all points
    selpoint( CLEAR );
}

select_poly_ids: polyIDArray
{
    for(loop = 1; loop <= polyIDArray.size(); loop++)
    {
        selpolygon( SET, POLYID, polyIDArray[loop] );
    }
}

deselect_poly_ids: polyIDArray
{
    for(loop = 1; loop <= polyIDArray.size(); loop++)
    {
        selpolygon( CLEAR, POLYID, polyIDArray[loop] );
    }
}

select_point_ids: pointIDArray
{
    for(loop = 1; loop <= pointIDArray.size(); loop++)
    {
        selpoint( SET, POINTID, pointIDArray[loop] );
    }
}

deselect_point_ids: pointIDArray
{
    for(loop = 1; loop <= pointIDArray.size(); loop++)
    {
        selpoint( CLEAR, POINTID, pointIDArray[loop] );
    }
}
 
Matt: handy stuff, that.

Re: getmode("SYMMETRY"); ... is there an equivalent to set / toggle the symmetry mode?

Still, regards to the indices question... where are those indices coming from, what are they referencing? This looks like something that will require experimentation, which means I have to wait until I can go up and down stairs to get to the work station... I hate recovering from surgery.
 
The indices are simply the indices from the Arrays, taht are generated by LScript when you enter the editmode (editbegin).
By entering the editmode in LScript, the engine creates 2 Arrays.
1 named "polygons" and one named "points". The indices are simply the index of an element in these Arrays.

I hope this will help.

Regards
KANUSO
 
Here's an interesting one...

Is it possible to read a bone's weightmap in lscript? It appears you can set one - BoneWeightMapName("name"); - but I don't see anything that looks like you can read the name of the weight map...

Here's why I'm asking : I have a tool, that assigns weight maps symmetrically, giving identifiers for Right and Left for bones and weight maps. My last revision had added buttons to move up and down the hierarchy, and assign & move to the next bone. I want to add "Next Unassigned" to the buttons, so that you can move to the next bone that doesn't have a weight map assigned to it.

If it isn't possible, then I have another candidate for conversion to Python.
 
Here's an interesting one...

Is it possible to read a bone's weightmap in lscript? It appears you can set one - BoneWeightMapName("name"); - but I don't see anything that looks like you can read the name of the weight map...

Here's why I'm asking : I have a tool, that assigns weight maps symmetrically, giving identifiers for Right and Left for bones and weight maps. My last revision had added buttons to move up and down the hierarchy, and assign & move to the next bone. I want to add "Next Unassigned" to the buttons, so that you can move to the next bone that doesn't have a weight map assigned to it.

If it isn't possible, then I have another candidate for conversion to Python.

Possibly mitigated since, but according to this thread, in 2006 Dodgy was asking Newtek to fix lack of read access to that info (as well as some other important info access issues).
 
Last edited:
Is it possible to read a bone's weightmap in lscript?

In Python it's possible to get weight map assigned to specified bone using Bone Info.
sdk/lwpython2015.3.zip/python2015/globalboneinfo.html
 
JWeide: From what I can tell, based on going through the lscript release docs, It hasn't been added. However, until someone from Newtek comes up and says "Hey, its there, here's a code snippet..." then I'm off to Python...

Sensei : Yeah, I saw that in the Python SDK docs. Looks like I'm moving my Weight assignment tool over to Python...
 
JWeide: From what I can tell, based on going through the lscript release docs, It hasn't been added. However, until someone from Newtek comes up and says "Hey, its there, here's a code snippet..." then I'm off to Python...
Python approach is direct, might as well use it.
 
As on offhand question, is ther a command sequence string for any of the following?
-Toggle Symmetry
-Weld 2.0
-Weld Avg 2.0

The lscript built in weld() and weldavg() don't respect symmetry, but the updated modeler detail tools do.
 
Another question:

While it is easy to add a motion plugin to an object in Layout, some do not have anyway to set any of the settings (Namely, simple position and rotation constraints), how does one go about this anyway? I assume it has a lot of saving and loading of the scene file involved (add plugin, save file, use lscript to edit file, and reload the file) going on, but I was wondering if there was another way...

Ideally, it would be like the generic_addItemShape command input string you can use to easily set the item shape and not muck around with the comring (saving a lot of code and frustrating errors).

I'd submit a feature request, but the likelihood of something being done on it is apparently Nil. I'll do it anyway, but I figure I'd best work on my own solution.
 
Another question:

While it is easy to add a motion plugin to an object in Layout, some do not have anyway to set any of the settings (Namely, simple position and rotation constraints), how does one go about this anyway? I assume it has a lot of saving and loading of the scene file involved (add plugin, save file, use lscript to edit file, and reload the file) going on, but I was wondering if there was another way...

Ideally, it would be like the generic_addItemShape command input string you can use to easily set the item shape and not muck around with the comring (saving a lot of code and frustrating errors).

I'd submit a feature request, but the likelihood of something being done on it is apparently Nil. I'll do it anyway, but I figure I'd best work on my own solution.
Another stupid solution but would work, is to use Autoit to open the interface to set the settings for you. and then have your LScript launch the Autoit script to do it. You Could pass variables back and forth to Autoit. Clunky, but it would work if there's no other choice.
 
As noted in Kryslin's lscripts, I managed to do it in LW2020, after digging out a couple of undocumented commands in the SDK.
One is SaveServerDataByItemID, and the other is LoadServerDataByItemId.

You use the first to save out a template for your data. In my case, it was the simple point contraints and simple orient constraints.

Then, in your script, you read in the template, set up your expressions if needed. Apply the server or servers. set up your template and write it out as a temp file. then set up your commands to reload the server data for the servers, then execute those commands, then refresh the scene.

When I was done, I had applied the two sets of settings to the motion modifiers as needed, and I could control the blending of the constraint with the switch null I had set up.

Why go through all that? Admittedly, I'm toying with the idea of reverse engineering Rhiggit2 and making it work in Python, so prototyping the some of the underlying things needed is a must. I've got item shapes done, I've got adding Constraints done. I'm working on aligning bones/joints and setting rest lengths. That way, I build up the basic functions I need that are debugged to hell and back so I'm not tracking down errors in 20K lines of code. :) It's not a serious project, though.
 
As noted in Kryslin's lscripts, I managed to do it in LW2020, after digging out a couple of undocumented commands in the SDK.
One is SaveServerDataByItemID, and the other is LoadServerDataByItemId.

You use the first to save out a template for your data. In my case, it was the simple point contraints and simple orient constraints.

Then, in your script, you read in the template, set up your expressions if needed. Apply the server or servers. set up your template and write it out as a temp file. then set up your commands to reload the server data for the servers, then execute those commands, then refresh the scene.

When I was done, I had applied the two sets of settings to the motion modifiers as needed, and I could control the blending of the constraint with the switch null I had set up.

Why go through all that? Admittedly, I'm toying with the idea of reverse engineering Rhiggit2 and making it work in Python, so prototyping the some of the underlying things needed is a must. I've got item shapes done, I've got adding Constraints done. I'm working on aligning bones/joints and setting rest lengths. That way, I build up the basic functions I need that are debugged to hell and back so I'm not tracking down errors in 20K lines of code. :) It's not a serious project, though.
That's cool. If you reverse engineer the lite Rhiggit game rig builder too, I'd certainly pay for that tool.
 
Back
Top