# Thread: Recreate Set Value & Flatten in Lscript?

1. ## Recreate Set Value & Flatten in Lscript?

Hi guys, what are the Set Value & Flatten on normal axis commands in Lscript?

I'm trying to automate my LW workflow & want to run those commands without the interactive panels showing up.

Thanks

2. You probably have to create the code for those steps. Not by calling the commands themselves I would guess.

3. It would be nice to have something like LScript Commander for modeler so you can capture the internal commands as you use them.

The Mirror tool also has an interactive panel, but they created 3 Lscripts "mirrorZ.ls, mirrorY.ls & mirrorX.ls" to bypass the panel, maybe they could do the same here. Hint..hint...LW3Dgroup

4. I read the reference manual & User Guide & came up with this for "set value" replacement...must be the world's simplest Lscript :P

How on earth do I even start trying to tackle the flatten tool on normal axis.....Matt, are you out there

Code:
```//-----------------------------------------
// LScript Modeler template
//

@version 2.2
@warnings
@script modeler

main
{
// edit only selected components.

selmode(DIRECT);

scale(<0,1,1>);

}```

5. For flatten to normal... take your polygon selection, and average the normal. This gets you the normal you need.

Once you have the normal, you can use the equation of a plane (Ax + By + Cz + D = 0, or P dot3d N + D = 0) to figure out which way the points need to move to flatten out, D being the distance along the normal vector. Move all your points in your selection, and there you go... (You do this by plugging in the values of your vertices and taking the dot product; This yields the distance along the normal vector the point needs to move ( P += (D * N) )

As options, you could give the user the choice of first selected poly normal, average poly normal, or last selected poly normal to flatten to.

Flatten to X, Y and Z would work the same way; get the average value for that axis, and then set all the points to the new value.
Code:
```//Code to average coordinate values goes here...
newvalue = center(boundingbox());
editbegin();
foreach(p, points){
tmp = pointinfo(p);
if(mode = X_COORD) tmp.x = newvalue.x;
if(mode = Y_COORD) tmp.y = newvalue.y;
if(mode = Z_COORD) tmp.z = newvalue.z;
pointmove(p,tmp);
}
editend();```

6. Thanks Kryslin, but that's way over my head

I got it working by using quadro app to send keyboard keys to modeler

7. Kuzey : Flatten to X, Y, or Z is fairly simple, as far as lscripts go. And knowing a bit about vector math is kind of necessary in doing some pretty cool things, like move all the selected points to the same plane. Likewise, set value is roughly the same script, except instead of generating a value from the selection, you get the value from the user. I find lscript easier to work with than Python, because I'm more familiar with C / C# syntax...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•