Report problems with the new Python API here please!

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Fri Aug 22, 2003 9:38 am

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.

breakin
Posts: 0
Joined: Fri Aug 22, 2003 3:33 am

Documentation bug

Post by breakin » Sat Aug 23, 2003 7:19 pm

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 :)

wahn
Posts: 15
Joined: Fri Nov 15, 2002 10:27 pm
Location: London
Contact:

Vertices

Post by wahn » Wed Sep 03, 2003 7:08 pm

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

Michel
Posts: 180
Joined: Wed Oct 16, 2002 7:27 pm
Location: Somewhere below the rivers in Holland (but not Limburg)

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

Post by Michel » Thu Sep 04, 2003 10:13 am

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
You can have one of two things: Progress or Progress Reports.

Michel
Posts: 180
Joined: Wed Oct 16, 2002 7:27 pm
Location: Somewhere below the rivers in Holland (but not Limburg)

Post by Michel » Thu Sep 04, 2003 10:14 am

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
You can have one of two things: Progress or Progress Reports.

Michel
Posts: 180
Joined: Wed Oct 16, 2002 7:27 pm
Location: Somewhere below the rivers in Holland (but not Limburg)

Re: Vertices

Post by Michel » Thu Sep 04, 2003 10:16 am

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
You can have one of two things: Progress or Progress Reports.

assassin
Posts: 0
Joined: Sat Aug 09, 2003 12:47 pm

How can I get the image path

Post by assassin » Mon Sep 22, 2003 7:03 pm

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]

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Mon Sep 22, 2003 10:48 pm

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.

assassin
Posts: 0
Joined: Sat Aug 09, 2003 12:47 pm

Post by assassin » Fri Sep 26, 2003 7:03 pm

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

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Sat Sep 27, 2003 4:46 am

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.

assassin
Posts: 0
Joined: Sat Aug 09, 2003 12:47 pm

Post by assassin » Sun Sep 28, 2003 4:58 pm

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.

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Sun Sep 28, 2003 8:03 pm

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).

z3r0_d
Posts: 289
Joined: Wed Oct 16, 2002 2:38 am
Contact:

Post by z3r0_d » Mon Sep 29, 2003 12:48 am

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

theeth
Posts: 500
Joined: Wed Oct 16, 2002 5:47 am
Location: Montreal
Contact:

Post by theeth » Mon Sep 29, 2003 1:05 am

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
Life is what happens to you when you're busy making other plans.
- John Lennon

z3r0_d
Posts: 289
Joined: Wed Oct 16, 2002 2:38 am
Contact:

Post by z3r0_d » Mon Sep 29, 2003 3:31 am

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

Locked