PDA

View Full Version : Generalized "every other loop" script



jeric_synergy
08-12-2016, 01:27 AM
from the "accordion pipe" thread:

It strikes me that the procedure for selecting every other segment of any extruded tube would probably not be too difficult to script. If you limit yourself to tubes, it could even sense the necessary parameters itself. That is, selecting ONE loop gives it the numbers it would need to complete the task.

The psuedo-code is:


How many polys selected by user (any loop on the geometry in question)=np
SELECT Nth PATTERN (np), OFFSET 1
Assign to PART 1
CLEAR
SELECT Nth PATTERN (np), OFFSET 2
Assign to PART 2
SELECT (ADD) PART 1
ASSIGN SURFACE(TEMP)
CLEAR
SELECT SURFACE(TEMP)
SELECT LOOP

For a tube, this selects every other segment --it might be interesting to see what would happen on other geometries. Like, say, trees.

Is "selecting every other loop" a generalized task that might be of interest??? :caffeine:

daforum
08-12-2016, 01:57 AM
Thanks for sharing :thumbsup:

So, with your script to work just select the first loop then run the script?
Will this run in all modes - point, edge or poly?

Every4thPixel
08-12-2016, 02:25 AM
Thanks for sharing :thumbsup:

So, with your script to work just select the first loop then run the script?
Will this run in all modes - point, edge or poly?

That's not a script. It just his idea how this should work. ;)

Every4thPixel
08-12-2016, 03:02 AM
I cooked one up for you.

Download the file or grab it from down here:

I realized you probably want to add it to the selection instead of jumping to the next other? Right?

@version 2.8
@warnings
@name "TVM_SelectEveryOtherLoop"
@script modeler

main
{

cmdseq("Sel Polys");
selmode(USER);
cmdseq("Select Loop");

nxt = true;
for(i = 0; i <= 2; i++){

if(nxt){
nxt = false;
cmdseq("Sel Next Loop");
}
else{
nxt = true;
}
}
}

Every4thPixel
08-12-2016, 03:57 AM
Here's one that adds every other loop to the selection. One issue I have is figuring out when to stop looking for loops which mean if you have a tube for example and you start looping in the middle there is a 50 50 chance the last loop will also be selected.
Anyone knows how to detect warning thrown by other scripts?

@version 2.8
@warnings
@name "TVM_AddSelEOLoop"
@script modeler

main
{

debug();
cmdseq("Sel Polys");
selmode(USER);
cmdseq("Select Loop");
polc = polycount();
nxt = true;

editbegin();
currentLoop = polygons;
editend();

selpolygon(CONNECT);
totalPolc = polycount();
loops = totalPolc[1]/polc[1];
str = loops;
loopsRND = integer(str);

selpolygon(SET,POLYID,currentLoop);

for(i = 1; i <= loopsRND+1; i++){

//currentPolys[i] = currentLoop;

if(nxt){
nxt = false;
cmdseq("Sel Next Loop");
if(i == (loopsRND+-1)){
selpolygon(CLEAR);
break;
}
}
else{
nxt = true;
cmdseq("Sel Next Loop");
editbegin();
temp = polygons;
editend();
selpolygon(SET,POLYID,currentLoop);
editbegin();
currentLoop = polygons;
editend();

selpolygon(CLEAR);
selpolygon(SET,POLYID,temp);
}
}

selpolygon(SET,POLYID,currentLoop);
}

Every4thPixel
08-12-2016, 05:43 AM
Update.........
Still not working solid... need to make a switch in loop search direction



@version 2.8
@warnings
@name "TVM_AddSelEOLoop"
@script modeler

main
{
cmdseq("Sel Polys");
selmode(USER);
cmdseq("Select Loop");
polc = polycount();
nxt = true;
editbegin();
currentLoop = polygons;
editend();
selpolygon(CONNECT);
totalPolc = polycount();
loops = totalPolc[1]/polc[1];
str = loops;
loopsRND = integer(str);

selpolygon(SET,POLYID,currentLoop);

for(i = 1; i <= loopsRND+1; i++){

if(nxt){
editbegin();
temp = polygons;
editend();

nxt = false;
cmdseq("Sel Next Loop");
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
selpolygon(CLEAR);
break;
}
}
}
else{
editbegin();
temp = polygons;
editend();

nxt = true;
cmdseq("Sel Next Loop");
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
selpolygon(CLEAR);
break;
}
}
//currentPolys[i] = currentLoop; // other way of storing selections
editbegin();
temp = polygons;
editend();
selpolygon(SET,POLYID,currentLoop);
editbegin();
currentLoop = polygons;
editend();
selpolygon(CLEAR);
selpolygon(SET,POLYID,temp);
}
}
selpolygon(SET,POLYID,currentLoop);
}

