美文网首页工具癖
MotionBuilder Python Script10 -

MotionBuilder Python Script10 -

作者: Houdinini | 来源:发表于2019-07-26 20:47 被阅读20次
    凑齐!

    昨天走的早,忘了写东西。。惭愧!

    今天我们来看一下MotionBuilder的Edit 的部分实现方法

    一、Edit

    Edit中包含了当前软件中许多的属性配置方法

    我们先来看一下UI效果


    UI_Edit

    这里包含了 name、Color、 Number 、 Vector 、TimeCode等参数UI,官方代码如下:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    # Copyright 2009 Autodesk, Inc.  All rights reserved.
    # Use of this software is subject to the terms of the Autodesk license agreement
    # provided at the time of installation or download, or which otherwise accompanies
    # this software in either electronic or hard copy form.
    
    # Script description:
    # Create a tool showing different FBEdit controls and possible customizations
    #
    # Topic: FBEdit, FBEditColor, FBEditNumber, FBEditVector, FBEditTimeCode
    #
    
    from pyfbsdk import *
    from pyfbsdk_additions import *
    
    editStyles = ["FBEdit", "FBEditColor", "FBEditNumber", "FBEditVector", "FBEditTimeCode"]
    edits = {}
    
    
    # Normal Edit
    def OnChange(control, event):
        print control.Text
    
    
    def PopulateLayout(mainLyt):
        anchor = ""
        attachType = FBAttachType.kFBAttachTop
    
        # Generically create different types of edit
        for style in editStyles:
            # Create label
            labId = "Label" + style
            l = FBLabel()
            l.Caption = style
            x = FBAddRegionParam(10, FBAttachType.kFBAttachLeft, "")
            y = FBAddRegionParam(10, attachType, anchor)
            w = FBAddRegionParam(100, FBAttachType.kFBAttachNone, "")
            h = FBAddRegionParam(25, FBAttachType.kFBAttachNone, "")
    
            mainLyt.AddRegion(labId, labId, x, y, w, h)
            mainLyt.SetControl(labId, l)
    
            # Create edit
            editId = "Edit" + style
            initCall = "%s()" % (style)
            e = eval(initCall)
            edits[style] = e
    
            x = FBAddRegionParam(10, FBAttachType.kFBAttachRight, labId)
            y = FBAddRegionParam(10, attachType, anchor)
            w = FBAddRegionParam(200, FBAttachType.kFBAttachNone, "")
            h = FBAddRegionParam(25, FBAttachType.kFBAttachNone, "")
    
            mainLyt.AddRegion(editId, editId, x, y, w, h)
    
            mainLyt.SetControl(editId, e)
    
            attachType = FBAttachType.kFBAttachBottom
            anchor = labId
    
        # Do specific edit initialization according to its type
    
        e = edits['FBEdit']
        e.Text = "initial text"
        # e.PasswordMode = True
        e.OnChange.Add(OnChange)
    
        # Color Edit
        e = edits['FBEditColor']
        e.Value = FBColor(1.0, 0.0, 0.0)
        # e.ColorMode = 2
        # e.ColorMode = 3
    
        # Number edit
        e = edits['FBEditNumber']
        e.Max = 100
        e.Min = 34
        e.Value = 62
    
        # Vector Edit
        e = edits['FBEditVector']
        e.Value = FBVector3d(42.0, 23.0, 666.666)
    
        e = edits['FBEditTimeCode']
        e.Value = FBTime(11, 22, 33, 11)
    
    
    def CreateTool():
        # Tool creation will serve as the hub for all other controls
        t = FBCreateUniqueTool("Edit Example")
        PopulateLayout(t)
        ShowTool(t)
    
    
    CreateTool()
    

    代码清晰!decomposition and refactor!

    二、结语

    有什么问题可以留言

    继续!

    共勉!

    相关文章

      网友评论

        本文标题:MotionBuilder Python Script10 -

        本文链接:https://www.haomeiwen.com/subject/eyfjrctx.html