2

Since hours I try to solve a problem I have with Maya / MEL / Python. I have a script to set values of a fluid container.

E.g. setAttr "fluidShape1.densityDissipation" 0.2

Works great...

My problem: Actually it is not possible to change the value using the interface (see image). Is there a way to find out if the "text box" is enabled?

Thanks!!

P.S. I cant upload the image :(. But I hope you guys know what i mean

PatrickWe
  • 31
  • 1
  • 7

5 Answers5

1

To find out if the attribute is settable, use

getAttr -settable your_object.your_attribute

it will return 1 if you can set the attribute using setAttr and 0 if you can't.

If the value is grayed out in the UI the attribute is locked, you can unlock it with

setAttr -lock 0  your_object.your_attribute

If the value is purple in the UI it's driven by a connection of some kind, you'll need to use the hypergraph or the listConnections command to find out what's driving it and decide if you want to override the connection.

theodox
  • 12,028
  • 3
  • 23
  • 36
1

I already tried the -settable flag, but for some reason this is not working in my case.

Ok, lets say I create a FluidContainer. The density is set to zero, by using this command:

setAttr "fluidShape1.densityMethod" 0;

By using the -settable flag

getAttr -settable "fluidShapeq.densityScale"

the result is 1. But I can not change the corresponding slider. But still it is possible to change the values by using setAttr... That is confusing for me!

PatrickWe
  • 31
  • 1
  • 7
0

ok I think I found a "solution" for my problem, but I think I can do better. I use the following command to get the "grougID" of the slider and the field:

import maya.cmds as cmds
txt = "attrFieldSliderGrp214" 
cmds.attrFieldSliderGrp( txt, q=True, l=True ) # Density Scale

And now I can usethe enable field by:

gray = cmds.attrFieldSliderGrp(txt, q=True, en=True ) # True/False
PatrickWe
  • 31
  • 1
  • 7
  • Ok, this is also not working. The problem is that "214" is not always the number for the Density Scale Slider... Any ideas? – PatrickWe Jul 02 '15 at 10:08
0

This works fine for me.

def gui():
    cmds.window()
    cmds.columnLayout( adjustableColumn=True )
    #since density support only upto 3 setting max to 3
    getCurrentInd = int(cmds.getAttr("fluidShape1.densityMethod"))
    cmds.intSlider( min=0, max=3, value=getCurrentInd, step=1, cc=updateDens)
    cmds.showWindow()

def updateDens(value):
    cmds.setAttr("fluidShape1.densityMethod", value)
gui()
Achayan
  • 5,720
  • 2
  • 39
  • 61
  • Ok that work's but it's not what I mean. getCurrentInd = int(cmds.getAttr("fluidShape1.densityDissipation")) returns 0 no matter if "densityMethod" = 0,1,2,3 ... E.g.: 0 --> Slider disabled. 1 2 --> Dlider enabled – PatrickWe Jul 03 '15 at 07:00
  • I don't understand what you saying getCurrentInd = int(cmds.getAttr("fluidShape1.densityDissipation")) this will return value and it will set the slider for sure :) – Achayan Jul 03 '15 at 16:52
  • Yes, you are totally right! This lines of code return the value of the slider. But I would like to know if the slider is enabled (gray) or disabled (light gray). If the slider is disabled, my plugin should not set "random" a value... – PatrickWe Jul 06 '15 at 07:11
0

By Interface if I understand that you mean the AttributeEditor, you could try this.

import pymel.core as pc
def findAEFieldByLabel(label='Dissipation', field_type=pc.ui.AttrFieldSliderGrp):   
    for i in pc.ui.PyUI('MainAttributeEditorLayout').walkChildren():
        if isinstance(i, pc.ui.RowLayout):
            name = i.name()
            try:
                grp = field_type(name)
                if grp.getLabel() == label:
                    return grp
            except:
                pass
print findAEFieldByLabel().getEnable()

I used pymel here because it helps you find the type of a python ui. Well ... not quite however! because it recognized attrFieldSliderGrps as RowLayouts

LazyLeopard
  • 194
  • 1
  • 11
  • Thank you so much for this code snippet. That is exactly what I was looking for!! – PatrickWe Oct 30 '15 at 15:11
  • Hey, I found one small problem. The state is only correct, when the user "opens" the spezific tab. From scratch, it is always "enabled" – PatrickWe Nov 03 '15 at 13:29
  • Ofcourse, UI can only be queried if it is there. What can always be queried reliably is the underlying node. Isn't the approach by @theodox something that you should be going for? – LazyLeopard Nov 04 '15 at 11:20
  • I can not see your point. Of coure I can ask if the textBox is settable or not. But that is not what i would like to have. Your code is exactly doing what i would like to have... :) The only code I would need now is: "Open the e.g. Velocity ToolBoxItem - which refreshes the view". But is that possible with MEL/Python ? – PatrickWe Nov 05 '15 at 13:22