The text of Layout::LinearDimension can't change

Sketchup 2020 Layout 2020
test.layout (38.5 KB)

path = 'C:\Users\admin\Desktop\test.layout'
doc = Layout::Document.open path
doc.units = Layout::Style::DECIMAL_MILLIMETERS
start_point = Geom::Point2d.new(10.mm, 20.mm)
end_point = Geom::Point2d.new(41.68.mm, 20.mm)
dim = Layout::LinearDimension.new(start_point, end_point,5.mm)
dim.custom_text = true
dim.text.plain_text = "30 mm"
doc.add_entity dim, doc.layers.first, doc.pages.first
doc.save save_path

This is ok.

path = 'C:\Users\admin\Desktop\test.layout'
doc = Layout::Document.open path
doc.units = Layout::Style::DECIMAL_MILLIMETERS
start_point = Geom::Point2d.new(10.mm, 20.mm)
end_point = Geom::Point2d.new(41.68.mm, 20.mm)
dim = Layout::LinearDimension.new(start_point, end_point,5.mm)
dim.custom_text = true
dim.text = Layout::FormattedText.new("30 mm", dim.text.bounds)
doc.add_entity dim, doc.layers.first, doc.pages.first
doc.save save_path

Generally, if possible, try to first add entities to the document before making changes to that entity.

Does this also work ?

dim = Layout::LinearDimension.new(start_point, end_point,5.mm)
doc.add_entity(dim, doc.layers.first, doc.pages.first)
dim.custom_text = true
dim.text = Layout::FormattedText.new("30 mm", dim.text.bounds)
2 Likes

Yes, it’s ok. Thank you.

1 Like