PDA

View Full Version : DSelect Works but Problem



riki
10-19-2003, 08:50 AM
Anyone idea's what's wrong with this script. It works if you run it externally, but if you load and map it to a button it gives the following error message.

"Line 30, unable to locate function reference addcontrol"



----------------- Here's the script


// Choose polygons by their direction. By James G. Jones ([email protected])
// 5/3/96, 7/31/97, 8/21/00

@script modeler

main
{
var Vt; // temporary vector
var polyInfo[6]; // for results of polycount()
var axis = 1; // recall("axis",1); // saved values from requester
var name = "New"; // recall("name","New");
var rename = 2; // recall("rename", 1); // make new surface, or not
var buttons[6]; // buttons strings for requester
buttons[1] = "+X";
buttons[2] = "-X";
buttons[3] = "+Y";
buttons[4] = "-Y";
buttons[5] = "+Z";
buttons[6] = "-Z";
var renamebuttons[2];
renamebuttons[1] = "New Surface";
renamebuttons[2] = "Select Only";
var c1, c2, c3; // to hold control handle returned by addcontrol()
var i; // for loops

// Put up the requester...
reqbegin("Directional Select");

c1 = ctlchoice("Direction:", axis, buttons);
c3 = ctlchoice("Options:", rename, renamebuttons);
c2 = ctlstring("New Surface Name:",name);

if(reqpost())
{
axis = getvalue(c1); // see what the user input
name = getvalue(c2);
rename = getvalue(c3);
// store("axis",axis); // keep values for subsequent runs...
// store("name",name);
// store("rename",rename);
}
else return;

reqend();

selmode(USER); // for rest of script

selpolygon(CLEAR,NVGT,0); // clear any existing selection

editbegin();
polyInfo = polycount();
switch(axis)
{
case 1: // +X axis
for(i=1; i<polyInfo[1]+1; i++) // scan each polygon
{
Vt = polynormal(polygons[i]); // get normal vector
if(Vt.x >= abs(Vt.y) && Vt.x >= abs(Vt.z)) polysurface(polygons[i],name);
}
break;
case 2: // -X axis
for(i=1; i<polyInfo[1]+1; i++) // scan each polygon
{
Vt = polynormal(polygons[i]); // get normal vector
if(Vt.x <= -abs(Vt.y) && Vt.x <= -abs(Vt.z)) polysurface(polygons[i],name);
}
break;
case 3: // +Y axis
for(i=1; i<polyInfo[1]+1; i++) // scan each polygon
{
Vt = polynormal(polygons[i]); // get normal vector
if(Vt.y >= abs(Vt.x) && Vt.y >= abs(Vt.z)) polysurface(polygons[i],name);
}
break;
case 4: // -Y axis
for(i=1; i<polyInfo[1]+1; i++) // scan each polygon
{
Vt = polynormal(polygons[i]); // get normal vector
if(Vt.y <= -abs(Vt.x) && Vt.y <= -abs(Vt.z)) polysurface(polygons[i],name);
}
break;
case 5: // +Z axis
for(i=1; i<polyInfo[1]+1; i++) // scan each polygon
{
Vt = polynormal(polygons[i]); // get normal vector
if(Vt.z >= abs(Vt.x) && Vt.z >= abs(Vt.y)) polysurface(polygons[i],name);
}
break;
case 6: // -Z axis
for(i=1; i<polyInfo[1]+1; i++) // scan each polygon
{
Vt = polynormal(polygons[i]); // get normal vector
if(Vt.z <= -abs(Vt.x) && Vt.z <= -abs(Vt.y)) polysurface(polygons[i],name);
}
break;
}
editend();

// info("Name = ", name);
selpolygon(SET, SURFACE, name);
if(rename != 1) undo(); // 1 = new surface name, 2 = select only.
}

bloontz
10-19-2003, 11:49 AM
I've tried to add that script as a plugin and it fails with a can't find plugin error when I select it from the additional menu. It usually works when loaded as a .ls manually but fails on some objects. I use it on a pc. Not sure what's up.

fxnut
10-19-2003, 02:32 PM
Like Bloontz, I couldn't add the *.ls file directly, so I compiled it into an *.lsc file, added it as a button on to the interface, and it works fine - no errors at all.

What your experiencing sounds like some sort of wierd LScript internal error though - as if it's unable to create the ctlchoice control. You might want to try changing that line to use a drop down list (or maybe just remove that part of the interface altogether). That at least might give you a few clues as to what's going wrong.

riki
10-19-2003, 06:26 PM
Thanks for that, I'll try compiling first, might be easier than editing the code.

bloontz
10-19-2003, 07:36 PM
Compiling worked for me, thanks. I also found out why some objects caused the script to fail, they had some two point polys. After deleting those the script worked fine.