BGE Error: 'VideoTexture.Texture' object has no attribute 'materialID' - python

I tried to change the texture of an object in the blender game engine.
I thought it would be a good idea to use the Texture Replacement from the Video Texture (bge.texture).
I tried to run the following script:
def createTexture(cont):
obj = cont.owner
# get the reference pointer (ID) of the internal texture
ID = texture.materialID(obj, 'Kraftwerk2.png')
# create a texture object
object_texture = texture.Texture(obj, ID)
# create a new source with an external image
url = logic.expandPath(new_file)
new_source = texture.ImageFFmpeg(url)
# the texture has to be stored in a permanent Python object
logic.texture = object_texture
# update/replace the texture
logic.texture.source = new_source
logic.texture.refresh(False)
def removeTexture(cont):
"""Delete the Dynamic Texture, reversing back the final to its original state."""
try:
del logic.texture
except Exception as e:
print(e)
but it failed with the following error message:
Python script error - object 'Plane', controller 'Python': Traceback
(most recent call last): File
"F:\Benutzer\Merlin\MW-Industries\Blender
Dateien\Cinema\Render-Blend\MoonSpace.ble nd\Test.py", line 19, in
createTexture AttributeError: 'VideoTexture.Texture' object has no
attribute 'materialID'
Is there a way to solve the problem?

Related

AttributeError: 'Image' object has no attribute 'frame'

I am trying to save images from Carla in my disk, but I receive this error on the terminal.
Traceback (most recent call last):
File "carla_basic_tutorial.py", line 83, in <lambda>
'out%02d/%06d.png' % (n_output, image.frame)
AttributeError: 'Image' object has no attribute 'frame'
I have already installed the libraries from requirements files and Pillow too, the drivers of GPU were installed.
The part of code is available below
# Spawn the camera and attach it to the vehicle
camera = world.spawn_actor(
camera_bp,
camera_transform,
attach_to=vehicle
)
actor_list.append(camera)
print('created %s' % camera.type_id)
# Check how much "out" folders already exists
n_output = len([d for d in os.listdir() if d.startswith('out')])
# Sets the function that will be called by the camera
# This will save the images to disk at a "out" folder
camera.listen(lambda image: image.save_to_disk(
'out%02d/%06d.png' % (n_output, image.frame)
))
The full code is available here Full code
I solved this using the attribute image.frame_number
camera.listen(lambda image: image.save_to_disk(
'out%02d/%06d' % (n_output, image.frame_number)
))

Python - a type error caused by what?

In Python 3, I am trying to connect attributes of an object to equivalent attributes of its proxy object (identified by its "_proxy" suffix).
Here's the code:
import maya.cmds as mc
attributes = ['.t', '.r', '.s']
controllers = mc.ls('ctrl_Lip*')
def corresponding_proxy(controller):
corresponding_proxy = mc.ls(controller+'_proxy')
return corresponding_proxy
for controller in controllers :
for attr in attributes :
mc.connectAttr(controller+attr, corresponding_proxy(controller)+attr)
The error returned is :
# Error: TypeError: file <maya console> line 13: can only concatenate list (not "str") to list #
I don't understand, because I thought controller, corresponding_proxy and attr were all strings.
What did I miss?
Ok jasonharper is right, returning controller+'_proxy' makes it work !
However it now throws another error at me :
# Error: RuntimeError: file <maya console> line 14: The destination attribute 'ctrl_Lip_Up_1_proxy_proxy.t' cannot be found. #
...and it's not doing the operation on the entire list of objects, just the first one and then there's the error.
Ok nevermind ! The ´ls´ command also returned the proxies I had created, so my loop was trying to iterate over the proxies themselves as well...
Thanks a lot everybody ! Solved !
This is the working code :
import maya.cmds as mc
attributes = ['.t', '.r', '.s']
controllers = mc.ls('ctrl_Lip*', tr=True)
for controller in controllers:
mc.duplicate(controller, n=controller+'_proxy')
def corresponding_proxy(controller):
return controller+'_proxy'
for controller in controllers:
for attr in attributes:
mc.connectAttr(controller+attr, corresponding_proxy(controller)+attr)

Python Tkinter Attribute Error