Every4thPixel
08-12-2016, 06:17 AM
Update... Now it works in both ways.



@version 2.8
@warnings
@name "TVM_AddSelEOLoop"
@script modeler

main
{
debug();
cmdseq("Sel Polys");
selmode(USER);
cmdseq("Select Loop");
polc = polycount();
nxt = true;
inverted = false;
editbegin();
currentLoop = polygons;
editend();
selpolygon(CONNECT);
totalPolc = polycount();
loops = totalPolc[1]/polc[1];
str = loops;
loopsRND = integer(str);

selpolygon(SET,POLYID,currentLoop);

for(i = 1; i <= loopsRND+1; i++){

if(nxt){
editbegin();
temp = polygons;
editend();

nxt = false;

if(inverted == false){
cmdseq("Sel Next Loop");
} else{
cmdseq("Sel Prev Loop");
}
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
if(i < 3){
inverted = true;
selpolygon(CLEAR);
selpolygon(SET,POLYID,currentLoop);
inverted = false;
compareLoop = nil;
temp = nil;
} else
{
selpolygon(CLEAR);
break;
}
}
}
}
else{
editbegin();
temp = polygons;
editend();

nxt = true;

if(inverted == false){
cmdseq("Sel Next Loop");
} else{
cmdseq("Sel Prev Loop");
}
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
if(i < 3){
inverted = true;
selpolygon(CLEAR);
selpolygon(SET,POLYID,currentLoop);
compareLoop = nil;
temp = nil;
} else
{
selpolygon(CLEAR);
break;
}
}
}
//currentPolys[i] = currentLoop; // other way of storing selections
editbegin();
temp = polygons;
editend();
selpolygon(SET,POLYID,currentLoop);
editbegin();
currentLoop = polygons;
editend();
selpolygon(CLEAR);
selpolygon(SET,POLYID,temp);
}
}
selpolygon(SET,POLYID,currentLoop);
}

prometheus
08-12-2016, 07:27 AM
Every4thPixel
Every4thPixel is online now

Canīt you post that as attached script or txt file?
I tried to copy and paste it, but doesnīt work to install ..if it has something with line formatting I donīt know? it becomes a mess when pasting to a text file though.
Note..I did only test those two others ..not the first which seem to be better formatted.

prometheus
08-12-2016, 07:31 AM
yep the first script works that you pasted directly..but the others must have some issues when you paste them in the field like that..??

Every4thPixel
08-12-2016, 07:31 AM
I made two versions. One that selects the "Next loop" and one that selects the "Previous loop". If it you start at the beginning of a pipe it will automatically detect the correct direction.

Download the rar or copy paste the code down here:

NextLoop:


@version 2.8
@warnings
@name "ASEONextLoop"
@script modeler

main
{
cmdseq("Sel Polys");
selmode(USER);
cmdseq("Select Loop");
polc = polycount();
nxt = true;
inverted = false;
editbegin();
currentLoop = polygons;
editend();
selpolygon(CONNECT);
totalPolc = polycount();
loops = totalPolc[1]/polc[1];
str = loops;
loopsRND = integer(str);

selpolygon(SET,POLYID,currentLoop);

for(i = 1; i <= loopsRND+1; i++){

if(nxt){
editbegin();
temp = polygons;
editend();

nxt = false;

if(inverted == false){
cmdseq("Sel Next Loop");
} else{
cmdseq("Sel Prev Loop");
}
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
if(i < 3){
inverted = true;
selpolygon(CLEAR);
selpolygon(SET,POLYID,currentLoop);
inverted = false;
compareLoop = nil;
temp = nil;
} else
{
selpolygon(CLEAR);
break;
}
}
}
}
else{
editbegin();
temp = polygons;
editend();

nxt = true;

if(inverted == false){
cmdseq("Sel Next Loop");
} else{
cmdseq("Sel Prev Loop");
}
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
if(i < 3){
inverted = true;
selpolygon(CLEAR);
selpolygon(SET,POLYID,currentLoop);
compareLoop = nil;
temp = nil;
} else
{
selpolygon(CLEAR);
break;
}
}
}
//currentPolys[i] = currentLoop; // other way of storing selections
editbegin();
temp = polygons;
editend();
selpolygon(SET,POLYID,currentLoop);
editbegin();
currentLoop = polygons;
editend();
selpolygon(CLEAR);
selpolygon(SET,POLYID,temp);
}
}
selpolygon(SET,POLYID,currentLoop);
}



