There is an issue with the return value of the method <model_to_paper_point> in Layout 2023

Bug Reports

  1. SketchUp/LayOut Version: 2023.1.340
  2. OS Platform: windows 10

I can not get right value by Layout::SketchUpModel#model_to_paper_point.
When I mapped the edges from the model to the drawing, the drawn results did not overlap.

ruby code

Sketchup.active_model.entities.erase_entities(Sketchup.active_model.entities.to_a)
Sketchup.active_model.entities.add_line(ORIGIN, ORIGIN + Geom::Vector3d.new(800.mm, 300.mm))
page = Sketchup.active_model.pages.add
camera = Sketchup.active_model.active_view.camera
camera.perspective = false
eye = Geom::Point3d.new(0, 0, 10)
up = Y_AXIS
target = Geom::Point3d.new(0, 0, 0)
camera.set eye, target, up
g = Sketchup.active_model.entities.add_group
p1 = ORIGIN - Geom::Vector3d.new(300.mm, 100.mm)
p2 = ORIGIN + Geom::Vector3d.new(1100.mm, 400.mm)
g.entities.add_line(p1, p2)
Sketchup.active_model.active_view.zoom g
g.erase!
page.update PAGE_USE_ALL
Sketchup.active_model.save('F:/desktop/test.skp')

doc = Layout::Document.new
page = Sketchup.active_model.pages.selected_page
bounds = Geom::Bounds2d.new(200.mm, 200.mm, 300.mm, 300.mm)
model = Layout::SketchUpModel.new(Sketchup.active_model.path, bounds)
doc.add_entity(model, doc.layers.first, doc.pages.first)
model.current_scene = Sketchup.active_model.pages.to_a.index(page) + 1
model.render_mode = Layout::SketchUpModel::RASTER_RENDER
model.scale = 1.0 / 15
model.perspective = page.camera.perspective? # 平行投影
model.line_weight = 0.1
model.render_mode

edge = Sketchup.active_model.entities.to_a[0]
s_p = model.model_to_paper_point(edge.start.position)
e_p = model.model_to_paper_point(edge.end.position)
doc.add_entity(Layout::Path.new(s_p, e_p), doc.layers.first, doc.pages.first)
doc.save('F:/desktop/test.layout')
puts "edge length in model : #{(edge.end.position - edge.start.position).length.to_mm} mm"
puts "edge length in paper : #{(s_p - e_p).length.to_mm} mm"

out put

edge length in model : 854.4003745317531 mm
edge length in paper : 359.9118903742617 mm

Generally, with the LayOut API, always add the entity to the document object before setting or changing any of the entity’s properties. LayOut uses a hardcoded set of default properties whenever an entity is added to the document, rather than what you might have attempted to set the properties as.


Otherwise, there might be some bugs related to display scaling.

Looking in the API Issue tracker, I see that a bug has already been reported …

1 Like