discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: start a module from a variabel

RW
Ray West
Mon, Oct 25, 2021 8:49 PM

This is what i was suggesting,  You should be able to copy both the
library file and the construction file - make sure you adjust the
library location in the includes to your library location, of course.

A library file named nema_lib.scad  say  (with explanatory comments)


//nema fix plate library

/* notes

sc= shaft clearance
pd =pilot diameter
pl = pilot length
bd= bolt diameter
s= bolt fixings square

nema series is in inches, these metric values may have errors, nema17
should have unc thread in motor plate
depending on manufacturer. Best to check motor and adjust values as
required.
*/

module nema_plate(sc,pd,pl,bd,s){
      p=s/2;
    translate([0,0,-pl])cylinder(h=pl2,d=pd,true); //to pl2 to stop z
fighting
    // fix holes
    translate([p,p,-50])cylinder(h=100,d=bd,true);
    translate([p,-p,-50])cylinder(h=100,d=bd,true);
    translate([-p,p,-50])cylinder(h=100,d=bd,true);
    translate([-p,-p,-50])cylinder(h=100,d=bd,true);
    translate([0,0,-50])cylinder (h=100,d=sc,true);
    echo("bolt holes diameter =",bd);
}

module nema23_fix( ){
   echo("Nema23");
  nema_plate(
    sc=7,
    pd=38.1,
    pl=1.5748,
    bd=5,
    s=47.1424 );
  }

module nema17_fix( ){
   echo("Nema17");
    nema_plate(
    sc=5.5,
    pd=22,
    pl=2.26,
    bd=4.4,
    s=30.988 );
}

module nema34_fix( ){
  echo("Nema34");
  nema_plate(
    sc=10,
    pd=73.025,
    pl=1.5748,
    bd=5.6,
    s=69.596);
 }

 module nema42_fix( ){
   echo("Nema42");
     nema_plate(
       sc=18,
       pd=55.5244,
       pl=1.5748,
       bd=7.5,
       s=88.9 );
 }

   // nema34_fix();

a construction file which uses the library file


//test for making and positioning nema motor mounting plate

    // plates depend not only on motor, but on whatever is supporting
it- it may not be square
    // so they should be kept as a separate parts

    // locate and make a nema34 mounting plate
    // say centre of plate at 120,120,top at 100, and 120 mm square and
plate is always 10mm thick
   // or maybe it could be 8mm... just change t

     // 10mm fixing holes 10 mm in from two opposite corners
     // in practice, the plates would be drawn as 2d, for 3 axis
milling, but 3d is ok for a ga.

    t=10;// plate thickness

    module nema34_plate(){
include<C:/users/Ray/Desktop/openscad/nema_lib.scad> ;
        difference(){
            translate ([0,0,-t/2])
            cube([120,120,t],true);
                   nema34_fix();
    }
    }

    translate([120,120,100])
    //fixing holes
    difference(){
         nema34_plate();
             translate ([50,50,-20]) cylinder(h=50, d=10);
            translate ([-50,-50,-20]) cylinder(h=50, d=10);
    }

    // and say a nema 23, vertical, plate at y =-10, // xz axis same
thickness, 80mm square

    module nema23_plate(){
include<C:/users/Ray/Desktop/openscad/nema_lib.scad> ;
        difference(){
           translate ([0,0,-t/2])
            cube([80,80,t],true);
                        bd=666;  //just to show no name conflicts
                       s=222222; // likewise
               nema23_fix();
    }
    }

    translate([40,-10,40])
       rotate([90,0,0])
       nema23_plate();

    // and so on and so forth.
    // For this example, one library include would do outside of the
modules, but
    // if the nemaxx_fix modules were different e.g. decided to move
the plate dimensions into there, then
    //would need the separate modules as here.
    // there are no conflicts of variable names with those in the library

    sc=500; // no conflict
    bd ="hi there"; // no conflict

    // what starts in a module, stays in a module


Best wishes,

Ray

This is what i was suggesting,  You should be able to copy both the library file and the construction file - make sure you adjust the library location in the includes to your library location, of course. A library file named nema_lib.scad  say  (with explanatory comments) ------------------------------ //nema fix plate library /* notes sc= shaft clearance pd =pilot diameter pl = pilot length bd= bolt diameter s= bolt fixings square nema series is in inches, these metric values may have errors, nema17 should have unc thread in motor plate depending on manufacturer. Best to check motor and adjust values as required. */ module nema_plate(sc,pd,pl,bd,s){       p=s/2;     translate([0,0,-pl])cylinder(h=pl*2,d=pd,true); //to pl*2 to stop z fighting     // fix holes     translate([p,p,-50])cylinder(h=100,d=bd,true);     translate([p,-p,-50])cylinder(h=100,d=bd,true);     translate([-p,p,-50])cylinder(h=100,d=bd,true);     translate([-p,-p,-50])cylinder(h=100,d=bd,true);     translate([0,0,-50])cylinder (h=100,d=sc,true);     echo("bolt holes diameter =",bd); } module nema23_fix( ){    echo("Nema23");   nema_plate(     sc=7,     pd=38.1,     pl=1.5748,     bd=5,     s=47.1424 );   } module nema17_fix( ){    echo("Nema17");     nema_plate(     sc=5.5,     pd=22,     pl=2.26,     bd=4.4,     s=30.988 ); } module nema34_fix( ){   echo("Nema34");   nema_plate(     sc=10,     pd=73.025,     pl=1.5748,     bd=5.6,     s=69.596);  }  module nema42_fix( ){    echo("Nema42");      nema_plate(        sc=18,        pd=55.5244,        pl=1.5748,        bd=7.5,        s=88.9 );  }    // nema34_fix(); ----------------------------------------------------- a construction file which uses the library file ---------------------------------------------------------- //test for making and positioning nema motor mounting plate     // plates depend not only on motor, but on whatever is supporting it- it may not be square     // so they should be kept as a separate parts     // locate and make a nema34 mounting plate     // say centre of plate at 120,120,top at 100, and 120 mm square and plate is always 10mm thick    // or maybe it could be 8mm... just change t      // 10mm fixing holes 10 mm in from two opposite corners      // in practice, the plates would be drawn as 2d, for 3 axis milling, but 3d is ok for a ga.     t=10;// plate thickness     module nema34_plate(){ include<C:/users/Ray/Desktop/openscad/nema_lib.scad> ;         difference(){             translate ([0,0,-t/2])             cube([120,120,t],true);                    nema34_fix();     }     }     translate([120,120,100])     //fixing holes     difference(){          nema34_plate();              translate ([50,50,-20]) cylinder(h=50, d=10);             translate ([-50,-50,-20]) cylinder(h=50, d=10);     }     // and say a nema 23, vertical, plate at y =-10, // xz axis same thickness, 80mm square     module nema23_plate(){ include<C:/users/Ray/Desktop/openscad/nema_lib.scad> ;         difference(){            translate ([0,0,-t/2])             cube([80,80,t],true);                         bd=666;  //just to show no name conflicts                        s=222222; // likewise                nema23_fix();     }     }     translate([40,-10,40])        rotate([90,0,0])        nema23_plate();     // and so on and so forth.     // For this example, one library include would do outside of the modules, but     // if the nemaxx_fix modules were different e.g. decided to move the plate dimensions into there, then     //would need the separate modules as here.     // there are no conflicts of variable names with those in the library     sc=500; // no conflict     bd ="hi there"; // no conflict     // what starts in a module, stays in a module ----------------------------------------------------- Best wishes, Ray