PDA

View Full Version : Select point/geometry of newly created object



nickdigital
05-12-2011, 05:27 PM
I'm a noob at lscript but I'm trying to learn. I made a lscript that creates a box and runs spherize on it to make a quad box. The basics of it work fine. What I'd like to improve is that if someone runs it on a layer that already has geometry all their layer contents don't get spherized.

My thinking if that if I could select the points or polys of the newly created box and then run spherize I could isolate the operation.

I've found the selpoints and selpolys entries but I'm unclear on how to use it.

Can someone point me in the right direction?

Thx.

evenflcw
05-12-2011, 08:41 PM
Elements, points and polygons, have an id and could also be said to have an index. As new elements are created they are assigned a unique id and the id is inserted at the end of the points and polygons arrays (see meshedit mode). The index corresponds to the elements/ids position in these arrays. Ie, the arrays and indices are in creation order.

Selpolygon()/selpoint() can select using either id or index.

I think that should be enough to point you in the right direction.

nickdigital
05-13-2011, 08:49 AM
Great! Thanks for steering me in the right direction.

nickdigital
05-16-2011, 10:52 AM
So I've poured over the docs and I feel I'm close. I'm just missing the understanding of the proper syntax.

I have the below:

makebox(lowValue,highValue,segments);
meshedit ("Spherize");

I've done the tutorial where you make points and assign a variable with an array to the points:
point[1] = addpoint (1,1,1);

I assume the makebox command is returning a value. Is it returning points or polys? Or both?

I want to be able to select the geometry of the makebox command so when I run Spherize it just does it on the newly created geometry and not everything that's in the Layer in Modeler.

evenflcw
05-16-2011, 02:31 PM
makebox() does not return anything in particular I think. Seldome do the higher level commands return anything.


main
{
//1.save count before operation
selmode(GLOBAL); //look at all geomerty
polyCount = polycount(); //returns an array of different polycounts
polyCountBefore = polyCount[1]; //this element in the array countains the total polycount. save that for later.

//2.perform operation
makebox(-1, 1, 10);

//3.save count after operation
polyCount = polycount();
polyCountAfter = polyCount[1]; //we sample the polycount again, after operation.
polyCountNew = polyCountAfter - polyCountBefore;

//4.select all points with indices higher than polyCountBefore, because they must've been created in the operation.
//this loop can look many different ways.
//you could also call the selpolygon command multiple times.
//I however prefer to build an array of indices and only call selpolygon once.
for(i=1; i<=polyCountNew; i++) {
indices[i] = i+polyCountBefore;
}
selmode(USER); //switch mode, because you cant select in GLOBAL mode
selpolygon(SET, POLYNDX, indices);

meshedit("Spherize");
}

nickdigital
05-16-2011, 02:56 PM
Oh my. So I wasn't even close, lol.

Thanks for posting the code for me to decipher.

nickdigital
05-16-2011, 03:05 PM
Hm, your code doesn't work as-is.

If I make a box in a layer and then run your lscript my original box gets spherized too.

evenflcw
05-16-2011, 03:12 PM
Was the existing box selected when you ran the script? Just add a selpolygon(CLEAR) before the selpolygon(SET...).

nickdigital
05-16-2011, 03:20 PM
Oh no, I had nothing selected. I'm hoping to make this sequence of commands work the same way as the existing ball, box, etc tools. I just want it to make a quad sphere instead.

evenflcw
05-16-2011, 03:22 PM
I think there might be a LW bug in there. A LW/LScript gui fail if you start out in point mode. The selpolygon command should switch to polygon mode. It doesn't, so Modelers doesn't see the polygon selection. Instead it sees the implicit selection of all points. Not my fault imho.

EDIT1:
Or it rather seems like Modeler (10) can't perform the polygon selection at all if starting in point mode. That surely is a bug!? If you start out in polygon mode it works. Same for you?

EDIT2:
Either way, adding in the selpolygon(CLEAR) forces the switch to polygon mode before the selpolygon(SET...) so all is well there at my end.

nickdigital
05-16-2011, 03:34 PM
This is what I'm seeing. I was originally doing this in 9.6 but I just ran the steps below in 10.0.

Test#1
1. Make a box.
2. Select all the points of the box.
3. Run your script.
4. Another box with a bunch of segments gets made but nothing gets spherized.

Test#2
1. Make a box.
2. Run your script.
3. Everything gets spherized.

Test#3
1. Make a box.
2. Change to polygon mode and select all the polys of the box.
2. Run your script.
3. Everything gets spherized.

Test#4
1. Make a box.
2. Change to polygon mode with nothing selected.
2. Run your script.
3. A new quad sphere is generated with my original box left as-is.

So it looks like Test#4 is the way to go. I don't know enough of lscript enough to know what is a bug and what isn't.

Of course if NewTek just added a Quad Sphere option to the ball tool then we'd be fine. :D

nickdigital
05-16-2011, 04:42 PM
Either way, adding in the selpolygon(CLEAR) forces the switch to polygon mode before the selpolygon(SET...) so all is well there at my end.

Yep, thanks so much for your help!

evenflcw
05-16-2011, 04:56 PM
Yw.