How to pipe bunch of lines in sketchup

Hi,
Is there any way to pipe a bunch of lines for creating spaceframe ?

1 Like

It is simple enough to “pipe a bunch of lines” if that is enough. The problem is joining of the tubes at the nodes.

What are you expecting?

I’m curious about how would you turn those lines into cylinders or “pipes”. I’ve been puzzling on this one and haven’t seen a solution yet.

Given a selection of edges

				for e in edges
					grp=ent.add_group;gent=grp.entities
					p0,vector=e.line
					circle=gent.add_circle(p0,vector,radius,@sides)
					face=gent.add_face(circle)
					face.followme e
				end

There are several plugins available to do things like this…
@sdmitch has one that puts a premade component’s instance on each line, and scales it along that line, along the Z/blue axis of the component, along the line.
The issue is that these component instances’ geometry will overlap at each ‘node’ vertex where several lines meet.
Placing a ‘node’ component and adjusting the related tube’s start/end locations would be possible, but not so easy.
And since the nodes will have various angle this could be an issue - perhaps the simplest node would be a ‘sphere’, so the springing/arrival of each tube would be masked by the sphere-node ??

Can You explain how to run this script?

We need to add a few lines first then you can copy and paste it into the Ruby Console

mod = Sketchup.active_model
ent = mod.active_entities
sel = mod.selection
edges = sel.grep(Sketchup::Edge)
val = UI.inputbox(["Radius:","#Sides"],[1.0,12],"Edge 2 Tube")
if val
  radius,sides = val
  for e in edges
    grp=ent.add_group;gent=grp.entities
    p0,vector=e.line
    circle=gent.add_circle(p0,vector,radius,sides)
    face=gent.add_face(circle)
    face.followme e
  end
end
2 Likes

Ummm… I expect just have lines :)) connections is not important!
from Sketchup 7 to 2017 we have two plugins do that thing: 1- lines2Tube 2- Pipe Along Path and other plugins have that option: 1001bit pro, but any of them have problems! 1- line2Tube: doesn’t make these bunch of lines and crashes!2- Pipe Along Path: when I select a whole bunch of lines plugin goes selecting a loop of three or four lines and then make it pipe :)) 1001bit pro works same as Pipe Along Path.

These script lines works well so much thanks to you :slight_smile:

Using a script/plugin that places reused scaled components/groups would greatly decrease the file size (and speed up SU) because it would reuse the same cylinder. For this model my guess is the file size could be as small as 1/20 of what it is when all cylinders are drawn separately.

1 Like

Not at all, I used script above and my SU file goes 25 Mb !! on the other hand I used Lunchbox plugin in rhino, grasshopper and import it to sketchup file goes 18 Mb.

I think this snippet should just increase the file size with one MB or so. That is the power of groups and components in SketchUp!

model = Sketchup.active_model
edges = model.selection.grep(Sketchup::Edge)

# Variables
segments = 12
radius = 5.cm # <-- EDIT THIS NUMBER TO DESIRED RADIUS.

model.start_operation("Pipe", true)

# Cretate group definition
group = model.active_entities.add_group
group.entities.add_circle(ORIGIN, Z_AXIS, radius, segments).first.find_faces
face = group.entities.grep(Sketchup::Face).first
face.reverse! unless face.normal.samedirection?(Z_AXIS)
face.pushpull(1)
definition = group.definition

# 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)
end

# Purge original group
group.erase!

model.commit_operation
3 Likes

It works fine :slight_smile: How to edit this script to make Rectangular profile instead of pipe and make it component instead of groups?
I’m not familiar with Ruby :frowning:

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)

# Variables
segments = 12
radius = 5.cm

model.start_operation("Pipe", true)

# 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)
face.pushpull(1)

# 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)
end

model.commit_operation

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 :smiley: . 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?

2 Likes

OR use these additional lines inserted in the ‘group’ version, as shown…
@eneroth3 beat me to it with her compo version !

###... include the previous code up to here...
face.pushpull(1)
### insert this new line to make the group into a component...
group = group.to_component
### actually it is now a component-instance, but the reference to 'group' is used later on in the code !
### define the definition as in original code...
definition = group.definition
### then insert this new line which names this definition...
definition.name = "Pipe"
###... leave the rest of the code to the end...

Incidentally the sides reference is omitted in the examples, so the default will then be used for the circle [24]…
It’s easily added back in.

sides = 12
definition.entities.add_circle(ORIGIN, Z_AXIS, radius, sides).first.find_faces

You could use an ngon instead of a circle and then the tube’s edges don’t get smoothed…
With 4 sides it’ll be a square tube, but it’s orientation/rotation around the line might not be what you want ?
A smoothed circular tube is more ‘forgiving’ as its orientation is not obvious…

sides = 4
definition.entities.add_ngon(ORIGIN, Z_AXIS, radius, sides).first.find_faces

1 Like

Wops, forgot to reference the variable :open_mouth: . I’ll edit my posts, thanks!

Using ngon is also a good idea!

1- with first script with Radius:20cm & Sides:5 file goes 25MB result shows after 2 min
With your Script Radius:20cm & Sides:5 goes 4 MB The result is displayed immediately after interpolation.
2- for square cross section you said, If possible to set any axes that profile applies to line it might be possible same as what happens in reality for modern gridshell structures. for example profiles add in z direction of each line.

At least so much thanks for your great guide :slight_smile: :hugs:

In my snippets I use Geom::Transformation.new with a Point3d and Vector3d as arguments to define a transformation matrix. SketchUp decides arbitrary vectors for the other axes. The API docs describes more ways to create matrices: http://ruby.sketchup.com/Geom/Transformation.html.

You can experimenting with passing an additional vector to the Transformation constructor method. However then you also need to change the orientation of the circle further up in the code. X_AXIS, Y_AXIS and Z_AXIS are constants containing unit vectors in the three axes and often very useful.

1 Like

I mean rectangle for cross section that have width and height not square. something line image below.
JPG