I knew I had it somewhere...
If this code snippet can be of any use, anyone is free to use it.
Notes:
The main() is just an example on how to call the makepart() function.
The groove option does not work.
There really should be an outputfilename variable, instead of preset to
"E:\makepart.dat".
#include <stdlib.h>
#include <stdio.h>
// MakePart v 1.00
void makepart( int c, int w,int h,int d, int studs, int groove);
main()
{
int w,h,d;
int c=16;
int studs=-1;//0=Tile
int groove=0;
w=1; h=8; d=1;
clrscr();
makepart(c,5,4,3,1,0);
}
void makepart( int c, int w,int h,int d, int studs, int groove)
{
char s[32], typ[16];
FILE *ut;
ut=fopen("e:\\makepart.dat", "wt");
if(d>w)
{
int tmp;
tmp=w;
w=d;
d=tmp;
}
strcpy(typ,"Brick");
strcpy(s,"");
if(h<8)
strcpy(typ,"Baseplate");
if(h>7 && h<13)
strcpy(typ,"Plate");
if(h!=4 && h!=8 && h%24!=0)
sprintf(s," %2d LDU high",h);
if(h>24 && h%24==0)
sprintf(s," x %2d",h/24);
if(groove!=0)
strcat(s," with Groove");
if(studs==0)
{
if(h>7 && h<13)
strcpy(typ,"Tile");
else
strcat(s," without Studs");
}
fprintf(ut,"0 %s %2d x %2d%s\n", typ,d,w,s);
fprintf(ut,"0 Name: %s\n", "foo.dat");
fprintf(ut,"0 Author: %s\n", "John Smith");
fprintf(ut,"0 Unofficial Part\n");
fprintf(ut,"0 Created by MakePart\n");
fprintf(ut,"\n0 BFC CERTIFY CCW\n");
if(d==1 && h>4) //Type 3 bottom studs
{
int x;
for (x=w*-10+20;x<w*10-19;x+=20)
fprintf(ut,"\n1 %d %d 4 0 1 0 0 0 %g 0 0 0 1 stud3.dat",
c,x,(4-(float)h)/4);
}
if(d>1 && h>4) //Type 4 bottom studs
{
int x,z;
for (z=d*10-20; z>d*-10+19; z-=20)
for (x=w*-10+20; x<w*10-19; x+=20)
fprintf(ut,"\n1 %d %d 4 %d 1 0 0 0 %g 0 0 0 1 stud4.dat",
c,x,z,(4-(float)h)/4);
}
if(h>7) // if not a Baseplate...
{
int x0,x1,z0,z1;
fprintf(ut,"\n0 BFC INVERTNEXT");
fprintf(ut,"\n1 %d 0 %d 0 %d 0 0 0 %d 0 0 0 %d box5.dat",
c,h,w*10-4,4-h,d*10-4);
x1=w*10;
x0=0-x1;
z1=d*10;
z0=0-z1;
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d ",
c,x1,h,z1,x1-4,h,z1-4,x0+4,h,z1-4,x0,h,z1);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d ",
c,x0,h,z1,x0+4,h,z1-4,x0+4,h,z0+4,x0,h,z0);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d ",
c,x0,h,z0,x0+4,h,z0+4,x1-4,h,z0+4,x1,h,z0);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d ",
c,x1,h,z0,x1-4,h,z0+4,x1-4,h,z1-4,x1,h,z1);
fprintf(ut,"\n1 %d 0 %d 0 %d 0 0 0 %d 0 0 0 %d box5.dat",
c,h,w*10,0-h,d*10);
}
else // if Baseplate...
{
int x0,x1,z0,z1;
int x10,x11,y,z10,z11;
x1=w*10;
x0=0-x1;
x11=x1-4;
x10=0-x11;
z1=d*10;
z0=0-z1;
z11=z1-4;
z10=0-z11;
fprintf(ut,"\n1 %d %d %d %d 4 0 0 0 1 0 0 0 4 1-4edge.dat",
c,x11,4,z11);
fprintf(ut,"\n2 24 %d %d %d %d %d %d", x1,h,z11,x1,h,z10);
fprintf(ut,"\n1 %d %d %d %d 4 0 0 0 1 0 0 0 -4 1-4edge.dat",
c,x11,4,z10);
fprintf(ut,"\n2 24 %d %d %d %d %d %d", x11,h,z0,x10,h,z0);
fprintf(ut,"\n1 %d %d %d %d -4 0 0 0 1 0 0 0 -4 1-4edge.dat",
c,x10,4,z10);
fprintf(ut,"\n2 24 %d %d %d %d %d %d", x0,h,z10,x0,h,z11);
fprintf(ut,"\n1 %d %d %d %d -4 0 0 0 1 0 0 0 4 1-4edge.dat",
c,x10,4,z11);
fprintf(ut,"\n2 24 %d %d %d %d %d %d", x10,h,z1,x11,h,z1);
fprintf(ut,"\n1 %d %d %d %d 4 0 0 0 1 0 0 0 4 1-4edge.dat",
c,x11,0,z11);
fprintf(ut,"\n2 24 %d %d %d %d %d %d", x1,0,z11,x1,0,z10);
fprintf(ut,"\n1 %d %d %d %d 4 0 0 0 1 0 0 0 -4 1-4edge.dat",
c,x11,0,z10);
fprintf(ut,"\n2 24 %d %d %d %d %d %d", x11,0,z0,x10,0,z0);
fprintf(ut,"\n1 %d %d %d %d -4 0 0 0 1 0 0 0 -4 1-4edge.dat",
c,x10,0,z10);
fprintf(ut,"\n2 24 %d %d %d %d %d %d", x0,0,z10,x0,0,z11);
fprintf(ut,"\n1 %d %d %d %d -4 0 0 0 1 0 0 0 4 1-4edge.dat",
c,x10,0,z11);
fprintf(ut,"\n2 24 %d %d %d %d %d %d", x10,0,z1,x11,0,z1);
y=h;
fprintf(ut,"\n1 %d %d %d %d 4 0 0 0 -1 0 0 0 4 1-4disc.dat",
c,x11,y,z11);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x1,y,z11,x1,y,z10,x11,y,z10,x11,y,z11);
fprintf(ut,"\n1 %d %d %d %d 4 0 0 0 -1 0 0 0 -4 1-4disc.dat",
c,x11,y,z10);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x11,y,z0,x10,y,z0,x10,y,z10,x11,y,z10);
fprintf(ut,"\n1 %d %d %d %d -4 0 0 0 -1 0 0 0 -4 1-4disc.dat",
c,x10,y,z10);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x0,y,z10,x0,y,z11,x10,y,z11,x10,y,z10);
fprintf(ut,"\n1 %d %d %d %d -4 0 0 0 -1 0 0 0 4 1-4disc.dat",
c,x10,y,z11);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x10,y,z1,x11,y,z1,x11,y,z11,x10,y,z11);
y=0;
fprintf(ut,"\n1 %d %d %d %d 4 0 0 0 1 0 0 0 4 1-4disc.dat",
c,x11,y,z11);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x1,y,z10,x1,y,z11,x11,y,z11,x11,y,z10);
fprintf(ut,"\n1 %d %d %d %d 4 0 0 0 1 0 0 0 -4 1-4disc.dat",
c,x11,y,z10);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x10,y,z0,x11,y,z0,x11,y,z10,x10,y,z10);
fprintf(ut,"\n1 %d %d %d %d -4 0 0 0 1 0 0 0 -4 1-4disc.dat",
c,x10,y,z10);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x0,y,z11,x0,y,z10,x10,y,z10,x10,y,z11);
fprintf(ut,"\n1 %d %d %d %d -4 0 0 0 1 0 0 0 4 1-4disc.dat",
c,x10,y,z11);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x11,y,z1,x10,y,z1,x10,y,z11,x11,y,z11);
fprintf(ut,"\n1 %d %d 0 %d 4 0 0 0 %d 0 0 0 4 1-4cyli.dat",
c,x11,z11,h);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x1,0,z11,x1,0,z10,x1,h,z10,x1,h,z11);
fprintf(ut,"\n1 %d %d 0 %d 4 0 0 0 %d 0 0 0 -4 1-4cyli.dat",
c,x11,z10,h);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x11,0,z0,x10,0,z0,x10,h,z0,x11,h,z0);
fprintf(ut,"\n1 %d %d 0 %d -4 0 0 0 %d 0 0 0 -4 1-4cyli.dat",
c,x10,z10,h);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x0,0,z10,x0,0,z11,x0,h,z11,x0,h,z10);
fprintf(ut,"\n1 %d %d 0 %d -4 0 0 0 %d 0 0 0 4 1-4cyli.dat",
c,x10,z11,h);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x10,0,z1,x11,0,z1,x11,h,z1,x10,h,z1);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x10,0,z10,x11,0,z10,x11,0,z11,x10,0,z11);
fprintf(ut,"\n4 %d %d %d %d %d %d %d %d %d %d %d %d %d",
c,x10,h,z11,x11,h,z11,x11,h,z10,x10,h,z10);
}
if(studs!=0) // if not a Tile...
{
int x,z;
x=333;
for(z=d*10-10;z>d*-10+9;z-=20)
for (x=w*-10+10; x<w*10-9; x+=20)
fprintf(ut,"\n1 %d %d 0 %d 1 0 0 0 1 0 0 0 1 stud.dat",
c,x,z);
}
fprintf(ut,"\n0");
fclose(ut);
getch();
}
|