One-Click Create Locator Redirection Scripts

One-Click Create Locator Redirection Scripts

1925250542
Participant Participant
209 Views
0 Replies
Message 1 of 1

One-Click Create Locator Redirection Scripts

1925250542
Participant
Participant

This is a small script that can quickly create locators and assign them to objects. It can be handy for K animations. 

 

Continuing to add strings after the creation_object_name_base variable can continue to increase the number of locators 

 

 

import maya.cmds as cmds
import random

def positioning_creation():
    creation_object_name_base = ["Rotate_Attr", "Translate_Attr", "Total_Object"] #一共要出现的
    random_number = random.randint(0, 255) #获取随机数
    object_name = cmds.ls(selection=True)[0] #获取选择对象
    creation_object_name = [] #定义一个列表
    sl_object_pos = cmds.getAttr(object_name + ".translate")[0] #获取选择对象的移动值
    sl_object_rot = cmds.getAttr(object_name + ".rotate")[0] #获取选择对象的旋转值

    for i in range(len(creation_object_name_base)):  # 随机名字赋予循环
        creation_object_name.append(creation_object_name_base[i] + "_" + str(random_number))  # 随机名字赋予

    for i in range(len(creation_object_name)):  # 创建定位器循环
        creation_object_name[i] = cmds.spaceLocator(name=creation_object_name[i])[0]  # 创建定位器
        cmds.setAttr(creation_object_name[i] + ".translate", sl_object_pos[0], sl_object_pos[1], sl_object_pos[2])
        cmds.setAttr(creation_object_name[i] + ".rotate", sl_object_rot[0], sl_object_rot[1], sl_object_rot[2])

    cmds.parent(object_name, creation_object_name[0]) #赋予第一个对象

    for i in range(len(creation_object_name)):  # 赋予子级工作
        cmds.parent(creation_object_name[i], creation_object_name[i + 1])

positioning_creation()

 

 

0 Likes
210 Views
0 Replies
Replies (0)