python socket 与unity通讯来调用photoshop批量处理

python socket 与unity通讯,通过unity发送消息来调用photoshop批量处理,photoshop批量处理完成完成后在发送complete完成通知给Unity
python部分代码

from math import fabs
import socket
import threading
import time
import json
from tkinter import E
from photoshop import Session



def on_new_connection( c_addr):

    print('Accept new connection from %s:%s...' % c_addr)

send_socket=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

send_socket.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)

listener = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

listener.bind(('0.0.0.0', 10086))

print('Waiting for connect...')



def oparection_ps(operation_path):
    with Session() as ps:
     idBtch =ps.app.charIDToTypeID( "Btch" )
     desc8=ps.ActionDescriptor
     desc8.putPath(ps.app.charIDToTypeID("null"),  operation_path)
     ref1=ps.ActionReference()
     ref1.putName(ps.app.charIDToTypeID("Actn"),"xiugai fenbinanlv")
     ref1.putName(ps.app.charIDToTypeID("ASet"),"组 1")
     desc8.putReference(ps.app.charIDToTypeID("Usng"),ref1)
     ps.app.executeAction(idBtch,desc8,ps.DialogModes.DisplayNoDialogs)
     send_socket.sendto("complete".encode(),("255.255.255.255",10087))



def thread_in(func,*args):
    t=threading.Thread(target=func,args=args)
    t.setDaemon(fabs)
    t.start()

def on_receive(rece_data,client):
    try:
        current_time=time.strftime('%m-%d %H:%M:%S', time.localtime())
        print(str( current_time)+"_"+str(client) +"发来消息:"+rece_data)
        commmand=json.loads(rece_data)
        if commmand['CommandName']=="start":
            oparection_ps(commmand['OperationPath'])
    except Exception as e:
        print("Exception:"+e)
    


while True:    
    try:
     receive_data, client = listener.recvfrom(1024)
     receive_data=receive_data.decode('utf-8')
     if receive_data:
        on_receive(receive_data,client)
    except Exception as e:
     print("发生错误"+e.message)



Unity 部分脚本


using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using UnityEngine;
using UnityEngine.UI;

public class getSocket : MonoBehaviour
{

    private string message;

    private Socket receive_client, send_client;

    private byte[] messTmp;

    // Use this for initialization
    private InputField send_inputfield;

    private Button send_button;

    private Thread rece_thread;

    private IPEndPoint receive_ip, send_ip;

    private void Awake()
    {
        var canvas = FindObjectOfType();
        send_inputfield = canvas.GetComponentInChildren();
        send_button = canvas.GetComponentInChildren

你可能感兴趣的:(python,unity,photoshop)