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.

Change scene length when import/reference new asset

Change scene length when import/reference new asset

Cavaliere.fab
Contributor Contributor
2,389 Views
20 Replies
Message 1 of 21

Change scene length when import/reference new asset

Cavaliere.fab
Contributor
Contributor

Hi...a weird thing.
Let's say I have a scene which is 100 frame long.
At some point I import or reference a new camera inside my scene and let's suppose that cam.fbx I've just imported/referenced has a different scene length (let's say 50 ftg), well...my scene takes that duration and change my scene file to the same length...every time. It doesn't change the framerate at least.
Does somebody know how to avoid this? It does it in maya 2022 and 2023 and it's very annoying.

Thanks.

Fab

0 Likes
2,390 Views
20 Replies
Replies (20)
Message 2 of 21

mcw0
Advisor
Advisor

There are scriptNodes in your files.  If you delete the scriptNodes from the camera file, then there shouldn't be an issue.  Script nodes are run when the file is opened or imported.  So the most recent file brought into a scene will override the current frame range.

0 Likes
Message 3 of 21

Cavaliere.fab
Contributor
Contributor

ScriptNodes?

I exported that cam by doing an "export selection" with only the group of the cam and the cam itself.

How should I delete those scriptNodes?

I actually have no clue about how I inserted a scriptNode nor how to delete it 😅

Can you please let me know?

Thanks

0 Likes
Message 4 of 21

mcw0
Advisor
Advisor

Open the expression editor.  Filter by scriptNode.  Select the scriptNode and delete.

0 Likes
Message 5 of 21

mcw0
Advisor
Advisor

Maya creates the script nodes when you start animating.

0 Likes
Message 6 of 21

Cavaliere.fab
Contributor
Contributor

I opened the fbx cam file and I have no Scriptnodes listed in the exprEditor.

 

I do have few of them in my animated scene (some from the scene, some from the rig file judging by their namespace) but i think those file are the ones I want, right? In my cam file there aren't any.

Sorry to bother but I'm so confused by this issue.

Also it says "modify this at your own risk" and it does not make me comfortable at all 😂

 

 

0 Likes
Message 7 of 21

mcw0
Advisor
Advisor

yes, if you see scriptNodes with namespaces from referencing, then go to the reference file and remove the scriptNode that sets the animation frame range.  I forget what it's called.  But it will have very few lines of code in it.  The other scriptNode you can leave.

sceneConfigurationScriptNode...that is the one that sets the frame range.  Delete it.

0 Likes
Message 8 of 21

Cavaliere.fab
Contributor
Contributor

Hi...I tried to do this

I create a whole complete set of cameras in a new scene with no animation (the empty scene was 75 ftg and 24fps). 

I create a new animation test scene (about 150 ftg at 30 fps) from scratch, just a cube inside a scene doing a bit of TranslationZ, and referenced/imported my fbx cams and yes, a script node appeared in the expr editor. 

There was indeed a script saying "bla bla bla 75", and i deleted it. 

Remove cams ref ftom scene, ref again...same thing happened.

There was another (and last one) script node listed, I deleted that one as well

Remove ref, import again, same thing happened.

I opened the cams only and they have no scriptnodes.

 

At this point I have a empty expr editor in the animated scene

And a empty expr editor in the cam fbx

But I still get the same result. 

The timeline, when I import or ref the cams, goes to 75.

 

 

My point is

It must be something with the fbx, cause when I import/ref the rig, this doesn't happen even if the rigs have a scriptnode, the scene keep its length. Only with import/ref the fbx this happens.

 

Help!

 

 

0 Likes
Message 9 of 21

mcw0
Advisor
Advisor

Sorry my suggestion didn't work for you.  From what you describe, it appears that Maya is adjusting the playback range.  At this point, what I usually do is create a workaround for the issue.  Write a script to record your playback range.  Then reference in all your files.  Then reset your playback range.

0 Likes
Message 10 of 21

Cavaliere.fab
Contributor
Contributor

I will just check my scene length before import myRefs and set it again...

Thanks anywa

The problem in production is that I'm not the only one importing ref in the scene so it will be very likely to have troubles later.

I was actually hoping for an extra option to set to avoid this problem.

 

Thanks anyway

 

0 Likes
Message 11 of 21

Cavaliere.fab
Contributor
Contributor

No solutions yet

0 Likes
Message 12 of 21

Kahylan
Advisor
Advisor

Hi!

 

There isn't a UI setting that you can use to do that. The problem is, that the "FBXIMPORTERUI" overrides the settings of the file command, and FBX doesn't have a built in setting to preserve your playback range. That's why referencing/importing maya files doesn't change your playback range but importing fbx does.

 

But you can automate the process to reset your playback range fairly easily by using scriptjobs as @mcw0 already mentioned.

import maya.cmds as mc

def storePlayBackRange():
    start = mc.playbackOptions(q=True, min=True)
    end = mc.playbackOptions(q=True, max=True)
    mc.optionVar(fv = ["startPlaybackRangeStorage", start])
    mc.optionVar(fv = ["endPlaybackRangeStorage", end])
    if mc.window('FBXIMPORTWINDOWUI', ex=True)== True:
        mc.scriptJob(runOnce = True, uid= ['FBXIMPORTWINDOWUI',askAboutReset])
    

def askAboutReset():
    d = mc.confirmDialog(t= "Do you want to reset the Playback Range?",b= ["Yes","No"], db= "Yes", cb= "No", ds= "No")
    if d == "Yes":
        s = mc.optionVar(q="startPlaybackRangeStorage")
        e = mc.optionVar(q="endPlaybackRangeStorage")
        
        mc.playbackOptions(min = s, max= e, e= True)
        
    


mc.scriptJob(ct = ["readingFile",storePlayBackRange])

 

This python script will start a scriptjob that waits for maya to read a file. Once it is triggered it stores the playback range to the prefs and checks if the file that is being imported is an FBX, if it is it will create another scriptjob that only runs once and gets triggered once the FBX importer window is closed. When it gets triggered it will give you a popup that asks you wether you want to reset your playback range.

I coded this with this popup because I think it can be handy to import the playback range sometimes, but you can easily change the code so it just runs without asking by changing line 13 to:

    d = "Yes"

 

If you put this script into the userSetup.py on your computers it will automatically run whenever you start maya and just create the scriptjob without you having to do anything.

 

I hope it helps!

0 Likes
Message 13 of 21

Cavaliere.fab
Contributor
Contributor

It doesn't work...
or better, I think I did not understand how to use it.
- I copied this script in usersetup.py
- launch maya
- set the range I want and the fps I need (1-100ftg, 30 fps)
- create a new scene with a animated cube
- saved as "temp.ma"
- as soon as I reference the cam fbx, my range changes to (0-75) which is the timerange of the camera referenced
- what am I doing wrong?
(yes, I changed the "d=Yes" line in the script)

thanks so much

Message 14 of 21

Cavaliere.fab
Contributor
Contributor

AH! It kind of works...
there's no popup and the start value still get reset to what the cam fbx has.
But the "end" of timerange works
Also, Only if I "import" the fbx cam, If I "reference" the fbx it doesn't work at all.
It is possible to change it to reference instead of import somehow?

0 Likes
Message 15 of 21

Kahylan
Advisor
Advisor

I will check if I can do that over the weekend. I don't have much experience with referenced FBX files.

0 Likes
Message 16 of 21

Kahylan
Advisor
Advisor

This worked for me:

 

import maya.cmds as mc


def storePlayBackRange():
    start = mc.playbackOptions(q=True, min=True)
    end = mc.playbackOptions(q=True, max=True)
    mc.optionVar(fv = ["startPlaybackRangeStorage", start])
    mc.optionVar(fv = ["endPlaybackRangeStorage", end])
    

def resetPBS():
    s = mc.optionVar(q="startPlaybackRangeStorage")
    e = mc.optionVar(q="endPlaybackRangeStorage")
    mc.playbackOptions(min = s, max= e, e= True)
    
    
storePlayBackRange()

mc.scriptJob(e = ["playbackRangeChanged",storePlayBackRange])

mc.scriptJob(ct = ["readingFile",resetPBS])

 

I hope it helps!

Message 17 of 21

Cavaliere.fab
Contributor
Contributor

Hi, it kind of works for the final value of the range, but it doesn't for the start value. That is still the fbx one.

The cam fbx is 0-75 and the file goes to 0-120, while it was 1-200.
Cause the script uses the active playback timerange, but not the scene timerange


Message 18 of 21

Kahylan
Advisor
Advisor

Ah I see.

 

This should fix that. I needed to add an additional scriptjob to listen to the overall scene length.

 

import maya.cmds as mc


def storePlayBackRange():
    start = mc.playbackOptions(q=True, min=True)
    end = mc.playbackOptions(q=True, max=True)
    startT = mc.playbackOptions(q=True, ast=True)
    endT = mc.playbackOptions(q=True, aet=True)
    mc.optionVar(fv = ["startPlaybackRangeStorage", start])
    mc.optionVar(fv = ["endPlaybackRangeStorage", end])
    mc.optionVar(fv = ["startPlaybackTimeStorage", startT])
    mc.optionVar(fv = ["endPlaybackTimeStorage", endT])
    

def resetPBS():
    s = mc.optionVar(q="startPlaybackRangeStorage")
    e = mc.optionVar(q="endPlaybackRangeStorage")
    sT = mc.optionVar(q="startPlaybackTimeStorage")
    eT = mc.optionVar(q="endPlaybackTimeStorage")
    mc.playbackOptions(min = s, max= e, e= True, aet= eT, ast = sT)
    
    
storePlayBackRange()

mc.scriptJob(e = ["playbackRangeChanged",storePlayBackRange])
mc.scriptJob(e = ["playbackRangeSliderChanged",storePlayBackRange])

mc.scriptJob(ct = ["readingFile",resetPBS])

 

I hope this helps!

0 Likes
Message 19 of 21

Cavaliere.fab
Contributor
Contributor

Hi...
First of all, thanks so much for you help.
I've just realized that I didn't thank you properly, sorry for that.
You've been a huge help.
The code now works perfectly when I import fbx as reference, and the time range is correct.

However...I can't use it like it is cause a weird problem appeared:
now every scene, when I open a file, get set to that range.
Example.
the script memorized 1-120 as range from the "idle file"
when I opened the "death file" which should be 1-60, instead of setting its time range,

maya opens the file with 1-120 ^^

Same thing if I open the "hit file" or "run file" or...everyone now gets opened with 1-120 time range (LOL)
at first I didn't understand it then I realized it was the same range as the "idle file"


My guess is that since it's in the usersetup.py file, it always gets read it, even when you open a file, not just when you import/reference an fbx. Wouldn't it be much better to place this code to a button, including the import/reference file function so it gets read only where there actually is that kind of operation needed?

Thanks, a lot.


0 Likes
Message 20 of 21

Kahylan
Advisor
Advisor

Actually, it's not the problem of the code being in usersetup py, because this file only gets read when maya gets started.

The problem is, that I had to bind the scriptjob to the event "readingFile" instead of the closure event of "FBXIMPORTWINDOW" since otherwise it wasn't triggered when referencing FBX. the "readingFile" event gets triggered whenever a file is read (opening a scene, creating a new scene, importing a file, referencing a file). So basically the scriptjob doesn't know the difference between importing/referencing a file and opening one, it also doesn't know the filetype of the file that is read, which is why I originally bound the scriptjob to the FBX window.

 

I tried to fix this problem by adding a scriptjob that deletes the rangevariables from prefs when the scene gets flushed Something that happens when a new Scene is created or an existing scene is opened, but not when a scene is referenced/imported. I also modified the function that resets the timeline to first check if those variables exist and just create them when they don't.

 

import maya.cmds as mc

def rmVar():
    mc.optionVar(rm = "startPlaybackRangeStorage")
    mc.optionVar(rm = "endPlaybackRangeStorage")
    mc.optionVar(rm = "startPlaybackTimeStorage")
    mc.optionVar(rm = "endPlaybackTimeStorage")
    
def storePlayBackRange():
    start = mc.playbackOptions(q=True, min=True)
    end = mc.playbackOptions(q=True, max=True)
    startT = mc.playbackOptions(q=True, ast=True)
    endT = mc.playbackOptions(q=True, aet=True)
    mc.optionVar(fv = ["startPlaybackRangeStorage", start])
    mc.optionVar(fv = ["endPlaybackRangeStorage", end])
    mc.optionVar(fv = ["startPlaybackTimeStorage", startT])
    mc.optionVar(fv = ["endPlaybackTimeStorage", endT])
    

def resetPBS():
    if mc.optionVar(ex = "startPlaybackRangeStorage")==True:
        s = mc.optionVar(q="startPlaybackRangeStorage")
        e = mc.optionVar(q="endPlaybackRangeStorage")
        sT = mc.optionVar(q="startPlaybackTimeStorage")
        eT = mc.optionVar(q="endPlaybackTimeStorage")
        mc.playbackOptions(min = s, max= e, e= True, aet= eT, ast = sT)
    else:
        storePlayBackRange()
         
    
    
storePlayBackRange()

mc.scriptJob(ct = ["readingFile",resetPBS])

mc.scriptJob(e = ["playbackRangeChanged",storePlayBackRange])
mc.scriptJob(e = ["playbackRangeSliderChanged",storePlayBackRange])
mc.scriptJob(ct = ["flushingScene",rmVar])

 

If this doesn't work, I'm afraid I can't solve your problem. Scriptjobs are fairly limited and I already used the only combination of conditions where I can assure they get triggered when a file is opened in the right order.

But I hope it works now.