path = 'C:\Users\admin\Desktop\无标题.layout'
doc = Layout::Document.open path
start_p = Geom::Point2d.new(20.mm, 20.mm)
r, a = 5.mm, 5.mm * Math.sqrt(2)
p1 = start_p + Geom::Vector2d.new(a * 2, 0)
p2 = start_p + Geom::Vector2d.new(a, -a)
new_path = Layout::Path.new(start_p, p2)
doc.add_entity new_path, doc.layers.first, doc.pages.first
new_path = Layout::Path.new(p1, p2)
doc.add_entity new_path, doc.layers.first, doc.pages.first
doc.save path
Use append_point and close.
Avoid closed point is the inflection point.
start_p = Geom::Point2d.new(20.mm, 20.mm)
r, a = 5.mm, 5.mm * Math.sqrt(2)
center = start_p + Geom::Vector2d.new(a, 0)
p1 = start_p + Geom::Vector2d.new(a, -a)
p2 = start_p + Geom::Vector2d.new(a * 2, 0)
new_path = Layout::Path.new(center, start_p)
new_path.append_point p1
new_path.append_point p2
new_path.append_point center
new_path.close
doc.add_entity new_path, doc.layers.first, doc.pages.first
You can also control the type of join and end caps for Layout::Path
objects.
They are a subclass of Layout::Entity
so they also have a style
getter and style=
setter.
The Layout::Style
class has join type constants:
Layout::Style::JOIN_STYLE_MITER
Layout::Style::JOIN_STYLE_ROUND
Layout::Style::JOIN_STYLE_BEVEL
… also stroke pattern (stipple) style and end cap style constants.
For example …
path_style = new_path.style
path_style.stroke_join_style= Layout::Style::JOIN_STYLE_ROUND
path_style.stroke_cap_style= Layout::Style::CAP_STYLE_ROUND
# Might need to set the modified style back to the entity:
new_path.style= path_style
@tt_su Do mods to an Layout::Entity
’s style manifest immediately ?
Not sure, I need to check.
I asked internally. The response:
You must set the style on the entity. The style object received is a copy.
To be more technical than is necessary, the style object is created at the time of request and is never owned by the entity in the first place.
Thank you Thomas, this is as I had thought (and surmised in the above code comment.)
I drew two lines before. This situation of two lines should not be handled.