AngelScript CSG

Talk about using software tools, drivers etc

AngelScript CSG

Postby cacb » 2016-Jan-Wed-17-Jan

Sometimes, I write software and have recently been playing with what could be described as a preprocessor to OpenSCAD, I call it AngelScript CSG, see http://arnholm.org/angelscript-csg-part-2/

OpenSCAD is really great but sometimes I find the language a bit limiting, and I really wanted something that runs and allows me to change variables and do more expressive stuff. Some time ago, I found AngelScript http://www.angelcode.com/angelscript/ and I figured I could add CSG (Constructive Solid geometry) functionality to that general language.

Right now, you write some code in AngelScript CSG and "compile" it on the command line into an OpenSCAD .csg file and use OpenSCAD to create an STL. This is how it is now, it could change as I am experimenting. Today I designed an electronics box for a friend, using AngelScript CSG, and printed it with my Simple Metal:

box.png


IMG_0847.jpg


Seems to work. I will probably do some more in this area.
  • 0

You do not have the required permissions to view the files attached to this post.
Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

AngelScript CSG

Sponsor

Sponsor
 

Re: AngelScript CSG

Postby Mooselake » 2016-Jan-Wed-19-Jan

A couple years back there was a sort of similar openSCAD preprocessor, but I can't remember it's name or find it with google. Among other things it was (going to be) good for rounded and chamfered edges. Guess it died out, but does anybody remember it or what it was called?

Kirk
  • 0

Modified KickStarter Classic Plus 7/2012
KS Thingybot Delta Pro 10/31/16
User avatar
Mooselake
My next printer is...
 
Posts: 3565
Joined: 2011-Dec-Tue-23-Dec
Location: Moose Swamp, Upper Michigan, USA
Reputation: 171

Re: AngelScript CSG

Postby cacb » 2016-Jan-Thu-01-Jan

Mooselake wrote:A couple years back there was a sort of similar openSCAD preprocessor, but I can't remember it's name or find it with google. Among other things it was (going to be) good for rounded and chamfered edges. Guess it died out, but does anybody remember it or what it was called?


I am not sure what that might be. I have seen references to half-similar approaches, but usually with a different focus than what I am looking at (the language used). My idea is to express models in a script, much like OpenSCAD, but using a more sophisticated and expressive language. I also want it to execute like a normal language, not "just" declare a static model.

Angelscript is a general purpose language using syntax similar to C/C++ and that opens up a lot of possibilities that I find attractive. It becomes easier to express more complex shapes, and build things on top of the usual primitives.

The fact that what I have now works like a preprocessor to OpenSCAD is not a design goal, it is just a practical intermediate step to try out things and see them printed. I am going to look at a couple of other approaches also, we shall see how it turns out.
  • 0

Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

Re: AngelScript CSG

Postby cacb » 2016-Jan-Mon-14-Jan

I have been doing some more work on this. It is now much easier to use with the new GUI editor/IDE that allows script writing, simple debugging and more:
http://arnholm.org/angelscript-csg-ide/
  • 0

Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

Re: AngelScript CSG

Postby Mooselake » 2016-Jan-Mon-16-Jan

I ignored the Windows 10 "We're all gonna die if you install this" :) error (click on more info, then run anyway), and seem to have survived. W10 Pro 64b insider preview 11102.rs1.

You posted this at the perfect time. I need to design a diamond shaped part to hold a couple screws with nut traps for my never-ending adjustable laser cutter table, followed by a stand for MT2 lathe accessories (think solid box with tapered holes in the top). We'll see how fast old moose pick up new programming things.

Kirk
  • 0

Modified KickStarter Classic Plus 7/2012
KS Thingybot Delta Pro 10/31/16
User avatar
Mooselake
My next printer is...
 
Posts: 3565
Joined: 2011-Dec-Tue-23-Dec
Location: Moose Swamp, Upper Michigan, USA
Reputation: 171

Re: AngelScript CSG

Postby cacb » 2016-Jan-Mon-16-Jan

Mooselake wrote:I ignored the Windows 10 "We're all gonna die if you install this" :) error (click on more info, then run anyway), and seem to have survived. W10 Pro 64b insider preview 11102.rs1.

