PDA

View Full Version : need help sel poly



titane357
03-20-2008, 07:18 AM
Hello

I try to make a script to select poly with same orientation :
I don't know if it is the good way
I don't understand the error,
anybody ? Thanks

@version 1.2
@warnings
@script modeler

main
{
reqbegin("YOKO idnormal");
c1 = ctlnumber("Value =",0.5);

if(reqpost()) {
Rvalue=getvalue(c1);
} else {
return;
}
reqend();
mypolys=nil;
index=1;
selmode(USER);
editbegin();
polyCount = polycount();
NNRM = polynormal(polygons[1]);
for(i=1 ; i<=polyCount[1] ; i++)
{
NNRMi = polynormal(polygons[i]);
if( NNRMi = NNRM)
{
mypolys[index] = polygons[i];
index++;
}
}
editend();
selpolygon(CLEAR);
selpolygon(SET,POLYID,mypolys);
}

art
03-20-2008, 07:29 AM
Are you trying to loop through all polygons or only the selected ones?

Also, are you getting this error: "Line 1, found '@', expecting Line @version 1.2"?

art
03-20-2008, 07:50 AM
Also, in this line "if( NNRMi = NNRM)" you probably meant "if( NNRMi == NNRM)".
You should probably allow for some small errors, direct comparison like this will probably not always give the right results. I'm assuming that's why you have the Rvalue. I would suggest measuring the angle between the normals and if it is small enough, assume they are the same. If you plan to loop through all polygons you should probably switch to GLOBAL mode before looping through polygons.

titane357
03-20-2008, 08:21 AM
Thank you very much ! :thumbsup:
Yes : "if( NNRMi == NNRM)". works far better !
In fact I select one poly and after all poly I want to be taken in consideration.
Yes : I'd like to use my Rvalue to have a range of value ( 0.1 to 1 degree )
But I don't know how to mesure between NNRMi and NNRM...:D

art
03-20-2008, 08:33 AM
try this:

//
@version 1.2
@warnings
@script modeler

main
{
reqbegin("YOKO idnormal");
c1 = ctlangle("Max Error=",0.5);

if(reqpost()) {
Rvalue=getvalue(c1);
} else {
return;
}
reqend();
mypolys=nil;

selmode(USER);
editbegin();
NNRM = polynormal(polygons[1]);
editend();
selpolygon(CLEAR);
selmode(GLOBAL);
editbegin();
polyCount = polycount();
for(i=1 ; i<=polyCount[1] ; i++)
{
NNRMi = polynormal(polygons[i]);
angle = deg(acos(dot3d(NNRM,NNRMi)));
if( angle <= Rvalue ) mypolys += polygons[i];
}
editend();
selmode(USER);
selpolygon(CLEAR);
if(mypolys != nil) selpolygon(SET,POLYID,mypolys);

}

titane357
03-20-2008, 08:49 AM
It's alive !
Thaaank you very much ! clear, elegant !
I have some problems with mathematics ! (and lscript)

Thanks you for your other scripts ( lineX's, bezier bridge, align and distribute : are my favorites) :thumbsup:

art
07-02-2008, 10:17 AM
Update:

change the last lines:

selpolygon(CLEAR);
if(mypolys != nil) selpolygon(SET,POLYID,mypolys);

into:

selpolygon(CLEAR);
selpoint(SET);
if(mypolys != nil) selpolygon(SET,POLYID,mypolys);
selpolygon(SET);

to make it work faster.

titane357
07-02-2008, 11:14 AM
??????? argh ! don't work for me.... :cry:

just select all geometry !

art
07-02-2008, 11:18 AM
here is full code. it works for me. I am on LW9.3.1 but i'm not sure if it makes a difference.

//
@version 1.2
@warnings
@script modeler

main
{
reqbegin("YOKO idnormal");
c1 = ctlangle("Max Error=",0.5);

if(reqpost()) {
Rvalue=getvalue(c1);
} else {
return;
}
reqend();
mypolys=nil;

selmode(USER);
editbegin();
NNRM = polynormal(polygons[1]);
editend();
selpolygon(CLEAR);
selmode(GLOBAL);
editbegin();
polyCount = polycount();
for(i=1 ; i<=polyCount[1] ; i++)
{
NNRMi = polynormal(polygons[i]);
angle = deg(acos(dot3d(NNRM,NNRMi)));
if( angle <= Rvalue ) mypolys += polygons[i];
}
editend();
selmode(USER);
selpolygon(CLEAR);
selpoint(SET);
if(mypolys != nil) selpolygon(SET,POLYID,mypolys);
selpolygon(SET);
}

art
07-02-2008, 11:27 AM
you are right. I chose wrong model to set. SET selects all geometry.
Disregard this whole thing :(

titane357
07-02-2008, 11:48 AM
have 9.3.1 too but don't work (boooooooh)

titane357
07-02-2008, 11:49 AM
Thanks for your efforts art ! :D

art
07-02-2008, 01:39 PM
Titane, try this. New tip from Sensei came along:

//
@version 1.2
@warnings
@script modeler

main
{

reqbegin("YOKO idnormal");
c1 = ctlangle("Max Error=",0.5);

if(reqpost()) {
Rvalue=getvalue(c1);
} else {
return;
}
reqend();
mypolys=nil;

selmode(USER);
editbegin();
NNRM = polynormal(polygons[1]);
editend();
selpolygon(CLEAR);
selmode(GLOBAL);
editbegin();
polyCount = polycount();
for(i=1 ; i<=polyCount[1] ; i++)
{
NNRMi = polynormal(polygons[i]);
angle = deg(acos(dot3d(NNRM,NNRMi)));
if( angle <= Rvalue ) mypolys += polygons[i];
}
editend();
selmode(USER);
selpolygon(CLEAR);
selpoint(CLEAR);
if(mypolys != nil) selpolygon(SET,POLYID,mypolys);
selpolygon(SET,NVEQ,0);
}

titane357
07-02-2008, 01:54 PM
HI ! yes it works but I don't notice any speed up (tested on a cube 7 times subdivided) 14s25 for old and new lscript. :boogiedow

art
07-02-2008, 02:05 PM
try it on a cube with 50 segments on each axis. In the old version I see the polygons being slowly selected. In the updated version they are selected in one shot. Or test it on a geometry where many polygons get selected as the result of running this script.

titane357
07-02-2008, 02:36 PM
yes, selection is "different" but overall take same amount of time. :(

art
07-02-2008, 02:47 PM
strange, i see significant differnce in time it takes for the two scripts to finish on the test cube (50 segments on each axis, 15k polys total). If I select one of the polygons from one side of the cube, all polygons on that side (2500 of them) get selected, but the time difference is:

old script: approx. 6 sec.

new script: approx. 1 sec

most of the time of the old script is spent on actually selecting the 2500 polygons in the last section of the script (selpolygon)