How can merge two arcs into one path in Layout?

how can merge two arcs into one path in Layout?

image

From Ruby API, use Entities#weld_edges

sorry, I didn’t express the problem clearly.

Layout::Entities not exist the function.

sorry, I didn’t express the problem clearly.

Since they are “arc type” paths, I am not sure if this will work …

if arc1.end_point == arc2.start_point
  arc2.points.each { |pt| arc1.append_point(pt) }
  doc.remove_entity(arc2)
elsif arc1.end_point == arc2.end_point
  arc2.points.reverse.each { |pt| arc1.append_point(pt) }
  doc.remove_entity(arc2)
elsif arc2.end_point == arc1.start_point
  arc1.points.each { |pt| arc2.append_point(pt) }
  doc.remove_entity(arc1)
elsif arc2.end_point == arc1.end_point
  arc1.points.reverse.each { |pt| arc2.append_point(pt) }
  doc.remove_entity(arc1)
end

… because the winding and point types may become confused.


You may need to just use the points from both arc1 and arc2 to build a new non-arc path.
Then afterward delete arc1 and arc2.

def weld_arcs(arc1, arc2)

  if arc1.end_point == arc2.start_point
    points = arc1.points + arc2.points
  elsif arc1.end_point == arc2.end_point
    points = arc1.points + arc2.points.reverse
  elsif arc2.end_point == arc1.start_point
    points = arc2.points + arc1.points
  end

  path = Layout::Path.new(points.shift, points.shift)
  path.style = arc1.style
  points.each { |pt| path.append_point(pt) }
  layer = arc1.layer_instance
  page  = arc1.page
  doc = arc1.document
  doc.remove_entity(arc1)
  doc.remove_entity(arc2)
  if page # might be nil
    doc.add_entity(path, layer, page)
  else
    doc.add_entity(path, layer)
  end

end ### weld_arcs()

Method is weld, not weld_edges. Note that it wouldn’tpreserve ArcCurves. It would explode them and reassemble as a simple Curve.

The result of the function path.points includes the center point.

new_path = Layout::Path.new_arc(Geom::Point2d.new, 10, 0.degrees, 180.degrees)
new_path.points.each_with_index do |pt, index|
  p1 = Geom::Point3d.new(pt.x, pt.y, 0)
  Sketchup.active_model.entities.add_cpoint p1
end

image

That must be a bug.

Also the Path::new_arc method produces points that are not actually on an arc.

Please report these in the API issue tracker.

For now you’ll have to delete the center from the points array.

path.points.delete(path.arc[0])

For now, I use the polyline to draw multi-arc in one path.