To use components instead, create a component Definition object from the add factory method of the DefinitionList object, instead of creating a temporary Group using the add_group factory method of an Entities object.
model = Sketchup.active_model
edges = model.selection.grep(Sketchup::Edge)
segments = 12
radius = 5.cm
# Cretate component definition
definition = model.definitions.add("Pipe")
definition.entities.add_circle(ORIGIN, Z_AXIS, radius, segments).first.find_faces
face = definition.entities.grep(Sketchup::Face).first
face.reverse! unless face.normal.samedirection?(Z_AXIS)
# Place group instances
edges.each do |edge|
tr = Geom::Transformation.new(*edge.line) * Geom::Transformation.scaling(1, 1, edge.length)
instance = model.active_entities.add_instance(definition, tr)
For a square cross section you can set the segment count to 4 instead of 12 but the edges will still be soften. Maybe it’s easiest to unsoften them manually. Also note that the rotation of the cross section is quite arbitrary which is why circular pipes are so useful for these designs.
If you want to learn Ruby you can read the different code snippets and try to understand them. Modifying and experiment is also a great way to learn . The Ruby API documentation lists all SketchUp’s classes and their methods.
Btw, how much did your original wireframe model gain in file size using my snippet?