////////////////////////////////////////////////////////////////////// // LibFile: titleBlock.scad // Includes: // include ; // include ; // include ; // FileGroup: TitleBlock // FileSummary: Title Block ////////////////////////////////////////////////////////////////////// include include title_block_debugging = false; /* [Hidden] */ // Constant: A4_LANDSCAPE // Description: A4 Page dimensions A4_LANDSCAPE= [297,210]; // Module: titleBlock() // // Synopsis: Generates a customizable title block layout for documents. // Topics: Document Layout, Design, Modularity // Description: // This module creates a title block that includes a project title, description, // scale, revision, date, and other metadata. It supports full customization of // text size, positioning, and color. The title block is fully parametric, // allowing for flexible layout adjustments. // Arguments: // project = The project name or title to be displayed. [default: undef] // title = The title text to display. [default: undef] // description= A description of the project or work. [default: ""] // textSize = The size of the text to be used in the title block. [default: 6] // date = The date associated with the project. [default: "2025-01-01"] // scale = The scale of the project (e.g., 1:10). [default: 1] // revision = The project revision or version. [default: "1a"] // rect = The width and height of the title block. [default: [90,30]] // inset = The inset (margin) around the title block content. [default: 2] // anchor = The anchor position for the title block. [default: CENTER] // spin = The rotation angle of the title block. [default: 0] // orient = The orientation of the title block. [default: UP] // color = The color of the title block text. [default: "Black"] // strokeWidth= The width of the title block's stroke. [default: 0.5] // page = The paper size (A4, etc.). [default: "A4"] // landscape = Whether the title block is in landscape orientation. [default: true] // DefineHeader:Returns: // A parametric title block layout with project and metadata information. // Example(3D,Big,ColorScheme=Nature): Title Block // titleBlock( // project = "X-Drone", // title = "Engineering Design", // description = "This project focuses on designing a new type of drone for urban delivery services", // date = "2025-02-17", // revision = "A1", // scale = 20 // ); // // // // module titleBlock( project, title = undef, description = "", textSize = 6, date="2025-01-01", scale=1, revision="1a", rect=[90,30], inset=2, anchor=CENTER, spin=0, orient=UP, color="Black", strokeWidth = 0.5, page="A4", landscape = true, //anchor=CENTER,spin=0,orient=LEFT ) { w = rect[0]; h = rect[1]; _inset = inset> 0 ? inset : h/20; //echo ("rect",rect); //echo ("h",h); //l1 = h/2 - _inset; l1 = h/2 - 1.5* textSize - _inset; //echo ("l1",l1); interline = 0; //path = rect([w,h], chamfer=0 /*, anchor=FRONT*/); attachable(anchor,spin,orient=TOP, size=[w,h,1]) { //projection( cut = false ) projection() union() recolor(color) { // ************ Frame *************** rect_tube(size=[w,h], wall=0.5, h=0.1); l2 = l1 - interline- 2*_inset ; // ************ Project *************** translate([-w /2+_inset, l1 ]) linear_extrude(0.1,convexity = 10) text(project, size=textSize,halign="left",valign="baseline",anchor=BOTTOM+LEFT,font="Saira Stencil One"); // ************ Scale *************** translate([w/2-_inset, l1]) linear_extrude(0.1) text(str("Scale: 1/",scale), size=textSize*2/5,halign="right",valign="baseline",anchor=BOTTOM); // ************ Title *************** //metrics = textmetrics(project, size=textSize, font="Saira Stencil One"); //l2 = l1 - metrics.size[1]- 2*_inset ; if ( title ) translate([-w /2+_inset, l1 - 2* _inset ]) linear_extrude(0.1) //text( title, size=textSize*2/4,halign="left",anchor=TOP,font="Arial Black"); smartText( title, size = textSize*2/4, halign = "left", font = "Arial Black",// "Courier New:style=Italic" style = "Regular", max_width = 5, interline = 4 ); // ************ Description *************** if ( description ) { //translate([ -8, l2 - _inset/2 ]) translate([ -8, l1 - _inset*2 ]) linear_extrude(0.1) smartText( description, size = textSize*1/4, halign = "left", font = "Courier New",// "Courier New:style=Italic" style = "Italic", max_width = 51, //interline = -5 ); } // ************ HL *************** h1 = h/2-2*_inset - interline; translate([-w/2+_inset,l1,0]) cube([w-2*_inset,0.1,0.1]); // ************ Vertical sep *************** translate([10,interline-1*_inset/2,0]) cube([0.1,interline,0.1]); // ************ Revision *************** translate([-w /2+_inset+14, -h/2 + 2*_inset]) { linear_extrude(0.1) text("Revision:", size=textSize*2/5, anchor = RIGHT, font = "Arial:style=Italic"); linear_extrude(0.1) text(str(revision), size=textSize*2/5, anchor = LEFT,font = "Arial:style=Bold"); } // ************ Date *************** translate([w/2-_inset-18, -h/2 + 2*_inset]) { linear_extrude(0.1) text("Date:", size=textSize*2/5,halign="right", anchor = RIGHT, font = "Arial:style=Italic"); linear_extrude(0.1) text(str(date), size=textSize*2/5, anchor = LEFT,font = "Arial:style=Bold"); } }; children(); }; } // Module: A4 // // Synopsis: Generates an A4-sized boundary with configurable margins. // Topics: Templates, Technical Drawings // Description: // This module defines an A4-sized boundary for technical drawings, with configurable // margins. It provides an optional outer frame and allows child objects to be placed // within the margin area. The module can be used for layout planning in OpenSCAD. // // Arguments: // margin = Margin size (default: 10). // landscape = Boolean flag to switch between landscape and portrait mode (default: true). // onlyMargin = If true, renders only the margin area; otherwise, includes the full frame (default: true). // anchor = Anchor position for alignment (default: CENTER). // spin = Rotation angle in degrees (default: 0). // orient = Orientation of the bounding box (default: UP). // scale = Scale factor (default: 1). // strokeWidth = Stroke width for the drawing boundary (default: 0.2). // // Usage: // A4(margin=15, landscape=false, onlyMargin=false); // // DefineHeader:Notes: // - The A4 paper dimensions are standardized at 210mm x 297mm (portrait mode). // - If `landscape` is true, the width and height are swapped. // // DefineHeader:Returns: // - A 2D boundary representation of an A4 page with an optional margin outline. // // Example(3D,Big,ColorScheme=Nature): A4 with border and margin // A4( onlyMargin = false ); // Example(3D,Big,ColorScheme=Nature): A4 without border // A4( onlyMargin = true ); // module A4( margin = 10, landscape = true, onlyMargin = true, anchor=CENTER, spin=0, orient=UP, scale=1, strokeWidth=0.2 ){ w = A4_LANDSCAPE[0]; h = A4_LANDSCAPE[1]; marginW = w-2*margin; marginH = h-2*margin; attachable(anchor,spin, orient, size=[marginW,marginH,50]) { projection( cut = false ) union(){ if (!onlyMargin) color("Orange") rect_tube(size=[w,h], wall=0.1, h=0.1); color("Red") rect_tube(size=[marginW,marginH], wall=0.1, h=0.1); }; children(); } } // Module: plan // // Synopsis: Generates a structured technical drawing layout with a title block. // Topics: Templates, Technical Drawings // Description: // This module creates a structured layout for technical drawings. It includes a title block // positioned within an A4-sized frame, allowing child objects to be placed within the defined // margins. The layout is configurable to support different project details and orientations. // // Arguments: // project = Project name (required). // title = Title of the drawing (default: undef). // description = Short description of the drawing (default: ""). // textSize = Size of the text in the title block (default: 6). // date = Date to be displayed in the title block (default: "2025-01-01"). // scale = Scale factor for the drawing (default: 1). // revision = Revision identifier (default: "1a"). // page = Page size identifier (default: "A4"). // margin = Margin size around the drawing area (default: 10). // orient = Orientation of the drawing (default: UP). // // Usage: // plan("Project Alpha", title="Main Assembly", description="Assembly drawing", scale=2); // // DefineHeader:Notes: // - This module uses `A4()` for the page layout and `titleBlock()` for the title block. // - The `align()` function ensures proper positioning of the title block. // - The `children()` function allows for additional drawing elements to be included. module plan( project, title = undef, description = "", textSize = 6, date = "2025-01-01", scale = 1, revision = "1a", page = "A4", margin = 10, orient = UP ) { A4( onlyMargin = false, anchor=LEFT+FWD, scale=2,orient=orient /*, orient*/ ) { //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( project, title = title, description = description, //textSize = 7, rect = [90,30], inset = 2 ); }; //align(BACK+LEFT /*,inside=true*/) //if (page == "A4") //translate([-A4_LANDSCAPE[0]/2+margin,+A4_LANDSCAPE[1]/2-margin,0]) // children(); //else children(); } } if ( title_block_debugging ) { //titleBlock("My First Project"); lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam at rutrum magna. Donec auctor euismod nulla ut congue."; if (true) plan( "Title Block", title="Engineering Design", description=lorem, ) { projection( cut = false ) cube([5,5,5],anchor=BACK+LEFT); } //A4() //show_anchors() // ; if (false) titleBlock( project = "Project", title = "Engineering Design", description = lorem, //rect = [90,30], ) //show_anchors() ; }