Hi,
“For” loops work… e.g.
for i in range(3):
for j in range(4):
print j
works as expected. (Note: copying and pasting from this webpage into Blender doesn’t seem to work… perhaps the newline characters don’t get imported… so you might need to retype my code)
The output:
‘import site’ failed; use -v for traceback
Using a clean Global Dictionary.
Run Python script “Text” …
0
1
2
3
0
1
2
3
0
1
2
3
But ones that involve meshes don’t.
Here’s some examples:
import Blender
selectionList = Blender.Object.getSelected()
mesh = selectionList[0].data
for v in mesh.vert:
print v[0]
The output:
Using a clean Global Dictionary.
Run Python script “Text” …
warning: The Object.getSelected() function will be removed in Blender 2.29
Please update the script to use Object.GetSelected
In Object_GetSelected()
Traceback (most recent call last):
File “Text”, line 5, in ?
AttributeError: vert
‘import site’ failed; use -v for traceback
import Blender
selectionList = Blender.Object.getSelected()
mesh = selectionList[0].data
for v in mesh.verts:
for i in range(3):
print v[i]
The output:
Using a clean Global Dictionary.
Run Python script “Text” …
warning: The Object.getSelected() function will be removed in Blender 2.29
Please update the script to use Object.GetSelected
In Object_GetSelected()
1.0
0.999999940395
0.0
Traceback (most recent call last):
File “Text”, line 6, in ?
ImportError: No module named warnings
‘import site’ failed; use -v for traceback
(Line 6 becomes highlighted - it is the inner loop)
It should print the coordinates of all 4 vertices in the plane - not just halt like that…
import Blender
selectionList = Blender.Object.getSelected()
mesh = selectionList[0].data
for v in mesh.verts:
for i in range(3):
for j in range(5):
print v[i]
This should print each component of the coordinates five times. Instead it prints the first coordinate component once, and halts. The innermost loop is highlighted.
The output:
Using a clean Global Dictionary.
Run Python script “Text” …
warning: The Object.getSelected() function will be removed in Blender 2.29
Please update the script to use Object.GetSelected
In Object_GetSelected()
1.0
1.0
1.0
1.0
1.0
Traceback (most recent call last):
File “Text”, line 7, in ?
ImportError: No module named warnings
‘import site’ failed; use -v for traceback
import Blender
selectionList = Blender.Object.getSelected()
mesh = selectionList[0].data
for v in mesh.verts:
print v[0]
print v[1]
print v[2]
print "Loop finished"
The output:
Using a clean Global Dictionary.
Run Python script “Text” …
warning: The Object.getSelected() function will be removed in Blender 2.29
Please update the script to use Object.GetSelected
In Object_GetSelected()
1.0
0.999999940395
0.0
1.0
-1.0
0.0
-1.00000011921
-0.999999821186
0.0
-0.999999642372
1.00000035763
0.0
Traceback (most recent call last):
File “Text”, line 5, in ?
ImportError: No module named warnings
‘import site’ failed; use -v for traceback
It goes through the one and only loop in that script properly, but it then halts, and highlights the “for” statement as usual. It doesn’t print that last part of the script.