3D part design#159: Export OpenSCAD code directly to a .step file with PythonSCAD

3D part design#159: Export OpenSCAD code directly to a .step file with PythonSCAD

In the last few posts I was using FreeCAD to convert a .3mf or .stl file that I had exported from the IC customizer code to a .step file, and while this works well there is a "native" way to make a .step file with straight OpenSCAD code via PythonSCAD.

This awesome piece of software allows you to use either the standard OpenSCAD syntax or PythonSCAD syntax which opens up a whole new world of possibilities, one of which is .step file export directly from your existing OpenSCAD code.

I am using the latest AppImage version on Linux Mint 22.1 Cinnamon:

Downloads - PythonSCAD

Here is a .step file I made with the OpenSCAD IC generator code that I imported into PythonSCAD and then loaded it and added colors to it with FreeCAD as a test:

To try it out just copy and paste the code into Python scad and select Openscad in the selector that is in the lower right hand corner:

Note: You will need to delete the auto generated python import code in the first line to run your existing OpenSCAD code:

// 

//Dual Inline Package IC customizer Version 4 by InfinityPlays.com//
//License- Public Domain

/*[Scale for Output to Kicad]*/
Scale_all=1;//[.001:.001:1]

/*[Main Body]*/
Number_of_pins=8;//[4:2:28]
Pin_length=3;//[1:.01:5]
show_notch=false;
Notch_adjust=.1;//[-4:.01:4]

/*[Text]*/
Input_text="U1";
Font_name="";
text_size=2;//[.1:.1:3]
Move_text_X=0;//[-12:.01:12]
Move_text_Y=0;//[-2:.01:2]
Text_rotate=90;//[-180:.01:180]

/*[SVG Logo]*/
Show_logo=false;
Path_to_SVG_file="";
Scale_logo=1;//[.001:.001:1]
Move_logoX=0;//[-10:.01:10]
Move_logoY=0;//[-10:.01:10]
Move_logoZ=1;//[-10:.01:10]

module body(){
 translate([0,-.25,0])
minkowski(){
 linear_extrude(1.3,scale=.90)
 square([2,Number_of_pins/2.5],center=true);
 mirror([0,0,1])
 linear_extrude(1.3,scale=.92)
 square([3.8,Number_of_pins/1.2],center=true);
 sphere(.2,$fn=60);
}

}

module pins(){
 $fn=100;
 color("azure")
 translate([0,1.5,0])
for(i=[-Number_of_pins/4:1:Number_of_pins/4-1])
  translate([0,i*2.54,0])
  rotate([90,0,0]){
  rotate([0,0,90])
  translate([-1.5,-3.81,-.1]) 
  cube([1.1,.25,1.1]);
  rotate([0,0,90])
  translate([-Pin_length-.5,-3.78,.15]) 
  cube([Pin_length,.2,.5]);
  translate([3.36,-.4,-.1])
  rotate_extrude(angle = 90)
  translate([.2,0,0])
  square([.25,1.1]);
  translate([3.36,0.05,-.1])
  rotate([0, 0, 180])
  cube([2,.25,1.1]);
}
}

module Text(){
  color("white")
  linear_extrude(.25)
  rotate([0,0,Text_rotate])
  translate([Move_text_X,Move_text_Y,1.3])
  text(Input_text,font=Font_name,spacing=1,
  size=text_size,valign="center",halign="center",$fn=50);
}

 module Logo(){
  if(Show_logo)
  color("white")
  rotate([0,0,90])
  translate([Move_logoX,Move_logoY,Move_logoZ])
  linear_extrude(2)
  scale([Scale_logo,Scale_logo,.1])
  import(Path_to_SVG_file);
}

 translate([0,0,0]){
 scale([Scale_all,Scale_all,Scale_all]){
 difference(){
 color("#242020")
 body();
if(show_notch){ 
 translate([0,Number_of_pins/2+Notch_adjust,1])
 #color("#242020")
 cylinder(.5,1,1,$fn=30);
 translate([-2.1,Number_of_pins/2+Notch_adjust-1,1])
 #color("white")
 cylinder(.5,.4,.3,$fn=30); 
}}
 mirror([1,0,0])
 pins();
 pins();
 Text();
 Logo();
}} 

To make step the export file type on the tool bar go to Edit>Preferences> Advanced>Export Features: