0

Is it possible to store the current Items in the Outliner as well as the new Items too?

def main():
    setupRenderGlobals()
    importItems()
    frameViewport()

    global app
    app=QtGui.qApp  

    global form
    form = MainWindow()
    form.show()

Eg. Current Items in Outliner (except the default items, eg. camera): ['pCube1', 'pCube2', 'pSphere1']

Then importing.adding in of new items: ['pCube1', 'pCube2', 'pSphere1', 'Man_Rig01', 'pShere2']

Could someone guide me how to write out a way that I can differentiate the new Items? Currently my import window (using of an in-house module which is the importItems() ) keeps popping up the prefix window (MainWindow()) when I hit close/ whether or not I import in any items. Thus I wanted to write it in a way where the prefix window will only pop up when new items are added.


Message to close voters: This question is not unclear to Maya users. There are answers waiting to be posted, but the question needs to be re-opened first.

mhlester
  • 22,781
  • 10
  • 52
  • 75
yan
  • 631
  • 9
  • 30
  • To clarify, you want to have a script run when new objects are added? – mhlester Feb 18 '14 at 17:27
  • I think this is a pretty clear question (on account it being a commonly asked feature). The way I understand this is that you want to know which items were just imported. Its simple Ive outlined this a few times in my life. The answer is: Simply do **size('ls')** before import then list all items that have higher index than that in ls after import are newly imported objects. I have this as a script that wraps import too if anybody's interested. Anyway this is a inferior solution since you can no longer fix problems after the fact with name spacing. – joojaa Feb 18 '14 at 19:15
  • @joojaa, question has been reopened. please feel free to post as a real answer now :) – mhlester Feb 18 '14 at 20:15

1 Answers1

1

Maya stores objects in a list. So every time you import stuff it goes to the end of said list so if you do,

coutBefore = len(cmds.ls())

before your import. You can then proceed with:

nodesImported = cmds.ls()[coutBefore:]

after import. It is possible to wrap this into import directly. But that's best done in MEL. Observe: I do not think this is a good approach. Since you dont get any namespace to protect any possible import issues from badly done scenes. So a alternate solution would be to import with namespace then strip the namespace if user asks.

joojaa
  • 4,354
  • 1
  • 27
  • 45
  • Just curious but is it possible to exclude certain nodes? Example, I do not wish for the Lighting nodes to be included – yan Feb 20 '14 at 02:48
  • @yan maya commands work on lists. So you can pass this list to yet another ls or a custom filter for further refinement. So yes you can. – joojaa Feb 20 '14 at 05:39