Skip to main content
added 43 characters in body
Source Link
unutbu
  • 350
  • 3
  • 11
import multiprocessing as mp
import socket
import sys
import bpy
import time
import threading
from xmlrpc.server import SimpleXMLRPCServer
import xmlrpc.client
bl_info = {
    "name": "XMLRPC Server",
    "author": "KristenH",
    "version": (0, 5, 0, 1),
    "blender": (2, 79, 0),
    "category": "System"
}


HOST = 'localhost'
PORT = 8000

class SimpleServer(SimpleXMLRPCServer):
    pass


def command(com):
    com = 'import bpy\n'+com
    exec(com)
    return com
 

def server_data():
    return bpy.app.version_string, bpy.context.blend_data.filepath, socket.gethostname()


class ServerPanel(bpy.types.Panel):
    bl_label = "Server Panel"
    bl_idname = "Object_PT_server"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_category = "Shortcuts"
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")

    def draw(self, context):
        layout = self.layout
        version_string, filepath, hostname = self.proxy.server_data()
        print('found server on', 'localhost:', hostname)
        layout.row().label(text="Server found on: {}:{}".format(hostname,PORT))
        layout.row().label(text="Press Ctrl-C in terminal to exit".format(hostname,PORT))        

def register():
    global thread
    proc = mp.Process(target=maybe_launch_server)
    proc.daemon = True
    proc.start()
    bpy.utils.register_class(ServerPanel)


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


def maybe_launch_server():
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
    try:
        result = proxy.server_data()
    except ConnectionRefusedError:
        server = SimpleServerSimpleXMLRPCServer((HOST, PORT))
        server.register_introspection_functions()
        server.register_function(command, "command")
        server.register_function(server_data, "server_data")
        version_string = bpy.app.version_string
        print("Started the server with:", HOST, ":", PORT)
        server.serve_forever()


if __name__ == "__main__":
    register()

This spawns the server as a separate process. proc.daemon = True causes the process to terminate when the calling process terminates. ThatOn the plus side, this means that whatever blender starts the server iswill terminate when you quit blender. On the "main" processnegative side, and when it terminates, so doesalso means you have to pay attention to which blender started the server (in case you launch multiple blenders).

import multiprocessing as mp
import socket
import sys
import bpy
import time
import threading
from xmlrpc.server import SimpleXMLRPCServer
import xmlrpc.client
bl_info = {
    "name": "XMLRPC Server",
    "author": "KristenH",
    "version": (0, 5, 0, 1),
    "blender": (2, 79, 0),
    "category": "System"
}


HOST = 'localhost'
PORT = 8000

class SimpleServer(SimpleXMLRPCServer):
    pass


def command(com):
    com = 'import bpy\n'+com
    exec(com)
    return com
 

def server_data():
    return bpy.app.version_string, bpy.context.blend_data.filepath, socket.gethostname()


class ServerPanel(bpy.types.Panel):
    bl_label = "Server Panel"
    bl_idname = "Object_PT_server"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_category = "Shortcuts"
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")

    def draw(self, context):
        layout = self.layout
        version_string, filepath, hostname = self.proxy.server_data()
        print('found server on', 'localhost:', hostname)
        layout.row().label(text="Server found on: {}:{}".format(hostname,PORT))
        layout.row().label(text="Press Ctrl-C in terminal to exit".format(hostname,PORT))        

def register():
    global thread
    proc = mp.Process(target=maybe_launch_server)
    proc.daemon = True
    proc.start()
    bpy.utils.register_class(ServerPanel)


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


def maybe_launch_server():
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
    try:
        result = proxy.server_data()
    except ConnectionRefusedError:
        server = SimpleServer((HOST, PORT))
        server.register_introspection_functions()
        server.register_function(command, "command")
        server.register_function(server_data, "server_data")
        version_string = bpy.app.version_string
        print("Started the server with:", HOST, ":", PORT)
        server.serve_forever()


if __name__ == "__main__":
    register()

