Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

I need your help to create a Tick Span Changer UI, either python(cmds) or mel would be helpful.

I need your help to create a Tick Span Changer UI, either python(cmds) or mel would be helpful.

amaterasu-qbb
Collaborator Collaborator
1,257 Views
7 Replies
Message 1 of 8

I need your help to create a Tick Span Changer UI, either python(cmds) or mel would be helpful.

amaterasu-qbb
Collaborator
Collaborator

Forgive me for being similar to this post.

https://forums.autodesk.com/t5/maya-programming/how-to-change-the-tick-span-of-the-time-slider-witho...

 

I am currently working on a tick span changer UI in Maya 2024. This image was created in Adobe XD and is for appearance only, not the actual UI that exists.
it's a concept picture.it's a concept picture.
As a dreamer to be an animator, there are times when I want to intuitively know how many frames the TimeSlider will take. For many years I have wanted to be able to change the tick span for this purpose.

The number of the TimeSlider is set and displayed by the Tick Span setting in the Preferences.The number of the TimeSlider is set and displayed by the Tick Span setting in the Preferences.
The problem is 2 points.

  • What command should I use to invoke the tick span preference in Maya?
  • How should I create the UI?

Thanks.

Accepted solutions (1)
1,258 Views
7 Replies
Replies (7)
Message 2 of 8

brentmc
Autodesk
Autodesk

Looks like the other post covers pretty much everything you need.

The actual tick preference is saved in the "timeSliderTickSpan" optionVar. (look at the optionVar command for details)

When you close the preferences window that value gets applied to the time slider using a command like this: (where $gPlaybackSlider is a MEL global that holds the name of the time slider control)

timeControl -e -tickSpan `optionVar -q timeSliderTickSpan` $gPlayBackSlider;

 
To create the UI look at the command documentation for the intSliderGrp command since many commands provide small examples that show how to create the controls.

string $window = `window -title "intSliderGrp Example"`;
columnLayout;
intSliderGrp -label "Group 2" -field true
    -minValue -10 -maxValue 10
    -fieldMinValue -100 -fieldMaxValue 100
    -value 0;
showWindow $window;

Then you need to setup command callbacks on the controls to call the commands to change the tick span etc.

 

Brent McPherson
Principle Engineer
Message 3 of 8

amaterasu-qbb
Collaborator
Collaborator

Hi! @brentmc ,

 

I appreciate your help. My current environment is,
Windows 11 Pro (64-bit) and Autodesk Maya 2024 Creative. UI is finished, now I will try to define the function of the UI.

 

import maya.cmds as cmds

window = cmds.window( t = 'Tick Span' )
cmds.columnLayout()
cmds.frameLayout( l = 'Tick Span' )
cmds.intSliderGrp( f = True, l = 'Tick Span', min = 0, max = 10, fmn = 0, fmx = 10000, v = 0 )

cmds.showWindow( window )

Completed UICompleted UI
Thanks.

Message 4 of 8

amaterasu-qbb
Collaborator
Collaborator

Hi! everyone,

 

 

import maya.cmds as cmds

cmds.timeControl( tsp = 12 )

 

 

When this code is executed, the following error message is displayed.

 

# Error: RuntimeError: file <maya console> line 3: Single timeControl already created.: timeControl1
# Cannot create UI object: timeControl5

 

Is this happening because of the missing command?

 

$gPlayBackSlider;

 

 

Thanks.

0 Likes
Message 5 of 8

amaterasu-qbb
Collaborator
Collaborator

Now works! I should have read the documentation carefully.

https://help.autodesk.com/view/MAYACRE/ENU/index.html?contextId=COMMANDSPYTHON-INDEX

 

import maya.cmds as cmds
import maya.mel

aPlayBackSliderPython = maya.mel.eval('$tmpVar=$gPlayBackSlider')
cmds.timeControl(aPlayBackSliderPython, e = True, tsp = 9 )

I could not run the code because $gPlayBackSlider; was missing.

 

 

0 Likes
Message 6 of 8

amaterasu-qbb
Collaborator
Collaborator

Hi. everyone,

 

I gave up because it was my limit. Please help me.

 

# -*- coding: utf-8 -*-
# tickspanChangeUI

import maya.cmds as cmds
import maya.mel

