Maya python-在同一窗口中创建控件滑块

时间:2018-11-26 21:01:29

标签: python maya

我是python的初学者。我试图使每次按def Previewbevel定义的按钮(忽略斜面)的滑块(控制斜面)在同一窗口中创建(忽略): 肯定有我不懂的东西

我更新了代码。现在可以测试了。您只需要选择一个多边形,然后按按钮即可。我希望每次按下按钮时,都会在窗口中添加滑块

此处是代码:

from os import path

import maya.cmds as cmds


import maya.mel as mel

import pymel.core as pm


def previewbevel(ignore): 


    pm.polySelectConstraint(type=0x8000, mode=3, sm=1)
    pm.mel.resetPolySelectConstraint()

    BevelA= mel.eval("polyBevel3 -fraction 0.3 -offsetAsFraction 1 -autoFit 1 -depth 1 -mitering 0 -miterAlong 0 -chamfer 1 -segments 2 -worldSpace 1 -smoothingAngle 45 -subdivideNgons 1 -mergeVertices 1 - mergeVertexTolerance 0.001;")
    bevel=BevelA[0]


    if pm.window('myWindow', exists=1):
       pm.deleteUI('myWindow', window=1)

    pm.window('myWindow', title="attrFieldSliderGrp")
    pm.columnLayout(adjustableColumn=True)

    slider=str(pm.attrFieldSliderGrp(columnAlign=(1, "right"), 
       min=0, 
       columnWidth=[(1, 84), (4, 1)], 
       label="Bevel", 
       at=(bevel + ".fraction"), max=20, 
       adjustableColumn=3))

    slider1=str(pm.attrFieldSliderGrp(columnAlign=(1, "right"), 
       min=0, 
       columnWidth=[(1, 84), (4, 1)], 
       label="Radial", 
       at=(bevel + ".mitering"), max=3, 
       adjustableColumn=3))


    slider2=str(pm.attrFieldSliderGrp(columnAlign=(1, "right"), 
       min=0, 
       columnWidth=[(1, 84), (4, 1)], 
       label="Segments", 
       at=(bevel + ".segments"), max=20, 
       adjustableColumn=3))
    pm.showWindow()





if cmds.window("test", exists =True):
    cmds.deleteUI("test")

if cmds.dockControl("testDock", exists =True):
    cmds.deleteUI("testDock")

myWindow = cmds.window("test", t="test", tlb=True, menuBar=True)
buttonForm = cmds.formLayout( parent = myWindow)
allowedAreas = ['all']
cmds.dockControl("testDock", l = "test",area='left', content=myWindow, allowedArea=allowedAreas,floating=True,fixedHeight= False ,fixedWidth= False,width=200, height=150)


tab=cmds.tabLayout('windowLayout',parent = buttonForm,width=205,bs="none")
cmds.separator( style='none', height=2,parent=buttonForm) 


topo=cmds.columnLayout('test',parent = tab)
cmds.button( label='Peview Bevel', command=previewbevel, parent=topo,width=205)  
cmds.window (myWindow, edit=True, ) 

预先感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

我不确定为什么将滑块转换为字符串。 这是一个工作的用户界面。由于我不了解您的工作,因此很难更正您的代码

import pymel.core as pm

def previewbevel(ignore): 


    pm.polySelectConstraint(type=0x8000, mode=3, sm=1)
    bevel = pm.bevel()[0]
    pm.mel.resetPolySelectConstraint()

    if pm.window('bevel', exists=1):
       pm.deleteUI('bevel', window=1)

    pm.window('bevel', title="attrFieldSliderGrp")
    main = pm.columnLayout(adjustableColumn=True)

    slider = pm.attrFieldSliderGrp(at=bevel + ".tolerance", p=main)

    slider1 = pm.attrFieldSliderGrp(at=bevel + ".extrudeDepth", p=main)

    slider2 = pm.attrFieldSliderGrp(at=bevel + ".width", p=main)
    pm.showWindow()


previewbevel(0)