Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored convert-2d.sh script. changed readme. #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 0 additions & 70 deletions 2d_examples_tweak.scad

This file was deleted.

49 changes: 39 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ lasercutoutSquare(thickness=thickness, x=x, y=y,


## Complex Example
Putting these all together - gives a better example - https://github.com/bmsleight/lasercut/blob/master/examples.scad
Putting these all together - gives a better example - https://github.com/bmsleight/lasercut/blob/master/example.scad

![alt tag](https://raw.githubusercontent.com/bmsleight/lasercut/master/readme/example-complex.png)

Expand All @@ -344,24 +344,53 @@ Putting these all together - gives a better example - https://github.com/bmsleig

These models are all very nice, but we need have a nice file, normally dxf to use in a laser-cutter. So we can do this automatically.
```
/bin/bash ./convert-2d.sh examples.scad
./convert-2d.sh example.scad
```
This generates three files;
* examples.scad.csg
* [2d_examples.scad](https://raw.githubusercontent.com/bmsleight/lasercut/master/2d_examples.scad)
* 2d_examples.scad.dxf
This generates following files (depending to SCAD source filename);
* example-flat.scad
* example/
* example.csg
* example.dxf
* example.stl
* example.svg

### [2d_examples.scad](https://raw.githubusercontent.com/bmsleight/lasercut/master/2d_examples.scad)

### [example.scad](https://raw.githubusercontent.com/bmsleight/lasercut/master/example.scad)
This is a openscad file showing all the shapes along the y-axis.

![alt tag](https://raw.githubusercontent.com/bmsleight/lasercut/master/readme/example-complex-2d-all.png)
![alt tag](https://raw.githubusercontent.com/bmsleight/lasercut/master/readme/example-complex-2d-part.png)


To adjust the positions of the cut-out, so that are not all along the y-axis the parameter flat_adjust can be used, either in the main files or tweaked in the 2d_ file. For example flat_adjust = [110, -350]), would put the next peice at 110 in x direction and -250 in y-direction. With just using flat_adjust four times, we get a more practical example.
To adjust the positions of the cut-out, so that are not all along the y-axis the parameter flat_adjust can be used, either in the main files or tweaked in the "-flat" file.
For example ```flat_adjust = [110, -350])``` as additional argument in ```lasercutout()```, would put the next peice at 110 in x direction and -250 in y-direction.

```
// example with additional flat_adjust argument
lasercutout(thickness = 3.1,
points = [[0, 0], [37.5, 0], [37.5, 200], [0, 200], [0, 0]]
, twist_connect = [[270, 18.75, 6.2], [270, 18.75, 190.7]]
, flat_adjust = [110, -350]
)

```

See [2d_examples_tweak.scad](https://github.com/bmsleight/lasercut/blob/master/2d_examples_tweak.scad)
With just using flat_adjust a couple of times, we get a more practical example. Which give an arrangement and can be exported to a new dxf file.

Which give an arrangement and can be exported to a new dxf file.
![alt tag](https://raw.githubusercontent.com/bmsleight/lasercut/master/readme/example-complex-2d-part-tweak-dxf.png)

## Files for 3d printing (or limited use with cnc depending of used endmill)

If you need a version for 3d printing you can comment out a line of the YOUR_FILENAME-flat.scad file and exported a stl file.


```
...
...
// uncomment if you need an extruded version for e.g. 3d printing
//linear_extrude(height=YOUR_HEIGHT_VALUE)
flat();
...
...
```

79 changes: 63 additions & 16 deletions convert-2d.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Defines where OpenSCAD is installed
#!/bin/bash

BOLD=$(tput bold)
NORMAL=$(tput sgr0)

SOURCE_FILE=$(basename $1)
NAME=${SOURCE_FILE%.scad}
CONVERTED_FILE="$NAME-flat.scad"
DEST_FOLDER="$NAME"

TMPCSG="/tmp/$NAME.csg"
TMPSCAD="/tmp/$NAME.scad"

if [ $# -lt 1 ] ; then
echo "> ${BOLD}Missing argument. No SCAD file given! Example: ./convert-2d.sh example.scad${NORMAL}" 1>&2
exit 1
fi

if [ ! -f "$SOURCE_FILE" ]; then
echo "> ${BOLD}The given $SOURCE_FILE does not exist?${NORMAL}" 1>&2
exit 1
fi

# Defines where OpenSCAD is installed
openscad_bin() {
if [ -n "$OPENSCAD_BIN" ]
then
Expand All @@ -12,26 +34,51 @@ openscad_bin() {
fi
}

makeFlat(){
# Create a 2d plan of your 3D model
echo "> generate ${BOLD}2d flat scad file${NORMAL}"

# Creates a 2d plan of your 3D model
openscad_bin "$SOURCE_FILE -D generate=1 -o $TMPCSG" 2>&1 >/dev/null | sed -e 's/ECHO: \"\[LC\] //' -e 's/"$//' -e '$a\
;' -e '/WARNING/d' >$TMPSCAD

TMPCSG=/tmp/$(basename $1).csg
TMPSCAD=/tmp/$(basename $1).scad
echo "use <lasercut.scad>;
\$fn=60;
module flat(){
projection(cut = false)
" > $CONVERTED_FILE

openscad_bin "$1 -D generate=1 -o $TMPCSG" 2>&1 >/dev/null | sed -e 's/ECHO: \"\[LC\] //' -e 's/"$//' -e '$a\;' -e '/WARNING/d' >$TMPSCAD
cat $TMPSCAD >> $CONVERTED_FILE

echo "
}

// uncomment if you need an extruded version for e.g. 3d printing, cnc milling
//linear_extrude(height=YOUR_HEIGHT_VALUE)
flat();" >> $CONVERTED_FILE
}

makeFlat

sed -i.tmp '1 i\
// May need to adjust location of <lasercut.scad> \
use <lasercut.scad> ;\
\$fn=60;\
projection(cut = false)\
' $TMPSCAD

# Exports in others formats (could be very long)
if [ ! -d "$DEST_FOLDER" ]; then
echo "> create folder ${BOLD}${NAME}${NORMAL}";
mkdir -p "$DEST_FOLDER"
fi

echo "> save ${BOLD}csg file${NORMAL}";
openscad_bin "./$CONVERTED_FILE -o ./$DEST_FOLDER/$NAME.csg -q"

echo "> save ${BOLD}dxf file${NORMAL}";
openscad_bin "./$CONVERTED_FILE -o ./$DEST_FOLDER/$NAME.dxf -q"

echo "> save ${BOLD}svg file${NORMAL}";
openscad_bin "./$CONVERTED_FILE -o ./$DEST_FOLDER/$NAME.svg -q"

echo "> save ${BOLD}3d stl file${NORMAL}";
openscad_bin "./$SOURCE_FILE -D foo=1 -o ./$DEST_FOLDER/$NAME.stl -q"

#openscad_bin "./2d_$1 -o ./2d_$1.csg"
#openscad_bin "./2d_$1 -o ./2d_$1.dxf"
#openscad_bin "./2d_$1 -o ./2d_$1.svg"
#openscad_bin "./$1 -o ./3d_$1.stl"
#echo "> save ${BOLD}3d stl flat file${NORMAL}";
#openscad_bin "./$CONVERTED_FILE -o ./$DEST_FOLDER/$NAME-3d-flat.stl"

mv $TMPSCAD $(dirname $1)/$(basename $1)_2d.scad
echo "> ${BOLD}done!${NORMAL}";
39 changes: 26 additions & 13 deletions 2d_examples.scad → examples-flat.scad
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
use <lasercut.scad>; $fn=60;
projection(cut = false)

use <lasercut.scad>;
$fn=60;
module flat(){
projection(cut = false)

// screw thread major dia must be < 3.1
// screw thread length must be < 15.5
// nut thickness must be < 3.1
// nut flats must be < 9.3
lasercutout(thickness = 3.1,
points = [[0, 0], [100, 0], [100, 75], [0, 75], [0, 0]]
, simple_tab_holes = [[360, 23.45, 37.5], [360, 73.45, 37.5]]
, captive_nuts = [[0, 50, 75]]
, captive_nuts = [[0, 50, 75, 7]]
, twist_holes = [[270, 50, 18.75, 37.5]]
)

lasercutout(thickness = 3.1,
points = [[0, 0], [100, 0], [100, 75], [0, 75], [0, 0]]
, simple_tab_holes = [[360, 23.45, 37.5], [360, 73.45, 37.5]]
, captive_nuts = [[0, 50, 75]]
, twist_holes = [[270, 50, 18.75, 37.5]]
, clips = [[0, 50, 75]]
)

lasercutout(thickness = 3.1,
Expand All @@ -28,37 +34,44 @@ lasercutout(thickness = 3.1,
lasercutout(thickness = 3.1,
points = [[0, 0], [93.8, 0], [93.8, 193.8], [0, 193.8], [0, 0]]
, simple_tabs = [[180, -1.55, 0], [180, -1.55, 196.9], [270, 93.8, -1.55]]
, captive_nut_holes = [[0, 50, 193.8], [180, 50, 0]]
, finger_joints = [[0, 1, 4], [180, 1, 4], [90, 1, 4], [270, 0, 4]]
, captive_nut_holes = [[180, 50, 0]]
, finger_joints = [[0, 1, 2], [180, 1, 2], [90, 1, 2], [270, 0, 2]]
, clip_holes = [[0, 50, 190.7]]
)

lasercutout(thickness = 3.1,
points = [[0, 0], [93.8, 0], [93.8, 193.8], [0, 193.8], [0, 0]]
, simple_tabs = [[180, -1.55, 0], [270, 93.8, -1.55]]
, finger_joints = [[0, 0, 4], [180, 1, 4], [90, 1, 4], [270, 0, 4]]
, circles_remove = [[25, 50, 100]]
, finger_joints = [[0, 0, 2], [180, 1, 2], [90, 1, 2], [270, 0, 2]]
, circles_remove = [[25, 46.9, 100]]
)

lasercutout(thickness = 3.1,
points = [[0, 0], [93.8, 0], [93.8, 43.8], [0, 43.8], [0, 0]]
, finger_joints = [[0, 1, 4], [180, 0, 4], [90, 1, 4], [270, 0, 4]]
, finger_joints = [[0, 1, 2], [180, 0, 2], [90, 1, 2], [270, 0, 2]]
)

lasercutout(thickness = 3.1,
points = [[0, 0], [93.8, 0], [93.8, 43.8], [0, 43.8], [0, 0]]
, simple_tabs = [[0, -1.55, 43.8], [180, 95.35, 0]]
, finger_joints = [[0, 1, 4], [180, 1, 4], [90, 1, 4], [270, 0, 4]]
, finger_joints = [[0, 1, 2], [180, 1, 2], [90, 1, 2], [270, 0, 2]]
)

lasercutout(thickness = 3.1,
points = [[0, 0], [43.8, 0], [43.8, 193.8], [0, 193.8], [0, 0]]
, finger_joints = [[0, 0, 4], [180, 1, 4], [90, 0, 4], [270, 1, 4]]
, finger_joints = [[0, 0, 2], [180, 1, 2], [90, 0, 2], [270, 1, 2]]
)

lasercutout(thickness = 3.1,
points = [[0, 0], [43.8, 0], [43.8, 193.8], [0, 193.8], [0, 0]]
, simple_tabs = [[0, 45.35, 193.8]]
, finger_joints = [[0, 0, 4], [180, 1, 4], [90, 0, 4], [270, 1, 4]]
, finger_joints = [[0, 0, 2], [180, 1, 2], [90, 0, 2], [270, 1, 2]]
)

;

}

// uncomment if you need an extruded version for e.g. 3d printing, cnc milling
//linear_extrude(height=YOUR_HEIGHT_VALUE)
flat();
Loading