This spawns the server as a separate process. proc.daemon = True causes the process to terminate when the calling process terminates. That means that whatever blender starts the server is the "main" process, and when it terminates, so does the server.

import multiprocessing as mp
import socket
import sys
import bpy
import time
import threading
from xmlrpc.server import SimpleXMLRPCServer
import xmlrpc.client
bl_info = {
    "name": "XMLRPC Server",
    "author": "KristenH",
    "version": (0, 5, 0, 1),
    "blender": (2, 79, 0),
    "category": "System"
}


HOST = 'localhost'
PORT = 8000

def command(com):
    com = 'import bpy\n'+com
    exec(com)
    return com

def server_data():
    return bpy.app.version_string, bpy.context.blend_data.filepath, socket.gethostname()


class ServerPanel(bpy.types.Panel):
    bl_label = "Server Panel"
    bl_idname = "Object_PT_server"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_category = "Shortcuts"
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")

    def draw(self, context):
        layout = self.layout
        version_string, filepath, hostname = self.proxy.server_data()
        print('found server on', 'localhost:', hostname)
        layout.row().label(text="Server found on: {}:{}".format(hostname,PORT))
        layout.row().label(text="Press Ctrl-C in terminal to exit".format(hostname,PORT))        

def register():
    global thread
    proc = mp.Process(target=maybe_launch_server)
    proc.daemon = True
    proc.start()
    bpy.utils.register_class(ServerPanel)


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


def maybe_launch_server():
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
    try:
        result = proxy.server_data()
    except ConnectionRefusedError:
        server = SimpleXMLRPCServer((HOST, PORT))
        server.register_introspection_functions()
        server.register_function(command, "command")
        server.register_function(server_data, "server_data")
        version_string = bpy.app.version_string
        print("Started the server with:", HOST, ":", PORT)
        server.serve_forever()


if __name__ == "__main__":
    register()

This spawns the server as a separate process. proc.daemon = True causes the process to terminate when the calling process terminates. On the plus side, this means that the server will terminate when you quit blender. On the negative side, it also means you have to pay attention to which blender started the server (in case you launch multiple blenders).

added 259 characters in body
Source Link
unutbu
  • 350
  • 3
  • 11

This spawns the server as a separate process. proc.daemon = True causes the process to terminate when the calling process terminates. That means that whatever blender starts the server is the "main" process, and when it terminates, so does the server.

This spawns the server as a separate process. proc.daemon = True causes the process to terminate when the calling process terminates. That means that whatever blender starts the server is the "main" process, and when it terminates, so does the server.

added 13 characters in body
Source Link
unutbu
  • 350
  • 3
  • 11
import multiprocessing as mp
import socket
import sys
import bpy
import time
import threading
from xmlrpc.server import SimpleXMLRPCServer
import xmlrpc.client
bl_info = {
    "name": "XMLRPC Server",
    "author": "KristenH",
    "version": (0, 5, 0, 1),
    "blender": (2, 79, 0),
    "category": "System"
}


HOST = 'localhost'
PORT = 8000

class SimpleServer(SimpleXMLRPCServer):
    pass


def command(com):
    com = 'import bpy\n'+com
    exec(com)
    return com


def server_data():
    return bpy.app.version_string, bpy.context.blend_data.filepath, socket.gethostname()


class ServerPanel(bpy.types.Panel):
    bl_label = "Server Panel"
    bl_idname = "Object_PT_server"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_category = "Shortcuts"
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")

    def draw(self, context):
        layout = self.layout
        version_string, filepath, hostname = self.proxy.server_data()
        print('found server on', 'localhost:', hostname)
        layout.row().label(text="Server found on: {}:{}".format(hostname,PORT))
        layout.row().label(text="Press Ctrl-C in terminal to exit".format(hostname,PORT))        

