ModraUp Ruby API Documentation Ruby API Reference

Module: Layout

Overview

Paper-space drawing API, named after the LayOut Ruby API. Access the document through ModraUp::Model#layout_document. Drawings are saved with the model, separately from model attributes. Standalone opening or saving of .layout files is unsupported.

Sheet coordinates, dimensions, paper sizes, margins, and model points (Geom::Point3d) use inches. Use expressions such as 20.mm for other units. Line weights, arrow sizes, and font sizes use points. View scale is a ratio (1:50 is 0.02).

Each edit creates an undo step. To group edits, enclose them in ModraUp::Model#start_operation and ModraUp::Model#commit_operation. Call ModraUp::Model#abort_operation to revert the operation. When the drawing workspace is open, new views render in the background. Calls without an application host raise NotImplementedError.

Note: ModraUp extension. The names are taken from a subset of LayOut's official API; capabilities not present in LayOut (model embedding ports, single-component viewports, sections and details, visible lines, title blocks) are individually noted in the methods.

Examples:

Create a sheet and place a scene view on it

doc = ModraUp.active_model.layout_document
page = doc.pages.add("Floor plan")
scene = ModraUp.active_model.pages.add("Ground floor")
view = Layout::SketchUpModel.new(scene, Geom::Bounds2d.new(20.mm, 20.mm, 250.mm, 180.mm))
view.scale = 1.0 / 100
doc.add_entity(view, doc.layers.active, page)

Drawing sheet and title block

doc = ModraUp.active_model.layout_document
doc.pages.add("Floor plan")
info = doc.page_info                # document-wide settings
info.width  = 420.mm
info.height = 297.mm
info.left_margin = 10.mm            # apply to all four sides
doc.title_block["project"] = "Example residence"

Create an elevation and an associated overall dimension for a component in one undo step

model = ModraUp.active_model
doc = model.layout_document
page = doc.pages.add
cabinet = model.entities.add_group
cabinet.entities.add_face([0, 0, 0], [600.mm, 0, 0], [600.mm, 400.mm, 0], [0, 400.mm, 0]).pushpull(-800.mm)
model.start_operation("Cabinet elevation", true)
front = Layout::SketchUpModel.new(cabinet, Geom::Bounds2d.new(290.mm, 20.mm, 110.mm, 90.mm))
front.view = Layout::SketchUpModel::FRONT_VIEW
front.scale = 1.0 / 20
doc.add_entity(front, doc.layers.active, page)
bb = cabinet.bounds
p1, p2 = bb.corner(0), bb.corner(1)
dim = Layout::LinearDimension.new(front.model_to_paper_point(p1), front.model_to_paper_point(p2), -8.mm)
dim.connect(Layout::ConnectionPoint.new(front, p1), Layout::ConnectionPoint.new(front, p2))
dim.set_attribute("auto_dim", "source", cabinet.persistent_id)
doc.add_entity(dim, doc.layers.active, page)
model.commit_operation

Section View (with the top as an independent viewport added to the document)

# bb = cabinet.bounds; c = bb.center
# section = top.create_section(Geom::Point3d.new(bb.min.x - 20.mm, c.y, c.z),
#                              Geom::Point3d.new(bb.max.x + 20.mm, c.y, c.z),
#                              Geom::Vector3d.new(0, 1, 0), depth: bb.height / 2 + 20.mm)
# section.scale = 1.0 / 20

Text and Line Styles (Styles are copies, modify at your own risk; revert changes when done)

doc = ModraUp.active_model.layout_document
page = doc.pages.add
title = Layout::FormattedText.new("Ground-floor plan  1:100", Geom::Point2d.new(20.mm, 205.mm),
                                  Layout::FormattedText::ANCHOR_TYPE_TOP_LEFT)
s = title.style
s.font_size = 14
title.style = s
doc.add_entity(title, doc.layers.active, page)
frame = Layout::Rectangle.new(Geom::Bounds2d.new(5.mm, 5.mm, 410.mm, 287.mm))
s = frame.style
s.stroke_width = 2.0
s.stroke_pattern = Layout::Style::STROKE_PATTERN_DASH
frame.style = s
doc.add_entity(frame, doc.layers.active, page)

Defined Under Namespace

Classes: AngularDimension, ArcDimension, ConnectionPoint, Document, Ellipse, Entities, Entity, FormattedText, Image, Label, Layer, LayerInstance, Layers, LinearDimension, LockedEntityError, LockedLayerError, Page, PageInfo, Pages, PaperView, Path, RadialDimension, Rectangle, SketchUpModel, Style, TitleBlock, VisibleLine