Well, if you run Windows 10 all bets are off, that is one giant surveillance system. My software is clean as a baby, no virus or anything. Check in virustotal.com or similar services if you still have doubts.

Mooselake wrote:You posted this at the perfect time. I need to design a diamond shaped part to hold a couple screws with nut traps for my never-ending adjustable laser cutter table, followed by a stand for MT2 lathe accessories (think solid box with tapered holes in the top). We'll see how fast old moose pick up new programming things.

Kirk


Well then you have some motivation to try. It is similar to OpenSCAD in some ways, but the language is more powerful. And it runs instead of just declare. Try the samples first to get a feel for it, then make your part.
  • 0

Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

Re: AngelScript CSG

Postby Mooselake » 2016-Jan-Mon-17-Jan

This might be the base part, minus the holes and nut traps. It should be a diamond 3mm thick, 30mm wide, and 60mm high.

edit: and it is! slic3ed and printing now, want to test fit on the laser before I go any further.

Code: Select all
// AngelScript CSG example code. See samples for more and use Help (Shift+F1).

const double pi = 4.0*atan(1.0);
double to_rad(double deg) { return pi*deg/180.0; } // from degrees to radians
 
shape@ main_shape()
{
   // Example code follows. This is where your model is built.
   // Use your own helper functions if required.
   // TODO: Remove or edit the lines below to do what you want.

   // start with a square, then rotate 45 degrees and scale to make a diamond
   //   probably not the easiest way..
   
   double height       = 3;
   double width        = 60;
   double length       = 30;
   double ratio        = length/width; // used to convert square to diamond
   
   // Notice the use of '@', indicating the variable is a reference.
   // All 2d,3d objects + transformations require using '@' as shown.

   solid@ sqplate   = cuboid(width, width, height);   // start with a square
 
   solid@ diamond   = rotate_z(to_rad(45))*sqplate;
   shape@ dplate    = scale(0.707*ratio, 0.707, 1)*diamond;
 
   
    return dplate;
}

void main()
{  // main() receives the finished model and exports it.
   shape@ obj = main_shape();
   obj.write_csg(GetOutputFullPath('.csg')); // OpenSCAD .csg file, ref. www.openscad.org
}


I pretty much just fumbled around to get it. I don't understand the difference between a shape and a solid, for example.

Next I'll try to put some holes in 15mm from the top and bottom, with 6 sided circles (how do I do cylinder(h,r,$fn=6)?) to drop the nuts in. Not sure I'll get adventurous enough to round off the corners, something to save for next time.

KIrk
  • 0

Modified KickStarter Classic Plus 7/2012
KS Thingybot Delta Pro 10/31/16
User avatar
Mooselake
My next printer is...
 
Posts: 3565
Joined: 2011-Dec-Tue-23-Dec
Location: Moose Swamp, Upper Michigan, USA
Reputation: 171

Re: AngelScript CSG

Postby Mooselake » 2016-Jan-Mon-17-Jan

cacb wrote:Well, if you run Windows 10 all bets are off, that is one giant surveillance system.

I've got nothing to hide.

Wait, who's that stomping up the stairs?

Please, sir, don't shoot me. Just let me send this first and I'll go peaceably. I promise I'll be good, please don't lock me in that dungeon with a Mac and dialup modem.
  • 0

Modified KickStarter Classic Plus 7/2012
KS Thingybot Delta Pro 10/31/16
User avatar
Mooselake
My next printer is...
 
Posts: 3565
Joined: 2011-Dec-Tue-23-Dec
Location: Moose Swamp, Upper Michigan, USA
Reputation: 171

Re: AngelScript CSG

Postby Mooselake » 2016-Jan-Mon-18-Jan

Looks good (well, needs a few more top layers at 120mm/s), need to make it a little bigger because the corner screws don't align with the steel mesh at the same place, but that's my problem and not AngelScript's.

Kirk
  • 0

You do not have the required permissions to view the files attached to this post.
Modified KickStarter Classic Plus 7/2012
KS Thingybot Delta Pro 10/31/16
User avatar
Mooselake
My next printer is...
 