Previous loop:


@version 2.8
@warnings
@name "ASEOPrevLoop"
@script modeler

main
{
cmdseq("Sel Polys");
selmode(USER);
cmdseq("Select Loop");
polc = polycount();
nxt = true;
inverted = false;
editbegin();
currentLoop = polygons;
editend();
selpolygon(CONNECT);
totalPolc = polycount();
loops = totalPolc[1]/polc[1];
str = loops;
loopsRND = integer(str);

selpolygon(SET,POLYID,currentLoop);

for(i = 1; i <= loopsRND+1; i++){

if(nxt){
editbegin();
temp = polygons;
editend();

nxt = false;

if(inverted == false){
cmdseq("Sel Prev Loop");
} else{
cmdseq("Sel Next Loop");
}
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
if(i < 3){
inverted = true;
selpolygon(CLEAR);
selpolygon(SET,POLYID,currentLoop);
inverted = false;
compareLoop = nil;
temp = nil;
} else
{
selpolygon(CLEAR);
break;
}
}
}
}
else{
editbegin();
temp = polygons;
editend();

nxt = true;

if(inverted == false){
cmdseq("Sel Prev Loop");
} else{
cmdseq("Sel Next Loop");
}
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
if(i < 3){
inverted = true;
selpolygon(CLEAR);
selpolygon(SET,POLYID,currentLoop);
compareLoop = nil;
temp = nil;
} else
{
selpolygon(CLEAR);
break;
}
}
}
//currentPolys[i] = currentLoop; // other way of storing selections
editbegin();
temp = polygons;
editend();
selpolygon(SET,POLYID,currentLoop);
editbegin();
currentLoop = polygons;
editend();
selpolygon(CLEAR);
selpolygon(SET,POLYID,temp);
}
}
selpolygon(SET,POLYID,currentLoop);
}




Cheers !!

Every4thPixel
08-12-2016, 07:39 AM
yep the first script works that you pasted directly..but the others must have some issues when you paste them in the field like that..??

Please let me know if these new ones work.
I installed the files in the .rar file so they have to be correct. The formatting seem a bit broken when I paste it here on the forums. In my editor the indenting seems correct. Don't know why?

prometheus
08-12-2016, 08:44 AM
Please let me know if these new ones work.
I installed the files in the .rar file so they have to be correct. The formatting seem a bit broken when I paste it here on the forums. In my editor the indenting seems correct. Don't know why?

Can not load plugin...fails, at least win32, lw 11.6.2
havenīt tested on 2015

Every4thPixel
08-12-2016, 09:04 AM
Did you try the files from the rar file?

If you are copy pasting make sure you start copying here @version 2.8 and end at the last }

I just tried copying from the forums and it still works here.

Where are you pasting it in? Maybe you can try the LScript Editor that comes with LW or notepad. Don't use wordpad or word something.

What is the error you are getting?

prometheus
08-12-2016, 09:46 AM
Did you try the files from the rar file?

If you are copy pasting make sure you start copying here @version 2.8 and end at the last }

I just tried copying from the forums and it still works here.

Where are you pasting it in? Maybe you can try the LScript Editor that comes with LW or notepad. Don't use wordpad or word something.

What is the error you are getting?

yes..the last rar file, so that wasnīt pasted....install of plugin worked, but I got an error when running the plugin..saying it canīt load plugin...again, on win32, lw 11.62.
not sure if lw 2015 and 64 bit is needed here?

Nope...previously I also just used txt.notepad not word.
will take a look at the code later perhaps, and also through lscript editor, may try it in 2015 as well etc...but itīs olympics now, so it has to wait for a while :)

jeric_synergy
08-12-2016, 09:59 AM
Thanks for sharing :thumbsup:

So, with your script to work just select the first loop then run the script?
Will this run in all modes - point, edge or poly?

Well, that's just an IDEA, "psuedo-code", not a real script.

As described, this would only work (which it does not, I stress) in poly mode because of the selection mechanism.

+++++++++++

Holy crap! Every4rthPixel, you are a MACHINE!!! Thanks for all your work! :bowdown:

:thumbsup:

Every4thPixel
08-12-2016, 10:20 AM
Haha Thanks! ;D

I fixed a little mistake I made. Here is a new version.
There seems a problem with the native "select next loop" and "select previous loop" code. Sometimes I doesn't want to skip to the next loop, this is when the mesh has manually created polys. I'm not really sure how to fix that or even what the exact problem is.

Here's the copy paste code:



@version 2.8
@warnings
@name "ASEONextLoop"
@script modeler