def register():
    global thread
    threadproc = threadingmp.ThreadProcess(target=maybe_launch_server)
    threadproc.daemon = FalseTrue
    threadproc.start()
    bpy.utils.register_class(ServerPanel)


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

    
def maybe_launch_server():
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
    try:
        result = proxy.server_data()
    except ConnectionRefusedError:
        server = SimpleServer((HOST, PORT))
        server.register_introspection_functions()
        server.register_function(command, "command")
        server.register_function(server_data, "server_data")
        version_string = bpy.app.version_string
        print("Started the server with:", HOST, ":", PORT)
        server.serve_forever()


if __name__ == "__main__":
    register()
import socket
import sys
import bpy
import time
import threading
from xmlrpc.server import SimpleXMLRPCServer
import xmlrpc.client
bl_info = {
    "name": "XMLRPC Server",
    "author": "KristenH",
    "version": (0, 5, 0, 1),
    "blender": (2, 79, 0),
    "category": "System"
}


HOST = 'localhost'
PORT = 8000

class SimpleServer(SimpleXMLRPCServer):
    pass


def command(com):
    com = 'import bpy\n'+com
    exec(com)
    return com


def server_data():
    return bpy.app.version_string, bpy.context.blend_data.filepath, socket.gethostname()


class ServerPanel(bpy.types.Panel):
    bl_label = "Server Panel"
    bl_idname = "Object_PT_server"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_category = "Shortcuts"
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")

    def draw(self, context):
        layout = self.layout
        version_string, filepath, hostname = self.proxy.server_data()
        print('found server on', 'localhost:', hostname)
        layout.row().label(text="Server found on: {}:{}".format(hostname,PORT))
        layout.row().label(text="Press Ctrl-C in terminal to exit".format(hostname,PORT))        

def register():
    global thread
    thread = threading.Thread(target=maybe_launch_server)
    thread.daemon = False
    thread.start()
    bpy.utils.register_class(ServerPanel)


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

    
def maybe_launch_server():
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
    try:
        result = proxy.server_data()
    except ConnectionRefusedError:
        server = SimpleServer((HOST, PORT))
        server.register_introspection_functions()
        server.register_function(command, "command")
        server.register_function(server_data, "server_data")
        version_string = bpy.app.version_string
        print("Started the server with:", HOST, ":", PORT)
        server.serve_forever()


if __name__ == "__main__":
    register()
import multiprocessing as mp
import socket
import sys
import bpy
import time
import threading
from xmlrpc.server import SimpleXMLRPCServer
import xmlrpc.client
bl_info = {
    "name": "XMLRPC Server",
    "author": "KristenH",
    "version": (0, 5, 0, 1),
    "blender": (2, 79, 0),
    "category": "System"
}


HOST = 'localhost'
PORT = 8000

class SimpleServer(SimpleXMLRPCServer):
    pass


def command(com):
    com = 'import bpy\n'+com
    exec(com)
    return com


def server_data():
    return bpy.app.version_string, bpy.context.blend_data.filepath, socket.gethostname()


class ServerPanel(bpy.types.Panel):
    bl_label = "Server Panel"
    bl_idname = "Object_PT_server"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_category = "Shortcuts"
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")

    def draw(self, context):
        layout = self.layout
        version_string, filepath, hostname = self.proxy.server_data()
        print('found server on', 'localhost:', hostname)
        layout.row().label(text="Server found on: {}:{}".format(hostname,PORT))
        layout.row().label(text="Press Ctrl-C in terminal to exit".format(hostname,PORT))        

def register():
    global thread
    proc = mp.Process(target=maybe_launch_server)
    proc.daemon = True
    proc.start()
    bpy.utils.register_class(ServerPanel)


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


def maybe_launch_server():
    proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
    try:
        result = proxy.server_data()
    except ConnectionRefusedError:
        server = SimpleServer((HOST, PORT))
        server.register_introspection_functions()
        server.register_function(command, "command")
        server.register_function(server_data, "server_data")
        version_string = bpy.app.version_string
        print("Started the server with:", HOST, ":", PORT)
        server.serve_forever()


if __name__ == "__main__":
    register()
Post Undeleted by unutbu
Post Deleted by unutbu
Source Link
unutbu
  • 350
  • 3
  • 11
Loading