string to vector with numpy?

Hi again,

have some problems with setting up this string:

[0.0, -0.0, 0.0] #just an example

to an numpy.array

don’t know if this possible because I need it for orientation an object

one more example:



camera_orientation = self.send_camori #send_camori is an shorted string from an long line. shorted with [1:-1] (example)
#yes of course it is converted with .to_euler()

print(camera_orientation)# this prints [0.0, 0.0, 0.0]
xyz = numpy.array(camera_orientation)

#and want to use xyz like this
avatar_cam_obj.worldOrientation = xyz

don’t know if I have to convert it before to an vector or else,
and when how?

You don’t need to use numpy here. Your code extract looks like a copy of different examples of programs, (what is self here?).
You shouldn’t need to convert a string to anything, unless you’re trying to configure vectors from the GUI (which makes little sense).


from mathutils import Euler
from math import radians

x = radians(45)
y = radians(90)
z = radians(120)

some_orientation = Euler((x, y, z))
some_obj.worldOrientation = some_orientation

not really working,

I have a string that is created by this line
OriCam = list(own.worldOrientation.to_euler())

now I convert it with this
ori = str([“€€€”, OriCam])



if "€€€" in self.chattext:
     camera_orientation = self.chattext[9:-2]
     camxyz = list(camera_orientation.split(", "))
     #xyz = numpy.array(camera_orientation)
     #print(camera_orientation)
     #some_orientation = Euler((camxyz))
                            
      newaddr = str(user.name)
                            
      camx = math.radians(camxyz[0])
      camy = math.radians(camxyz[1])
      camz = math.radians(camxyz[2])
      print(camx, camy, camz)


the last thing isn’t working

I want to reach

avatar_cam_obj.worldOrientation = camxyz

ok get it

camx = Euler((float(camxyz[0]), float(camxyz[1]), float(camxyz[2])))

So, you’re parsing this from a string on purpose, then.

something to handle “45, 0, 0”:

from mathutils import *
from math import radians


def degree_string_to_euler(text):
    return Euler((radians(float(x)) for x in text.strip().split(',')))

Yes. If you want to put something in a string, send it and recover it later you have to format it clearly. I usually use a symbol to keep entries in a string separate.
Something like;
my_ori = “$”.join(str(number) for number in list(camera.worldOrientation))

Then
orientation = mathutils.Vector ([float(number) for number in my_ori.split("$")])

ok thank you all have solved it with:



                        if "€€€" in self.chattext:
                            try:
                                camera_orientation = self.chattext[9:-2]
                                camxyz = list(camera_orientation.split(", "))
                                
                                newaddr = str(user.name)
                                
                                cam_orientation_new = Euler((float(camxyz[0]), float(camxyz[1]), float(camxyz[2])))
                                
                                for l, i in self.camavatarlist.items():
                                    if newaddr in i:
                                        self.avatar_cam_obj = objList.from_id(l)

                                try:
                                    self.avatar_cam_obj.worldOrientation = cam_orientation_new          
                                    self.avatar_cam_obj.children[0]
                                    #print("yup")
                                except:
                                    print("no cam")
                                    pass
                                return


it is a part of a long server receive.script on an server window (not that efficient but working well)

so thank for help