Posts: 3565
Joined: 2011-Dec-Tue-23-Dec
Location: Moose Swamp, Upper Michigan, USA
Reputation: 171

Re: AngelScript CSG

Postby cacb » 2016-Jan-Mon-18-Jan

It is an inheritance tree :-) Go to Shift+F1 open the "class list" and find "shape" to see the tree.

Anything is a shape, both 2d and 3d objects. Any 2d shape (circle, polygon....) is a "shape2d" and any 3d object (cone, cube, ...) is a "solid", they are all "shape"s. You can hold an abstract handle like this
Code: Select all
solid@ obj = cube(5);  // OK, because a cube is a solid
solid@ obj2 = circle(5);  // ERROR, a circle is not a solid
shape2d@ obj3 = circle(5);  // OK, a circle is a shape2d
double h = 10;
double r = 2;
cylinder@ cyl = cylinder(h,r);  // OK, a cylinder is a cylinder :-)


The OpenSCAD "trick" with $fn=6 is not supported.... I would model a hexagonal nut by first creating a cuboid with dx equal to the width of the flat side, and dy equal to the distance to the opposite side, and dz as nut thickness. Then rotate 2 of them by 60 and -60 degrees. Here is a quick example making something resembling a nut (then make this a reusable function to put in a library):

Code: Select all
const double pi = 4.0*atan(1.0);
double to_rad(double deg) { return pi*deg/180.0; } // from degrees to radians
 
shape@ main_shape()
{
   // the nut is essentially 3 cuboids rotated 60 degrees
   double dx = 5;
   double dy = 9;
   double dz = 5;
   solid@ c1 = cuboid(dx,dy,dz,true);
   solid@ c2 = rotate_z(to_rad(60))*c1;
   solid@ c3 = rotate_z(to_rad(-60))*c1;

   // let them become one piece
   solid@ hex = union3d(c1,c2,c3);

   // drill a hole (no threads)
   solid@ hex_with_hole = difference3d(hex,cylinder(20,3,true));

   // make rounded edges on the outside
   return intersection3d(hex_with_hole,cylinder(20,5,true));
}

void main()
{  // main() receives the finished model and exports it.
   shape@ obj = main_shape();
   obj.write_csg(GetOutputFullPath('.csg'));
}
  • 0

You do not have the required permissions to view the files attached to this post.
Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

Re: AngelScript CSG

Postby cacb » 2016-Jan-Mon-18-Jan

Mooselake wrote:Looks good (well, needs a few more top layers at 120mm/s), need to make it a little bigger because the corner screws don't align with the steel mesh at the same place, but that's my problem and not AngelScript's.

Kirk


Not sure what I am looking at there, but it is nice to see you trying!
  • 0

Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

Re: AngelScript CSG

Postby Mooselake » 2016-Jan-Mon-18-Jan

Thanks!

I won't be able to get back to it until Wednesday afternoon or Thursday, have to work from late tomorrow morning until 6am Wednesday. We have a bridge that's undergoing maintenance every night this week and need an extra ambulance crew to cover the service area south of it - it's the only way across. I didn't look at my caller ID quick enough...

Not very good at explaining that "almost retired" doesn't mean "unlimited free time, call for everything".

Kirk
  • 0

Modified KickStarter Classic Plus 7/2012
KS Thingybot Delta Pro 10/31/16
User avatar
Mooselake
My next printer is...
 
Posts: 3565
Joined: 2011-Dec-Tue-23-Dec
Location: Moose Swamp, Upper Michigan, USA
Reputation: 171

Re: AngelScript CSG

Postby cacb » 2016-Jan-Tue-09-Jan

Mooselake wrote:Thanks!


You're welcome!

Before you return, I had some fun designing a small library for metric hex nuts, with optional rounded corners. These have no holes or threads so they could be used as heads on screws or for countersinking.

Simple example using the library
Code: Select all
// AngelScript CSG example code.
#include "lib_metric_hex_nut.as"
 
shape@ main_shape()
{
   return metric_hex_nut('M5');
}

