0
$\begingroup$

I am trying to run a custom script when Blender starts.

My script location is

C:\Program Files (x86)\Blender Foundation\Blender\2.70\scripts\startup

My idea is to start a TCP server on Blender start up, but Blender is complaining:

NameError: name 'register' is not defined

This is my script:

import bpy
import socketserver

class MyTCPHandler(socketserver.BaseRequestHandler):

def handle(self):
    # self.request is the TCP socket connected to the client
    self.data = self.request.recv(1024).strip()
    print("{} wrote:".format(self.client_address[0]))
    print(self.data)
    # just send back the same data, but upper-cased
    self.request.sendall("[MOVE]MessageReceived[END]")

def register():
    bpy.utils.register_class(MyTCPHandler)

def unregister():
    bpy.utils.unregister_class(MyTCPHandler)

if __name__ == "__main__":

    register()  

    # Create the server, binding to localhost on port 9999
    server = socketserver.TCPServer(("localhost", 9999), MyTCPHandler)

    # Activate the server; this will keep running until you
    # interrupt the program with Ctrl-C
    server.serve_forever()
$\endgroup$

1 Answer 1

1
$\begingroup$

The script has a few issues, first indentation seems not correct and seems to cause the error (could be caused by copy and paste).

Python relies on the indentation of code because it doesn't use braces to separate code segments syntactically.

Before a class can be registered as an operator the class must be inherit from bpy.types.Operator or bpy.types.Menu (see the docs whether there're more options).

The socketserver constructor is not invoked.

Related:

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .