Page 4 of 5

Posted: Fri Aug 22, 2003 9:38 am
by stiv
breakin wrote:myObject=Blender.Object.Get('myObjectName')
myObject.setName('myNewObjectName') # line 4

fails (blender 2.28a, rh9) with the following error:

Traceback (most recent call last):
File "Text.001", line 4, in ?
AttributeError: expected a String as argument
It appears to be broken. ( or maybe the interpreter just didn't like the name you chose. heehee )

The Object.setName() method is calling PyArg_Parse() rather than PyArg_ParseTuple() to get its arguments. PyArg_Parse is an older func, maybe left over from an earlier implementation.

I sent a patch to the bf-python list.

Documentation bug

Posted: Sat Aug 23, 2003 7:19 pm
by breakin
Under NVerts you state that the normal shoudl be obtained using

vert.no.nx but it should be vert.no.x. Types for uvco is omitted. Suppose all of this will be clarified over time during the iterative documentation process :)

Vertices

Posted: Wed Sep 03, 2003 7:08 pm
by wahn
Why do I get 4 coordinates with NMVert (even though the length of the vector object is 3)?

Try this to see what I mean:

Code: Select all

import Blender

# get the current scene
scene = Blender.Scene.getCurrent()
# loop over all objects in the scene
children = scene.getChildren()
print "%s children" % len(children)
for child in children:
    print child
    # which type?
    type = child.getType()
    if type == "Mesh":
        # mesh
        print "I'm a mesh"
        data = child.getData()
        print data
        print dir(data)
        print "name: %s" % data.name
        print "verts: %s" % len(data.verts)
        for vertex in data.verts:
            print "%s: %s" % (len(vertex.loc), vertex.loc)
        print "faces: %s" % len(data.faces)
        for face in data.faces:
            vertices = face.v
            print "face: [",
            for vertex in vertices:
                print vertex.index,
            print "]"
    else:
        print "type: %s ..." % type
        print "... not handled (yet)"
Cheers,

Jan

Re: Report problems with the new Python API here please!

Posted: Thu Sep 04, 2003 10:13 am
by Michel
wahn wrote:Hi Michael,

First of all: Thanks that someone took care about the Python API !!! :wink:
Hi,

actually, my name is Michel :)
Luckily I'm not the only one who's actively working on the Python API; many others are jumping in!

About the bug report with regards to argument parsing: This is fixed in cvs now. Apparently some more issues where in the code. I have not tested these functions very well :oops:

Thanks for reporting this!!!

With regards,
Michel

Posted: Thu Sep 04, 2003 10:14 am
by Michel
breakin wrote:myObject=Blender.Object.Get('myObjectName')
myObject.setName('myNewObjectName') # line 4

fails (blender 2.28a, rh9) with the following error:

Traceback (most recent call last):
File "Text.001", line 4, in ?
AttributeError: expected a String as argument
Hi,

this has been fixed in cvs. Thanks for reporting.

With regards,
Michel

Re: Vertices

Posted: Thu Sep 04, 2003 10:16 am
by Michel
wahn wrote:Why do I get 4 coordinates with NMVert (even though the length of the vector object is 3)?
Hi,

this has been fixed by IanWill just 2 or 3 days ago! Weehaa, I like progress! :D
Thanks for reporting though!

With regards,
Michel

How can I get the image path

Posted: Mon Sep 22, 2003 7:03 pm
by assassin
Hi. I wanna know how can I get the path of an image.
But all I get is that the object has no image [none]

Posted: Mon Sep 22, 2003 10:48 pm
by stiv
A quick test with 2.28a seems to work:

Code: Select all

image = Image.Load('some_file_name')
print image.getFilename()
Tell us what version of blender and show us a code snippet.

Posted: Fri Sep 26, 2003 7:03 pm
by assassin
stiv wrote:A quick test with 2.28a seems to work:

Code: Select all

image = Image.Load('some_file_name')
print image.getFilename()
Tell us what version of blender and show us a code snippet.
I use blender 2.28 and I'm not sure about this cause I'm not realy using
Image.Load .
When I make an object let's say a machine gun I use that
Add material and add texture from the buttons window and not telling
blender through phyton that I wanna have the image from this path

Posted: Sat Sep 27, 2003 4:46 am
by stiv
Even with my psychotic powers, I can't tell what is going on without seeing some code. However, this snippet prints the filenames of Image blocks that were created for image textures via the buttons:

Code: Select all

images = Blender.Image.Get()
for img in images:
    print img.getFilename()
A goal of the python api is to provide programmatic access to blender data. It shouldn't matter whether it was created via the buttons or via python.

Posted: Sun Sep 28, 2003 4:58 pm
by assassin
stiv wrote:Even with my psychotic powers, I can't tell what is going on without seeing some code. However, this snippet prints the filenames of Image blocks that were created for image textures via the buttons:

Code: Select all

images = Blender.Image.Get()
for img in images:
    print img.getFilename()
A goal of the python api is to provide programmatic access to blender data. It shouldn't matter whether it was created via the buttons or via python.
What I wanted to do is to loop through all objects and write into file
their image paths. But when I use

data=SelectedObjects[index].getData()
faces=data.faces

print faces[0].image // result is [none]
And that's the problem. I wanna loop through all selected objecs and
get those image objects so I could know which face uses which image.
How can I use opengl on it when I don't know what texture file they use.

Posted: Sun Sep 28, 2003 8:03 pm
by stiv
Aha! I think I see the problem. Question: Do your mesh faces have a UV texture?

Images can be used as Textures in a Material block, rather like glueing the image on the whole object. Images can also be used for UV Textures. This is like cutting the image up and applying it to individual mesh faces.

Your code looks ok. ( you may want to use face[0].image.getFilename() to get the complete path ).

From the recent bpython doc for NMesh.NMFace:

Warning: Assigning uv textures to mesh faces in Blender works like this:
Select your mesh.
Enter face select mode (press f) and select at least some face(s).
In the UV/Image Editor window, load / select an image.
Play in both windows (better split the screen to see both at the same time) until the uv coordinates are where you want them. Hint: in the 3d window, the 'u' key opens a menu of default uv choices and the 'r' key lets you rotate the uv coords.
Leave face select mode (press f).

Posted: Mon Sep 29, 2003 12:48 am
by z3r0_d
bah, about time I complain here I guess

a number of functions have different names, or maybe not, but it is annoying

coming to mind is:

Blender.Window.draw_progressbar(...) from Blender.Windows.DrawProgressBar(...)

bah, you could probably do some hack python diff thing on different versions of blender (probably a good idea anyway) but it is annoying.

maybe I will, no guarntees

Posted: Mon Sep 29, 2003 1:05 am
by theeth
just add this at the start of the script:

Code: Select all

Blender.Windows.draw_progressbar = Blender.Windows.DrawProgressBar
same goes for all the other renamed function. It's not really harder than the import blender210 as blender fix.

Martin

Posted: Mon Sep 29, 2003 3:31 am
by z3r0_d
theeth wrote:just add this at the start of the script:

Code: Select all

Blender.Windows.draw_progressbar = Blender.Windows.DrawProgressBar
same goes for all the other renamed function. It's not really harder than the import blender210 as blender fix.

Martin
yeah, but I don't like to have to search for the function again