Noob question

Hi this is probably a silly noob question, but to learn you have to ask, rigth?
I’ve made script that generates a list like this [1, 2] what do I do if I want to use only one of the values in another part of my script, and not both of them. Like if I want another part of the script to know that 1 is 1 and that 2 is 2 and use this information to do stuff.

Like this?

a = [1, 2]

print a
print a[0]
print a[1]

no, like this


import Blender
from Blender import Image
image = Image.Load("C:\path")
image.getSize()

image.getSize() returna a kind of list over the lengths of the two akses in the picture (x, y) I would like to use these values induvidualy.

well, I figured out how to use your answer Xjazz, thanks for that :slight_smile: I will probably post more questions in this tread when they come up…

You could say:

x,y = image.getSize()

to unpack the list, or you could do

size = image.getSize()

size[0], size[1]

to get things out.

New question about the same ting !!
How do I do the same thing if I have a list like this [[1, 2], [3, 4]]

Indexes nest, so if you have a list like that and you want the first element of the first list it would be like:

list = [[1, 2], [3, 4]]
elem = list[0][0]

what does ubsubscriptabele means?

That means your trying to subscript an object which does not support retrieving values via subscripts like:

var = 2
var[0] = 1

would give you an error because var is an integer, not a list, dictionary, set, etc which are iterable types (you can move over the elements contained within them).

I’m trying to use this for making a line betweentwo points, the code realy is like this:


p1 = [1, 0, 0]
p2 = [0, 0, 0]
 
verts = [p1,p2]
faces = [0, 1]
 
ob = B.Object.New('Mesh', 'Meshob')
me = B.Mesh.New('myMesh')
me.verts.extend( verts )
me.faces.extend( faces )
ob.link( me )
 
scene = B.Scene.GetCurrent()
scene.link( ob )
 
B.Redraw(-1)

but I want the xy coordinates in p1 and p2 to vary in diferent situations, depending on the xy coordinates of one pixel, using the match.append([x,y]) to get the coordinates. How do I do that?

I’m having a hard time understanding what your trying to do (not the connection part, the image part). Im wondering what your this “match.append([x,y])” you mentioned is (obviously its a list your trying to append to, but what are you trying to do with this list once its been appended to). Could you explain a little more clearly?

Also the code you posted could be modernized some with:


p1 = [1, 0, 0]
p2 = [0, 0, 0]
 
verts = [p1,p2]
faces = [0, 1]
 
me = B.Mesh.New('myMesh')
me.verts.extend( verts )
me.faces.extend( faces )
 
scene = B.Scene.GetCurrent()
scene.objects.new(me, 'MeshOb')
 
B.Redraw(-1)

I am trying to use the coordinates from one spesific pixel in p1 an another in p2. I’ve got the coordinates, but they are of cause only x,y coordinates, the other problem is that I dont know how to make the program use only the x,y coordinates with zero in the z angle
so what I kind of want the program to do is this, the names of the coordinates in this example is qwer in stead of xy to illustrate that it is different coordinates.
p1 = [q, w, 0]
p2 = [e, r, 0]

p1 and p2 coordinates is given like this p1 = [x, y, z]
I could also code it like this, in stead of using the p1 and p2


verts = [[1, 0, 0], [0, 0, 0]]
faces = [0, 1]
 
me = B.Mesh.New('myMesh')
me.verts.extend( verts )
me.faces.extend( faces )
 
scene = B.Scene.GetCurrent()
scene.objects.new(me, 'MeshOb')
 
B.Redraw(-1)

Do you understand it now?


#or set from wherever
p1=[1,2,0]

p2=[p1[0], p1[1], 0]
#p2 is now [1,2,0]

If you have q,w,e,r already, then what you posted would work just fine:


p1 = [q, w, 0]
p2 = [e, r, 0] 

I don’t think you understand my question, if it isn’t me who don’t understand the answer, could we discuss this on msn or something?
You migth be interested in that I am using this help in my project that has as a goal to program software to a simpel laser 3d scanner. Anyone that wants to help me, please contact me on mail or msn.
my adress is [email protected]

What are you actually trying to do?

I’ve got the coordinates, but they are of cause only x,y coordinates, the other problem is that I dont know how to make the program use only the x,y coordinates with zero in the z angle

So you want to take (x,y) and turn it into [x,y,0]?

It would help if you gave an example, like:
By this point in the program, I have found x and y to be 3 and 5.
I want p1 to be [3,5,0] and p2 to be [5,3,0]

Cheers,
Ian

Ok, it’s time to put out the script.


import Blender as B
from Blender import Image
import timeit
 
image = Image.Load("C:\color.psd")
print "Image from", image.getFilename()
print "loaded to obj", image.getName()
 
image.setXRep(4)
image.setYRep(2)
print "All Images available no2", Image.Get()
print "Size", image.getSize()
print image.getPixelI(0,0)
 
a = image.getSize
yaks =a[0]
xaks = a[1]
 
match = []
for y in range(yaks):
        for x in range(xaks)
                if image.getPixelI8x, y) == [224, 38, 14, 255]:
                        match.aooend([x,y])
print match
 
p1 =[match[0], 0]
p2 =[match[1], 0]
 
verta = [p1, p2]
faces = [0, 1]
 
me = = B.Mesh.New('myMesh')
me.verts.extend( verts )
me.faces.extend( faces )
 
scee = B.Scene.GetCurrent()
scene.objects.new(me, 'MeshOb')
 
B.Redraw(-1)

well, the problem is that it don’t work. print match print this [[23, 23], [23, 29]], that is the x,y coordinates I want p1 and p2 to be in, how should I make it do that?


p1=[match[0][0],match[0][1],0]
p2=[match[1][0],match[1][1],0]

Lists are nested in python.

thanks man.
new question. how do I automaticaly make one new point (p3,p4,p5, and so on) for each pixel with the [224, 38, 14, 255] color?
The best way to explain what I want it to do now is to automaticly make this if I have five points with the [224, 38, 14, 255] color.


p1 = [match[0][0],match[0][1], 0]
p2 = [match[1][0],match[1][1], 0]
p3 = [match[2][0],match[2][1], 0]
p4 = [match[3][0],match[3][1], 0]
p5 = [match[4][0],match[4][1], 0]

so I guess what I realy tries to do is sort of this:


for y in range(yaks):
        p+1 = [match[0+1][0],match[1+1][1],0]

and then sort of ad one to the numbers I’ve written +1 behind for each times it repeats. but I get a syntax error: can’t assign to operator
So can anybody tell me how to do this properly and working?

No worries.

You can either use "exec(“code goes here)” to compile and run code on the fly, but you’ll be left with loads of variables lying around the place. You could just build a new list.


p=[]
for i in range(blah):
    p.append( [match[i][0],match[i][1],0] )

#or do this
for item in match:
    p.append([item[0],item[1],0])

#then you can use 
me.verts.extend(p)

thanks!
Now I got a bunch of points, I have to get lines between them, do you thing I could use this http://www.blender.org/documentation/242PythonDoc/Geometry-module.html to make these lines, if not, what should I do?