script to create many tubes at specific coordinates

Hi all,

I’m a Blender newbie and I need help getting started to create a simple script for a scientific display…

I need to create many thin lines (or tubes) that start and end as specific coordinates, and have a specific color. I have the start coordinates (x1,y1,z1) and stop coordinates (x2,y2,z2) for each line, as well as each line’s designated color (r,g,b) stored in a text file. So essentially, I need a simple script to call up these values, and generate the lines (tubes).

Something like the following…

Line (x1,y1,z1; x2,y2,z2; color r,g,b)

The problem is, I have no Python experience, so specific code would be appreciated. Thanks!
Dave

I have a script that I use to duplicate from an object library. In your case the object library would consist of one object: the tube :wink:

"""
Name: 'Test Script Name'
Blender: 237
Group: Object
"""
import Blender
import math
import string
import bpy

from Blender import *
from math import *
from string import *

f = file('filename')
scn = Blender.Scene.GetCurrent()

#read file
for line in f:
    ar = split(line, '|') # each line in the file has |-delimeted parameters (could be anything)
        
    
        ob_act = Blender.Object.Get(ar[0]) # which object to duplicate, in your case this could be the tube directly

        scn.objects.selected = []
        ob_act.sel = 1

        Blender.Object.Duplicate() #Duplicate linked
        ob_act = Object.GetSelected()

        ob_act.LoxX = float(ar[7].replace(",",".")) # here x is the 7th argument in the line and  have to replace the "," with the "."
        # change location, colour etc.
    
Blender.Redraw()

hope this helps to beginn with
chris
(also python noob)

Thanks Chris,

I’m afraid I need a little more hand-holding. How can I specify two points (p1 and p2) and get blender to construct a line (tube or cylinder) between those two points?

That is essentially what I need to do over and over again for different pairs of points in space (while also giving each line a different color).

Thanks for your help
D

In my script I have
Get.LocX
Get.LocY
Get.LocZ

Thats for the start points

And because you are essentially wanting to make a tree of sorts, visit http://www.python.org to find out how to read and write to text files.

Don’t worry, I was a newb too, and a project like this is how you learn both Blender and Python

Another idea too would be to have a look at the script for Second Life prims
That script will generate a mesh based on R, G, B colours of a picture file

In case you’re wondering the script I am writing will generate 2D interpolation curves, locations and rotations from a bezier spline, the loactions are done, and am working out how on earth to generate the rotation curves

Have fun

i would have to find about tube properties myself but guessing from what happens when i create a cylinder in blender you will have the number of faces, the radius = thickness and the depth = height = length. so once you have the location and the length you would adjust these properties.

http://www.zoo-logique.org/3D.Blender/scripts_python/API/

here you can search for mesh and/or mesh primitives in the upper left and then on the right click the cylinder primitive for example and you will be able to see the properties.

i found the above site useful as it also shows examples of code which helped me alot to get my head into python space :slight_smile:

Do you want colors set in materials or in vertex colors, UV map, etc.?

Does it matter if the “lines” have parallel ends, or is it okay for them to be skewed Thinking of a cylinder, its relatively easy to move the centers of the end caps to certain locations, and have them still remain parallel, but the line then becomes a parallelogram, not a rectangle, if you can visualize it. In an alternative method, though, it would be possible to scale the cylinder to the proper magnitude and rotate it appropriately such that it remains a “non-skewed” line.

Or would a wireframe type render work, rendering only edges, and also reducing vertex cost?

Would it not be better to create curve objects?
The Hang Curve Script form ED comes to mind.
It Makes a curve between two points.
You can adjust the parameters to make the curve straight.

Meta,
That link is dead. Or at least the link to the script on the page you mention. It also has an obscene external dependency.

Is that script part of Elephants Dream DVD?

Atom,
Sorry, the link is good now.