main
{
undogroupbegin();
cmdseq("Sel Polys");
selmode(USER);
cmdseq("Select Loop");
polc = polycount();
nxt = true;
inverted = false;
editbegin();
currentLoop = polygons;
editend();
selpolygon(CONNECT);
totalPolc = polycount();
loops = totalPolc[1]/polc[1];
str = loops;
loopsRND = integer(str);

selpolygon(SET,POLYID,currentLoop);

for(i = 1; i <= loopsRND+1; i++){

if(nxt){
editbegin();
temp = polygons;
editend();

nxt = false;

if(inverted == false){
cmdseq("Sel Next Loop");
} else{
cmdseq("Sel Prev Loop");
}
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
if(i < 3){
inverted = true;
nxt = true;
selpolygon(CLEAR);
selpolygon(SET,POLYID,currentLoop);
compareLoop = nil;
temp = nil;
} else
{
selpolygon(CLEAR);
break;
}
}
}
}
else{
editbegin();
temp = polygons;
editend();

nxt = true;

if(inverted == false){
cmdseq("Sel Next Loop");
} else{
cmdseq("Sel Prev Loop");
}
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
if(i < 3){
inverted = true;
selpolygon(CLEAR);
selpolygon(SET,POLYID,currentLoop);
compareLoop = nil;
temp = nil;
} else
{
selpolygon(CLEAR);
break;
}
}
}
//currentPolys[i] = currentLoop; // other way of storing selections
editbegin();
temp = polygons;
editend();
selpolygon(SET,POLYID,currentLoop);
editbegin();
currentLoop = polygons;
editend();
selpolygon(CLEAR);
selpolygon(SET,POLYID,temp);
}
}
selpolygon(SET,POLYID,currentLoop);
undogroupend();
}






@version 2.8
@warnings
@name "ASEOPrevLoop"
@script modeler

main
{
undogroupbegin();
cmdseq("Sel Polys");
selmode(USER);
cmdseq("Select Loop");
polc = polycount();
nxt = true;
inverted = false;
editbegin();
currentLoop = polygons;
editend();
selpolygon(CONNECT);
totalPolc = polycount();
loops = totalPolc[1]/polc[1];
str = loops;
loopsRND = integer(str);

selpolygon(SET,POLYID,currentLoop);

for(i = 1; i <= loopsRND+1; i++){

if(nxt){
editbegin();
temp = polygons;
editend();

nxt = false;

if(inverted == false){
cmdseq("Sel Prev Loop");
} else{
cmdseq("Sel Next Loop");
}
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
if(i < 3){
inverted = true;
nxt = true;
selpolygon(CLEAR);
selpolygon(SET,POLYID,currentLoop);
compareLoop = nil;
temp = nil;
} else
{
selpolygon(CLEAR);
break;
}
}
}
}
else{
editbegin();
temp = polygons;
editend();

nxt = true;

if(inverted == false){
cmdseq("Sel Prev Loop");
} else{
cmdseq("Sel Next Loop");
}
// check if loop is still moving, if not break
editbegin();
compareLoop = polygons;
editend();
//if(i == (loopsRND+-1)){
if(temp != nil){
if(compareLoop[1] == temp[1]){
if(i < 3){
inverted = true;
selpolygon(CLEAR);
selpolygon(SET,POLYID,currentLoop);
compareLoop = nil;
temp = nil;
} else
{
selpolygon(CLEAR);
break;
}
}
}
//currentPolys[i] = currentLoop; // other way of storing selections
editbegin();
temp = polygons;
editend();
selpolygon(SET,POLYID,currentLoop);
editbegin();
currentLoop = polygons;
editend();
selpolygon(CLEAR);
selpolygon(SET,POLYID,temp);
}
}
selpolygon(SET,POLYID,currentLoop);
undogroupend();
}

jeric_synergy
08-12-2016, 10:59 AM
If "manually created", do they need POINT MERGEing?

++++++++++

DAMN that's fun to play with!!! Thanks so much, E4P!

+++
re: jumping to the next loop: there's already a native function for that.

+++++++++
Play time in LWM: :D :thumbsup:
134006

jeric_synergy
08-12-2016, 01:13 PM
E4P, I appreciate the functionality of "Next/Prev", but wonder if a simple 'both ways' version would be hard to produce?

Every4thPixel
08-13-2016, 07:21 AM
E4P, I appreciate the functionality of "Next/Prev", but wonder if a simple 'both ways' version would be hard to produce?

This does work both ways. I only made two different versions to add the ability to start half way a tube because there's no way of knowing what direction is the preferred direction.
So currently it doesn't matter (if you start at the end of beginning of a tube) which plugin you run.