void main()
{
   shape@ obj = main_shape();
   obj.write_csg(GetOutputFullPath('.csg'));
}


The result is
metric_hex_nut_M5.png


A slightly more involved example:
Code: Select all
// AngelScript CSG example code.
#include "lib_metric_hex_nut.as"
 
shape@ main_shape()
{
   // array of metric nut names
   string[] names = {'M2','M3','M4','M5','M6','M8','M10','M12','M14','M16','M20','M24'};

   // generate array of nuts
   solid@[] nuts;
   for(uint i=0; i<names.size(); i++) {
      nuts.push_back( translate(i*(i+2)*2,0,0)*metric_hex_nut(names[i]));
   }

   // make a union so we can see them all
   return union3d(nuts);
}

void main()

   shape@ obj = main_shape();
   obj.write_csg(GetOutputFullPath('.csg'));
}


which produces
metric_hex_nuts_all.png
  • 0

You do not have the required permissions to view the files attached to this post.
Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

Re: AngelScript CSG

Postby Mooselake » 2016-Feb-Mon-14-Feb

I found another issue, at least for me. I'm making a cabinet for my lathe tools, and need to make a tool holder for it's MT1 tooling. It needs a morse taper cylindrical hole (well, a several of them once I build a working first . OpenSCAD lets you specify a top and bottom radius, but I can only find a single radius without a taper, or a cone. In this case it's a tapered cylinder with a specified length (shortened so the tool will stick out and make it easier to grab underneath and lift out), and top and bottom radius. Plus I've also got lathes with MT2 and MT3 head and tailstocks, and plan to make them in multiple sizes.

I know I could always make a straight hole, but then I could just drill them in a piece of maple. What fun is that?

Kirk

For your entertainment, here's the current work in progress:

Code: Select all
// AngelScript CSG MT holder
//  holder for morse taper lathe tools
//  Mooselake 8 Feb 2016, another product of the Mooselake Development Labs
//   no warranty, rights, etc expressed or implied.  Good Luck!

// I have several lathes, wood and metal, with assorted morse taper head and tail stocks,
//   and need somewere to store all the assorted gadgets that go in them.  This is it!

const double pi = 4.0*atan(1.0);
double to_rad(double deg) { return pi*deg/180.0; } // from degrees to radians

string mt = "MT1";  // MT1, MT2, MT3 currently

double NumX = 1; //3;    // how many holes across
double NumY = 1; //2;    //  and how many left to right
double stickOut = 10; // shorten taper for finger room under tool
double toolSpace = 3; // space between tools
double toolRadius = 25/2; // radius of tool

 
shape@ main_shape()
{
   // Example code follows. This is where your model is built.
   // Use your own helper functions if required.
   // TODO: Remove or edit the lines below to do what you want.


   // determine tool hole dimensions required, from the
   //   Little Machine Shop reference page
   double largeEnd, smallEnd, Length;

   if ( mt == "MT1") then
      {
      largeEnd = 0.4750*25.4;
      smallEnd = 0.3690*25.4;
      length   = 2.13*25.4;
      }
   elseif ( mt == "MT2") then
      {
      largeEnd = 0.7000*25.4;
      smallEnd = 0.9380*25.4;
      length   = 2.56*25.4;
      }
   elseif ( mt == "MT3") then
      {
      largeEnd = 0.9380*25.4;
      smallEnd = 0.7780*25.4;
      length   = 3.19*25.4;
      }
   else
      {
      //error message here
      exit;
      }
   double depth       = length - stickOut; // depth of tool hole
   double height      = depth + 3;         // height of box
   double width       = (toolSpace+toolRadius)*2.*NumX;
   double length      = (toolSpace+toolRadius)*2.*NumY;

   //  this is a test, only one hole so no iteration

   solid@ box = cuboid(width, length, height);
   
   // remove hole for tool shaft
   
   solid@ box = difference() {box, ??? }
   
 /*  // Notice the use of '@', indicating the variable is a reference.
   // All 2d,3d objects + transformations require using '@' as shown.

   solid@ sqplate   = cuboid(width, width, height);   // start with a square
 
   solid@ diamond   = rotate_z(to_rad(45))*sqplate;   // rotate into a diamond
   solid@ dplate    = scale(sqrt(2)/2*ratio, sqrt(2)/2, 1)*diamond;  // and scale to fit
   solid@ bigtrap   = cylinder(
 
   shape@ nplate   = dplate;
   return nplate; */
}

void main()
{  // main() receives the finished model and exports it.
   shape@ obj = main_shape();
   obj.write_csg(GetOutputFullPath('.csg')); // OpenSCAD .csg file, ref. www.openscad.org
}
  • 0

Modified KickStarter Classic Plus 7/2012
KS Thingybot Delta Pro 10/31/16
User avatar
Mooselake
My next printer is...
 
Posts: 3565
Joined: 2011-Dec-Tue-23-Dec
Location: Moose Swamp, Upper Michigan, USA
Reputation: 171

Re: AngelScript CSG

Postby cacb » 2016-Feb-Mon-15-Feb

In OpenSCAD a cone is called a "cylinder", in AngelScript CSG a cone is called a cone. So if you need a tapered hole, make a cone.

Code: Select all
double h=50, r1=10,r2=5;
cone@ c = cone(h,r1,r2);


You have some of the syntax wrong. Generally, the AngelScript syntax follows C/C++ syntax very closely. I will check it and get back.
  • 0

Last edited by cacb on 2016-Feb-Mon-15-Feb, edited 1 time in total.
Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

Re: AngelScript CSG

Postby cacb » 2016-Feb-Mon-15-Feb

This is a version of your code that runs, although it probably does not do what you want yet. Notice the changes!

Code: Select all
// AngelScript CSG MT holder
//  holder for morse taper lathe tools
//  Mooselake 8 Feb 2016, another product of the Mooselake Development Labs
//   no warranty, rights, etc expressed or implied.  Good Luck!
// corrections by cacb, 8 feb 2016
//  - if syntax fixed
//  - Length and length are distinct (case sensitive) variables
//  - added iostream style error message
//  - defined a tapered hole using a cone
//  - used difference3d to subtract the hole
//  - returned the box from the main_shape function

// I have several lathes, wood and metal, with assorted morse taper head and tail stocks,
//   and need somewere to store all the assorted gadgets that go in them.  This is it!

const double pi = 4.0*atan(1.0);
double to_rad(double deg) { return pi*deg/180.0; } // from degrees to radians

string mt = "MT1";  // MT1, MT2, MT3 currently

double NumX = 1; //3;    // how many holes across
double NumY = 1; //2;    //  and how many left to right
double stickOut = 10; // shorten taper for finger room under tool
double toolSpace = 3; // space between tools
double toolRadius = 25/2; // radius of tool


shape@ main_shape()
{
   // determine tool hole dimensions required, from the
   //   Little Machine Shop reference page
   double length=0.0,largeEnd=0.0, smallEnd=0.0;

   if ( mt == "MT1") {
      largeEnd = 0.4750*25.4;
      smallEnd = 0.3690*25.4;
      length   = 2.13*25.4;
   }
   else if ( mt == "MT2") {
      largeEnd = 0.7000*25.4;
      smallEnd = 0.9380*25.4;
      length   = 2.56*25.4;
   }
   else if ( mt == "MT3") {
      largeEnd = 0.9380*25.4;
      smallEnd = 0.7780*25.4;
      length   = 3.19*25.4;
   }
   else  {
      //error message here
      cout << " asERR: Wrong value for 'mt': "<< mt << endl();
      return null; // returning null will cause exception
    }
   double depth       = length - stickOut; // depth of tool hole
   double height      = depth + 3;         // height of box
   double width       = (toolSpace+toolRadius)*2.*NumX;
// double length      = (toolSpace+toolRadius)*2.*NumY;

   //  this is a test, only one hole so no iteration
   solid@ box = cuboid(width, length, height);
 
   // remove hole for tool shaft
   double r1=largeEnd/2,r2=smallEnd/2;
   cone@  hole = cone(height*2,r1,r2);

   // the box variable is reused and becomes a box with a hole, note the syntax       
   @box = difference3d(box,translate(width/2,length/2,-height/2)*hole );

   return box;
}

void main()
{  // main() receives the finished model and exports it.
 shape@ obj = main_shape();
 obj.write_csg(GetOutputFullPath('.csg')); // OpenSCAD .csg file, ref. www.openscad.org
}


btw. if you want to work in inches instead of mm, you could define something like this

Code: Select all
double inches(double inch) { return inch*25.4; }


and later use it as

Code: Select all
double largeEnd = inches(0.4750);
  • 0

Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

Re: AngelScript CSG

Postby Mooselake » 2016-Feb-Mon-17-Feb

Thanks! inches(n) does look cooler than n*25.4, should have caught that on.

Cone is in your list in part-2 with only one argument, didn't know you took variable length argument lists. If that works the same way as cylinder then it's exactly what I need.

The LP gas truck got stuck in the driveway, helped dig them out but I need to go out and plow off the chewed up mess. Worst part is my tank is 70% and with the wood heat it won't move much while the outdoor boiler is trying to burn up half the north woods. Not real efficient... I'll make the changes as soon as I make it back in.

Dang snow, just keeps coming, although this years 110" is a lot less than this time last year.

Kirk
  • 0

Modified KickStarter Classic Plus 7/2012
KS Thingybot Delta Pro 10/31/16
User avatar
Mooselake
My next printer is...
 
Posts: 3565
Joined: 2011-Dec-Tue-23-Dec
Location: Moose Swamp, Upper Michigan, USA
Reputation: 171

Re: AngelScript CSG

Postby cacb » 2016-Feb-Mon-17-Feb

Mooselake wrote:Thanks! inches(n) does look cooler than n*25.4, should have caught that on.

Cone is in your list in part-2 with only one argument, didn't know you took variable length argument lists. If that works the same way as cylinder then it's exactly what I need.


It does not take variable length argument lists, it was a bug I thought didn't make it into the release. Just to be sure you have the very latest I uploaded version V2.0-01 to this page, with up-to-date docs as well. Make sure you exit the editor when upgrading. The correct thing to do is run uninstall, then install the new one.

Cone does indeed take 1 height + 2 radius arguments.
  • 0

Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

Re: AngelScript CSG

Postby Mooselake » 2016-Feb-Sat-13-Feb

I might have broken it. When trying to compile this script I get a message
Code: Select all
C:\Program Files (x86)\AngelScript_CSG\as_csg.exe E:\Downloads\3D Files\MT Tool holder\MT-Toolholder.as
as_csg V2.0-01


but nothing else, including any reported errors. My previous script compiles as before and renders in OpenSCAD. I uninstalled and reinstalled without any change.

Kirk

Code: Select all
// AngelScript CSG MT holder
//  holder for morse taper lathe tools
//  Mooselake 8 Feb 2016, another product of the Mooselake Development Labs
//   no warranty, rights, etc expressed or implied.  Good Luck!

// I have several lathes, wood and metal, with assorted morse taper head and tail stocks,
//   and need somewere to store all the assorted gadgets that go in them.  This is it!

const double pi = 4.0*atan(1.0);
double inches(double inch) { return inch*25.4; }
double to_rad(double deg) { return pi*deg/180.0; } // from degrees to radians

string mt = "MT1";  // MT1, MT2, MT3 currently

double NumX = 1; //3;    // how many holes across
double NumY = 1; //2;    //  and how many left to right
double stickOut = 10; // shorten taper for finger room under tool
double toolSpace = 3; // space between tools
double toolRadius = 25/2; // radius of tool

 
shape@ main_shape()
{
   // Example code follows. This is where your model is built.
   // Use your own helper functions if required.
   // TODO: Remove or edit the lines below to do what you want.


   // determine tool hole dimensions required, from the
   //   Little Machine Shop reference page
   double largeEnd, smallEnd, Length;

   if ( mt == "MT1") then
      {
      largeEnd = inches(0.4750);
      smallEnd = inches(0.3690);
      length   = inches(2.13);
      }
   elseif ( mt == "MT2") then
      {
      largeEnd = inches(0.7000);
      smallEnd = inches(0.9380);
      length   = inches(2.56);
      }
   elseif ( mt == "MT3") then
      {
      largeEnd = inches(0.9380);
      smallEnd = inches(0.7780);
      length   = inches(3.19);
      }
   else
      {
      cout << " asERR: Wrong value for 'mt': "<< mt << endl();
      return null; // returning null will cause exception
 
      }
   double depth       = length - stickOut; // depth of tool hole
   double height      = depth + 3;         // height of box
   double width       = (toolSpace+toolRadius)*2.*NumX;
   double length      = (toolSpace+toolRadius)*2.*NumY;

   //  this is a test, only one hole so no iteration
 
   // remove hole for tool shaft
   
   solid@ box = difference() {cuboid(width, length, height),
      translate(width/2, height/2, depth-height) cone(depth, largeEnd, smallEnd)
      }
   
   shape@ nbox   = box;
   return nbox;
}

void main()
{  // main() receives the finished model and exports it.
   shape@ obj = main_shape();
   obj.write_csg(GetOutputFullPath('.csg')); // OpenSCAD .csg file, ref. www.openscad.org
}
  • 0

Modified KickStarter Classic Plus 7/2012
KS Thingybot Delta Pro 10/31/16
User avatar
Mooselake
My next printer is...
 
Posts: 3565
Joined: 2011-Dec-Tue-23-Dec
Location: Moose Swamp, Upper Michigan, USA
Reputation: 171

Re: AngelScript CSG

Postby cacb » 2016-Feb-Sat-14-Feb

Mooselake wrote:I might have broken it. When trying to compile this script I get a message
Code: Select all
C:\Program Files (x86)\AngelScript_CSG\as_csg.exe E:\Downloads\3D Files\MT Tool holder\MT-Toolholder.as
as_csg V2.0-01


but nothing else, including any reported errors. My previous script compiles as before and renders in OpenSCAD. I uninstalled and reinstalled without any change.

Kirk


You found a bug. It does not like folder names with spaces in it. A work-around is to replace those spaces with underscores:
E:\Downloads\3D_Files\MT_Tool_holder\MT-Toolholder.as

Then it will work. I will have to fix that bug...

You still have the wrong language syntax for the if statements, see my 2016-02-08 21:02:28 post for corrected syntax :P

---
UPDATE: I have fixed the problem with the spaces in version V2.0-02, available here.
  • 0

Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

Re: AngelScript CSG

Postby Mooselake » 2016-Feb-Sat-14-Feb

My OO programming skills have gotten a bit rusty, probably been about 12 years since my last C++ and java projects :(

Fixed another couple errors, too. Other than I'm not sure of the taper (can't see it well enough in the preview) this should be good enough for a test. I have a couple hour print going, but as soon as that's done I'll see if the drive center fits in the hole.

Really like how fast this Core i5 laptop compiles. Not like the olden days when it took several hours to compile and print a few thousand lines of assembly code on the Motorola Exorterm.

Thanks!

Kirk
Code: Select all
// AngelScript CSG MT holder
//  holder for morse taper lathe tools
//  Mooselake 8 Feb 2016, another product of the Mooselake Development Labs
//   no warranty, rights, etc expressed or implied.  Good Luck!

// I have several lathes, wood and metal, with assorted morse taper head and tail stocks,
//   and need somewere to store all the assorted gadgets that go in them.  This is it!

const double pi = 4.0*atan(1.0);
double inches(double inch) { return inch*25.4; }
double to_rad(double deg) { return pi*deg/180.0; } // from degrees to radians

string mt = "MT1";  // MT1, MT2, MT3 currently

double NumX = 1; //3;    // how many holes across
double NumY = 1; //2;    //  and how many left to right
double stickOut = 10; // shorten taper for finger room under tool
double toolSpace = 3; // space between tools
double toolRadius = 25/2; // radius of tool

 
shape@ main_shape()
{
   // Example code follows. This is where your model is built.
   // Use your own helper functions if required.
   // TODO: Remove or edit the lines below to do what you want.


   // determine tool hole dimensions required, from the
   //   Little Machine Shop reference page

   double largeEnd, smallEnd, TaperLength;

   if ( mt == "MT1")
      {
      largeEnd = inches(0.4750);
      smallEnd = inches(0.3690);
      TaperLength   = inches(2.13);
      }
   else if ( mt == "MT2")
      {
      largeEnd = inches(0.7000);
      smallEnd = inches(0.9380);
      TaperLength   = inches(2.56);
      }
   else if ( mt == "MT3")
      {
      largeEnd = inches(0.9380);
      smallEnd = inches(0.7780);
      TaperLength   = inches(3.19);
      }
   else
      {
      cout << " asERR: Wrong value for 'mt': "<< mt << endl();
      return null; // returning null will cause exception
 
      }
   double depth       = TaperLength - stickOut; // depth of tool hole
   double height      = depth + 3;         // height of box
   double width       = (toolSpace+toolRadius)*2.*NumX;
   double length      = (toolSpace+toolRadius)*2.*NumY;

   //  this is a test, only one hole so no iteration

   solid@ box = cuboid(width, length, height);

   // hole for tool shaft

   cone@ hole = cone(depth, smallEnd, largeEnd);
   
   @box = difference3d(
      box,
      translate(width/2, length/2, 3)*hole
      );
   
   shape@ nbox   = box;
   return nbox;
}

void main()
{  // main() receives the finished model and exports it.
   shape@ obj = main_shape();
   obj.write_csg(GetOutputFullPath('.csg')); // OpenSCAD .csg file, ref. www.openscad.org
}
  • 0

Last edited by Mooselake on 2016-Feb-Sat-17-Feb, edited 2 times in total.
Reason: swap arguments to cone
Modified KickStarter Classic Plus 7/2012
KS Thingybot Delta Pro 10/31/16
User avatar
Mooselake
My next printer is...
 
Posts: 3565
Joined: 2011-Dec-Tue-23-Dec
Location: Moose Swamp, Upper Michigan, USA
Reputation: 171

Re: AngelScript CSG

Postby cacb » 2016-Feb-Sat-15-Feb

Two things: I just found that there is a similar bug with spaces when starting OpenSCAD from within AngelScript CSG IDE, I will have to fix that as well. I generally recommend not to use spaces in paths.

Your model compiles, but the top of the hole is flush with the top of the box, that isn't good practice. The "hole part" should extend outside the box to make a a clean hole entrance, otherwise you might end up with a bad STL. This is just how booleans work.

Suggested fix to your script, observe how the hole is cleaner in OpenSCAD after the fix:
Code: Select all
       cone@ hole = cone(depth+1, largeEnd, smallEnd);


i.e. just extended the hole 1mm to let it extend beyond the top of the box.
  • 0

Printrbot Simple Metal Kit + heated bed upgrade. KISSlicer (Kubuntu/Win7), OctoPrint (wireless Raspberry Pi model B) - http://arnholm.org/
cacb
Support material...
 
Posts: 403
Joined: 2015-Mar-Sun-06-Mar
Location: Norway
Reputation: 17

Re: AngelScript CSG

Postby Mooselake » 2016-Feb-Sat-17-Feb

Sound of hoof smacking forehead. I knew that.

I made the taper the proper length and let the hole extend above the box. The way I had it before the taper was too short so the angle would have been off. Not that it was critical, but might as well do it right.

I had an extruder jam about an hour and a half into the two and a half hour print (my first with the AMU hot end). Disassembled the extruder, burned out the nozzle and heated the barrel enough to remove the jammed filament. For good luck I took a string and some polishing compound and worked on the inside for a while. Edited the gcode and restarted the print. There's a bump where it jammed, but it should file out. Fingers crossed...

Thanks again!

Kirk
  • 0

Modified KickStarter Classic Plus 7/2012
KS Thingybot Delta Pro 10/31/16
User avatar
Mooselake
My next printer is...
 
Posts: 3565
Joined: 2011-Dec-Tue-23-Dec
Location: Moose Swamp, Upper Michigan, USA
Reputation: 171


Return to Software usage talk

Who is online

Users browsing this forum: No registered users and 2 guests