riki
05-18-2003, 09:42 AM
Anyone know what's wrtong with this 'Gears.ls' script by Art Howe. It creates an object with 2 inward facing polys. Has been bugging me for a long time, is it possible to fix. Sorry I'm not a programmer. BTW this is the 'Gears.ls' not 'Gear.ls' that ships with LW. It can be found in the Additional Menu.
I've also noticed that it will cuase Modeler to freeze if you select the 'Smooth' option.
Any suggestions??
-----------------------
// shut off warnings (we'll get one when getempty() is called because it
// returns 10 elements, and our array only has 1)
//
// Updated 06.08.01 Art Howe
@warnings
@version 2.3
@script modeler
@define ANGULAR 1
@define SMOOTH 2
@define XAXIS 1
@define YAXIS 2
@define ZAXIS 3
main
{
teeth = 15;
axis = Z;
rad_inner = .7;
rad_outer = 1.0;
thickness = .5;
geartype = 1;
cntr = <0,0,0>;
x = 1;
// request some parameters
reqbegin("Gear");
c1 = ctlchoice("Axis",axis,@"X","Y","Z"@);
c2 = ctlinteger("Number of Teeth",teeth);
c3 = ctldistance("Inner Radius",rad_inner);
c4 = ctldistance("Outer Radius",rad_outer);
c5 = ctldistance("Thickness",thickness);
c6 = ctlchoice("Gear Type",geartype,@"Angular","Smooth"@);
c7 = ctlvector("Center",cntr);
return if !reqpost();
axis = getvalue(c1);
teeth = getvalue(c2);
rad_inner = getvalue(c3);
rad_outer = getvalue(c4);
thickness = getvalue(c5);
geartype = getvalue(c6);
cntr = getvalue(c7);
cx = cntr.x;
cy = cntr.y;
cz = cntr.z - (thickness / 2);
reqend();
t_ang = 360 / teeth / 57.2957794;
lyrsetfg(1);
editbegin();
moninit(teeth,"Generating gear...");
for(i = 0;i < teeth;i++)
{
a1 = t_ang * i;
a2 = a1 + (t_ang * 3 / 6);
a3 = a1 + (t_ang * 4 / 6);
a4 = a1 + (t_ang * 5 / 6);
pt[1] = (rad_inner * sin(a1) + cx);
pt[2] = (rad_inner * cos(a1) + cy);
pt[3] = cz;
ptID[x] = addpoint(pt);
++x;
pt[1] = (rad_inner * sin(a2) + cx);
pt[2] = (rad_inner * cos(a2) + cy);
pt[3] = cz;
ptID[x] = addpoint(pt);
++x;
pt[1] = (rad_outer * sin(a3) + cx);
pt[2] = (rad_outer * cos(a3) + cy);
pt[3] = cz;
ptID[x] = addpoint(pt);
++x;
pt[1] = (rad_outer * sin(a4) + cx);
pt[2] = (rad_outer * cos(a4) + cy);
pt[3] = cz;
ptID[x] = addpoint(pt);
++x;
if(monstep())
{
editend(ABORT); // any non-zero value will
// will abort the operation
return;
}
}
if(geartype == ANGULAR)
addpolygon(ptID,"Gear");
else // Smooth
addcurve(ptID,"Gear");
editend();
monend();
if(geartype == SMOOTH)
freezecurves();
extrude(Z,thickness);
// punch a hole through the center.
(bglayer) = lyrempty();
// only punch a hole if we can get an empty layer to work in
if(bglayer != nil)
{
lyrsetfg(bglayer);
// Make hole diameter 25% of the gear's radius
makedisc(rad_outer * .25, // radius
-.5, // top
thickness + 1, // bottom
Z, // along the Z axis
32, // 32 sides
1, // 1 segment
<cx,cy,cz>); // center vector
lyrsetfg(1);
lyrsetbg(bglayer);
boolean(SUBTRACT);
lyrsetfg(bglayer);
delete();
lyrsetfg(1);
}
else
info("Need at least one empty layer to punch center hole");
switch(axis)
{
case XAXIS:
rotate(90,Y);
break;
case YAXIS:
rotate(90,X);
break;
}
}
I've also noticed that it will cuase Modeler to freeze if you select the 'Smooth' option.
Any suggestions??
-----------------------
// shut off warnings (we'll get one when getempty() is called because it
// returns 10 elements, and our array only has 1)
//
// Updated 06.08.01 Art Howe
@warnings
@version 2.3
@script modeler
@define ANGULAR 1
@define SMOOTH 2
@define XAXIS 1
@define YAXIS 2
@define ZAXIS 3
main
{
teeth = 15;
axis = Z;
rad_inner = .7;
rad_outer = 1.0;
thickness = .5;
geartype = 1;
cntr = <0,0,0>;
x = 1;
// request some parameters
reqbegin("Gear");
c1 = ctlchoice("Axis",axis,@"X","Y","Z"@);
c2 = ctlinteger("Number of Teeth",teeth);
c3 = ctldistance("Inner Radius",rad_inner);
c4 = ctldistance("Outer Radius",rad_outer);
c5 = ctldistance("Thickness",thickness);
c6 = ctlchoice("Gear Type",geartype,@"Angular","Smooth"@);
c7 = ctlvector("Center",cntr);
return if !reqpost();
axis = getvalue(c1);
teeth = getvalue(c2);
rad_inner = getvalue(c3);
rad_outer = getvalue(c4);
thickness = getvalue(c5);
geartype = getvalue(c6);
cntr = getvalue(c7);
cx = cntr.x;
cy = cntr.y;
cz = cntr.z - (thickness / 2);
reqend();
t_ang = 360 / teeth / 57.2957794;
lyrsetfg(1);
editbegin();
moninit(teeth,"Generating gear...");
for(i = 0;i < teeth;i++)
{
a1 = t_ang * i;
a2 = a1 + (t_ang * 3 / 6);
a3 = a1 + (t_ang * 4 / 6);
a4 = a1 + (t_ang * 5 / 6);
pt[1] = (rad_inner * sin(a1) + cx);
pt[2] = (rad_inner * cos(a1) + cy);
pt[3] = cz;
ptID[x] = addpoint(pt);
++x;
pt[1] = (rad_inner * sin(a2) + cx);
pt[2] = (rad_inner * cos(a2) + cy);
pt[3] = cz;
ptID[x] = addpoint(pt);
++x;
pt[1] = (rad_outer * sin(a3) + cx);
pt[2] = (rad_outer * cos(a3) + cy);
pt[3] = cz;
ptID[x] = addpoint(pt);
++x;
pt[1] = (rad_outer * sin(a4) + cx);
pt[2] = (rad_outer * cos(a4) + cy);
pt[3] = cz;
ptID[x] = addpoint(pt);
++x;
if(monstep())
{
editend(ABORT); // any non-zero value will
// will abort the operation
return;
}
}
if(geartype == ANGULAR)
addpolygon(ptID,"Gear");
else // Smooth
addcurve(ptID,"Gear");
editend();
monend();
if(geartype == SMOOTH)
freezecurves();
extrude(Z,thickness);
// punch a hole through the center.
(bglayer) = lyrempty();
// only punch a hole if we can get an empty layer to work in
if(bglayer != nil)
{
lyrsetfg(bglayer);
// Make hole diameter 25% of the gear's radius
makedisc(rad_outer * .25, // radius
-.5, // top
thickness + 1, // bottom
Z, // along the Z axis
32, // 32 sides
1, // 1 segment
<cx,cy,cz>); // center vector
lyrsetfg(1);
lyrsetbg(bglayer);
boolean(SUBTRACT);
lyrsetfg(bglayer);
delete();
lyrsetfg(1);
}
else
info("Need at least one empty layer to punch center hole");
switch(axis)
{
case XAXIS:
rotate(90,Y);
break;
case YAXIS:
rotate(90,X);
break;
}
}