def tickspanChangeUI():
    windowName = 'tickspanChangeUI'
    
    if cmds.window( windowName, ex = True ):
        cmds.deleteUI( windowName )
    
    cmds.window( windowName )
    
    v = getValue()
    window = cmds.window( t = 'Tick Span' )
    cmds.columnLayout( adj = True )
    cmds.frameLayout( l = 'Tick Span' )
    intSliderGrp = cmds.intSliderGrp( f = True, l = 'Tick Span', min = 0, max = 10, fmn = 0, fmx = 1000, v = v )
    cmds.intSliderGrp( intSliderGrp, l = 'Tick Span', e = True, x = cmds.intSliderGrp( intSliderGrp, q = True, v = True 😞 changeOptionVar( value = x ) )

    cmds.showWindow( window )

def editTickspanValue():
    aPlayBackSliderPython = maya.mel.eval( '$tmpVar=$gPlayBackSlider' )
    cmds.timeControl( aPlayBackSliderPython, e = True, tsp = x )

    if cmds.optionVar( ex = '$tmpVar=$gPlayBackSlider')== 0:
        cmds.optionVar( fv = ('$tmpVar=$gPlayBackSlider', 0.1))
        changeValue= 1
    else:
        changeValue = cmds.optionVar( q = '$tmpVar=$gPlayBackSlider' )
    return changeValue    
    
def changeTickspanOptionVar( value = None ):
    cmds.optionVar( iv= ( '$tmpVar=$gPlayBackSlider', value ) )

tickspanChangeUI()

 

 

0 Likes
Message 7 of 8

amaterasu-qbb
Collaborator
Collaborator

I'm embarrassed to say that this time I was able to get the code working with Bing Chat.
Originally, I needed help from you all. But unfortunately, no help came in time.

I am neither anti-AI nor pro-AI, but this was a good opportunity to take a fresh look at AI, and since there is talk that Autodesk Maya will someday have AI or not, I will watch it unfold.

Now, here is the code that works.

 

# -*- coding: utf-8 -*-
# tickspanChangeUI

import maya.cmds as cmds
import maya.mel

def tickspanChangeUI():
    windowName = 'tickspanChangeUI'
    
    if cmds.window( windowName, ex = True ):
        cmds.deleteUI( windowName )
    
    cmds.window( windowName )
    
    v = getValue()
    window = cmds.window( t = 'Tick Span' )
    cmds.columnLayout( adj = True )
    cmds.frameLayout( l = 'Tick Span' )
    intSliderGrp = cmds.intSliderGrp( f = True, l = 'Tick Span', min = 0, max = 10, fmn = 0, fmx = 1000, v = v )
    cmds.intSliderGrp( intSliderGrp, l = 'Tick Span', e = True, cc = lambda *args: changeOptionVar( value = cmds.intSliderGrp(intSliderGrp, q=True, v=True) ) )

    cmds.showWindow(  )

def getValue():
    aPlayBackSliderPython = maya.mel.eval('$tmpVar=$gPlayBackSlider')
    current_tickspan = cmds.timeControl(aPlayBackSliderPython, query=True, tickSpan=True)
    return current_tickspan

def changeOptionVar( value = None ):
    aPlayBackSliderPython = maya.mel.eval('$tmpVar=$gPlayBackSlider')
    cmds.timeControl(aPlayBackSliderPython, edit=True, tickSpan=value)

tickspanChangeUI()

You can change it by dragging and undragging the slider or entering a number.

The Preferences do not reflect the numbers, but you can see that the UI controls them.

UI controls tick spanUI controls tick spanUI and Preference, the preferences do not reflect the numbers.UI and Preference, the preferences do not reflect the numbers.

https://sl.bing.net/fetffv9hbfo (Bing Chat)

Thanks,

Message 8 of 8

amaterasu-qbb
Collaborator
Collaborator
Accepted solution

Hi! everyone,

 

The code has been improved to prevent the appearance of multiple windows.

 

# -*- coding: utf-8 -*-
# tickspanChangeUI

import maya.cmds as cmds
import maya.mel

def tickspanChangeUI():
    windowName = 'tickspanChangeUI'
    
    if cmds.window( windowName, ex = True ):
        cmds.deleteUI( windowName )
    
    window = cmds.window( windowName, t = 'Tick Span' )
    
    v = getValue()
    cmds.columnLayout( adj = True )
    cmds.frameLayout( l = 'Tick Span' )
    intSliderGrp = cmds.intSliderGrp( f = True, l = 'Tick Span', min = 0, max = 10, fmn = 0, fmx = 1000, v = v )
    cmds.intSliderGrp( intSliderGrp, l = 'Tick Span', e = True, cc = lambda *args: changeOptionVar( value = cmds.intSliderGrp(intSliderGrp, q=True, v=True) ) )

    cmds.showWindow( window )

def getValue():
    aPlayBackSliderPython = maya.mel.eval('$tmpVar=$gPlayBackSlider')
    current_tickspan = cmds.timeControl(aPlayBackSliderPython, query=True, tickSpan=True)
    return current_tickspan

def changeOptionVar( value = None ):
    aPlayBackSliderPython = maya.mel.eval('$tmpVar=$gPlayBackSlider')
    cmds.timeControl(aPlayBackSliderPython, edit=True, tickSpan=value)

tickspanChangeUI()

 

 

https://sl.bing.net/ijWbWW6IKEC

Thanks,