From db32cff7044747cc4b76a23391361ea75d2f0ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Dante=20Ursini?= Date: Sat, 8 Feb 2025 16:44:24 -0300 Subject: [PATCH] Quote and a4 page with title block --- .gitignore | 6 +++ Readme.md | 3 +- quotes.scad | 65 ++++++++++++++++++++++++++++++ titleBlock.scad | 103 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 quotes.scad create mode 100644 titleBlock.scad diff --git a/.gitignore b/.gitignore index e43b0f9..c187832 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ .DS_Store +.swp + + +## Customizers presets +quotes.json +titleBlock.json diff --git a/Readme.md b/Readme.md index 077a455..9e2d6f2 100644 --- a/Readme.md +++ b/Readme.md @@ -3,9 +3,10 @@ ## Setup soft link +Make a symbolic link to make the quotes library available as library ```bash -ln -s /Users/sursini/Documents/Design/OpenSCAD Quotes +ln -s /Users/sursini/Documents/Design/OpenSCAD/Quotes /usr/local/share/openscad/libraries/Quotes ``` diff --git a/quotes.scad b/quotes.scad new file mode 100644 index 0000000..bc8365d --- /dev/null +++ b/quotes.scad @@ -0,0 +1,65 @@ +include + + +debugging = false; + + +/** + * Quote + * + * @param offsetFromOrigin - It specifies the distance from the object being dimensioned to the start of the extension lines + * @param extendBeyondDimLines - How much the extension lines extend past the dimension line + * @param textOffset - Distance between dimension text and dimension line + * @param direction - Direction of the dimension line (RIGHT, LEFT, UP, DOWN) + * @param placement - If BOTTOM, places the dimension below the model; if TOP, above (default is TOP) + */ +module quote( + length, + offsetFromOrigin = 140, + extendBeyondDimLines = 40, + textOffset = 10, + direction = RIGHT, + color = "Red", + placement = TOP + ){ + + // Determine rotation angle based on direction + angle = + direction == RIGHT ? 0 : + direction == LEFT ? 180 : + direction == UP ? 90 : + direction == DOWN ? -90 : 0; + + // Adjust offset based on whether the dimension is under the model + actualOffset = placement == BOTTOM ? -offsetFromOrigin : offsetFromOrigin; + + // Use color + color(color) { + // Rotate everything according to the direction + zrot(angle) { + path = [[ 0, actualOffset], [length-5 , actualOffset ]]; + // Paralel line + stroke(path, width = 3,endcaps = "arrow2",endcap_width = 15); + + // Extension Line 1 + ext1 = [[0,0], [0,actualOffset + (placement == BOTTOM ? -extendBeyondDimLines : extendBeyondDimLines)]]; + stroke(ext1, width=3); + + // Extension Line 2 + ext2 = [[length,0], [length,actualOffset + (placement == BOTTOM ? -extendBeyondDimLines : extendBeyondDimLines)]]; + stroke(ext2, width=3); + + // Text + back( actualOffset + textOffset ) + right(length/2) + text(str(length), size=60, font="Saira Stencil One", halign="center"); + } + } + +} + + + + +if ( debugging ) + quote(1000,direction=RIGHT,placement=BOTTOM); \ No newline at end of file diff --git a/titleBlock.scad b/titleBlock.scad new file mode 100644 index 0000000..b99c200 --- /dev/null +++ b/titleBlock.scad @@ -0,0 +1,103 @@ + +include + + +A4_LANDSCAPE= [297,210]; + + +debugging = false; + +module titleBlock( + project, + textSize=6, + date="2025-01-01", + scale=1, + revision="1a", + rect=[90,30], + inset=10, + anchor=CENTER, + spin=0, + orient=UP + //anchor=CENTER,spin=0,orient=LEFT + + ) { + w = rect[0]; + h = rect[1]; + _inset = inset> 0 ? inset : h/20; + echo("w",w); + echo("h",h); + echo("inset",_inset); + // Border + path = rect([w,h], chamfer=0 /*, anchor=FRONT*/); + //color("Blue") + + //back(-50/2) + + //square(rect, center=true); + + //attachable( anchor,orient,/*anchor, spin, orient,*/size=[w,h,0] /*,axis=RIGHT*/ ) { + attachable(anchor,spin,orient, size=[w,h,50]) { + union() { + stroke(path, closed=true); + // Title + translate([-w /2+_inset, h/2 - _inset ]) + text(project, size=textSize,halign="left",anchor=TOP); + // Revision + translate([-w /2+_inset, -h/2 + _inset]) + text(str("Revision:",revision), size=textSize*2/3/*,anchor=BOTTOM*/); + // Scale + translate([w/2-_inset, h/2 - _inset]) + text(str("Scale: 1:",scale), size=textSize*2/3,halign="right",anchor=TOP); + // Date + translate([w/2-_inset, -h/2 + _inset]) + text(str("Date:",date), size=textSize*2/3,halign="right"); + }; + children(); + }; +} + + +module A4( margin = 10, landscape = true, onlyMargin = true, anchor=CENTER, spin=0, orient=UP ){ + + //a4= [297,210]; + w = A4_LANDSCAPE[0]; + h = A4_LANDSCAPE[1]; + marginW = w-2*margin; + marginH = h-2*margin; + contour = rect([w,h]); + + //translate([w/2,h/2,0]) + //attachable(size=[100,200,0] ) { +// attachable( /*anchor=anchor, , spin, orient,*/size=[marginW,marginH,0] ) { + attachable(anchor,spin,orient, size=[marginW,marginH,50]) { + + union(){ + + if (!onlyMargin) color("Orange") stroke(contour, closed=true); + marginPath = rect([marginW,marginH]); + color("Red") stroke(marginPath, closed=true); + }; + //} + children(); + } +} + + + +if ( debugging ) { + //titleBlock("My First Project"); + + A4( onlyMargin = false,anchor=LEFT+FWD ) + //align(align=TOP+LEFT+FWD,spin=[0, 0, 0],inside=true) + //attach(LEFT+FWD,/*RIGHT,inside=true*/) + //align(LEFT,inside=true) + align(FWD+RIGHT,inside=true) + titleBlock("Metal Desk",textSize=7,rect=[90,30],inset=2); + //cuboid([50,20,10],anchor=TOP); + + + + + + +}