I have made a tkinter program where i keep getting this error:
File "F:\Programming 2\Gui\Gui #11.py", line 78, in shape_workit
cylinder(pos=(0,0,0),axis=(1,0,0),color=self.color3.get(),
AttributeError: 'Kinter' object has no attribute 'color3'
Here is the code which the error occurs from:
def shapescolor(self):
if self.color1.get()=="Does a Orange":
color3=color.orange
if self.color1.get()=="Does a Blue":
color3=color.blue
def shape_workit(self):
try:
if self.shape.get()=="Does a Cylinder": #Creates Cylinder
cylinder(pos=(0,0,0),axis=(1,0,0),color=self.color3.get() ##ERROR HERE,
radius=float(self.radius.get()))
Here is the Code where the error it gets from
My guess is that you need to be doing self.color3 = ... rather than color3 = ..., since you're later refering to self.color3 and haven't set that attribute anywhere else in the code you posted.

How can I create an Exception in Python minus the last stack frame?

Not sure how possible this is, but here goes:
I'm trying to write an object with some slightly more subtle behavior - which may or may not be a good idea, I haven't determined that yet.
I have this method:
def __getattr__(self, attr):
try:
return self.props[attr].value
except KeyError:
pass #to hide the keyerror exception
msg = "'{}' object has no attribute '{}'"
raise AttributeError(msg.format(self.__dict__['type'], attr))
Now, when I create an instance of this like so:
t = Thing()
t.foo
I get a stacktrace containing my function:
Traceback (most recent call last):
File "attrfun.py", line 23, in <module>
t.foo
File "attrfun.py", line 15, in __getattr__
raise AttributeError(msg.format(self._type, attr))
AttributeError: 'Thing' object has no attribute 'foo'
I don't want that - I want the stack trace to read:
Traceback (most recent call last):
File "attrfun.py", line 23, in <module>
t.foo
AttributeError: 'Thing' object has no attribute 'foo'
Is this possible with a minimal amount of effort, or is there kind of a lot required? I found this answer which indicates that something looks to be possible, though perhaps involved. If there's an easier way, I'd love to hear it! Otherwise I'll just put that idea on the shelf for now.
You cannot tamper with traceback objects (and that's a good thing). You can only control how you process one that you've already got.
The only exceptions are: you can
substitute an exception with another or re-raise it with raise e (i.e make the traceback point to the re-raise statement's location)
raise an exception with an explicit traceback object
remove outer frame(s) from a traceback object by accessing its tb_next property (this reflects a traceback object's onion-like structure)
For your purpose, the way to go appears to be the 1st option: re-raise an exception from a handler one level above your function.
And, I'll say this again, this is harmful for yourself or whoever will be using your module as it deletes valuable diagnostic information. If you're dead set on making your module proprietary with whatever rationale, it's more productive for that goal to make it a C extension.
The traceback object is created during stack unwinding, not directly when you raise the exception, so you can not alter it right in your function. What you could do instead (though it's probably a bad idea) is to alter the top level exception hook so that it hides your function from the traceback.
Suppose you have this code:
class MagicGetattr:
def __getattr__(self, item):
raise AttributeError(f"{item} not found")
orig_excepthook = sys.excepthook
def excepthook(type, value, traceback):
iter_tb = traceback
while iter_tb.tb_next is not None:
if iter_tb.tb_next.tb_frame.f_code is MagicGetattr.__getattr__.__code__:
iter_tb.tb_next = None
break
iter_tb = iter_tb.tb_next
orig_excepthook(type, value, traceback)
sys.excepthook = excepthook
# The next line will raise an error
MagicGetattr().foobar
You will get the following output:
Traceback (most recent call last):
File "test.py", line 49, in <module>
MagicGetattr().foobar
AttributeError: foobar not found
Note that this ignores the __cause__ and __context__ members of the exception, which you would probably want to visit too if you were to implement this in real life.
You can get the current frame and any other level using the inspect module. For instance, here is what I use when I'd like to know where I'm in my code :
from inspect import currentframe
def get_c_frame(level = 0) :
"""
Return caller's frame
"""
return currentframe(level)
...
def locate_error(level = 0) :
"""
Return a string containing the filename, function name and line
number where this function was called.
Output is : ('file name' - 'function name' - 'line number')
"""
fi = get_c_frame(level = level + 2)
return '({} - {} - {})'.format(__file__,
fi.f_code,
fi.f_lineno)

VLC python module not working in Ubuntu

I have code like this
import vlc # no error
Instance = vlc.Instance() # no error
MediaPlayer = Instance.media_player_new() # error triggered here
the error message is
Instance.media_player_new()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "vlc.py", line 895, in media_player_new
p._instance = self
AttributeError: 'NoneType' object has no attribute '_instance'
I am using python 2.6
Whats the problem with my code?
Looks like a bug. I did a peek into the code at https://github.com/geoffsalmon/vlc-python/blob/master/generated/vlc.py (see snippets below).
Looks like media_player_new calls libvlc_media_player_new( self ) and libvlc_media_player_new calls the native libvlc_media_player_new( ... ) function. This function returns NULL which results in None and the further code fails.
According to the doc string NULL will be returned if an error occurs. Maybe you could enable logging via the libvlc_log functions and see what's going wrong. Refer to http://www.videolan.org/developers/vlc/doc/doxygen/html/group_libvlc_log.html
EDIT: it looks like that you can set up logging via vlc.py, too. (You shouldn't need native calls then)
def media_player_new(self, uri=None):
"""Create a new MediaPlayer instance.
#param uri: an optional URI to play in the player.
"""
p = libvlc_media_player_new(self)
if uri:
p.set_media(self.media_new(uri))
p._instance = self
return p
and
def libvlc_media_player_new(p_libvlc_instance):
'''Create an empty Media Player object.
#param p_libvlc_instance: the libvlc instance in which the Media Player should be created.
#return: a new media player object, or NULL on error.
'''
f = _Cfunctions.get('libvlc_media_player_new', None) or \
_Cfunction('libvlc_media_player_new', ((1,),), class_result(MediaPlayer),
ctypes.c_void_p, Instance)
return f(p_libvlc_instance)

Categories

Resources