Selecting Newly Loaded Nodes

Hi !
I need to do some node cleanup everytime new nodes comes into the scene(open/import).
What are my options to select nodes comming from imported fie? If I could run a script right before open/import and then just after it, then I'm home. Or there's a command for that purpose ?

Actually what I try to do is to make sure only one instance of my node exists in scene. This is a node that identifies an asset piece - right now it's a scriptNode with some special attrs, but I could compile my own node for that if this simplifies the goal above.

thanks !

QUOTE(ogre @ 05/15/09, 03:04 PM) [snapback]307800[/snapback]
Or there's a command for that purpose ?

theres a event yes, look at scriptjob

QUOTE
Actually what I try to do is to make sure only one instance of my node exists in scene.

In that case you dont proebably need any special magic, ls -type should return stuff in load order, wouldnt bet my life on that tough.

whatabout something like this?

CODE
{
    string $before[] = ls;
    //
    // now import stuff
    //
    string $new[] = stringArrayRemove($before, ls);
}

Yes that works but i think you dont need it. Because maya allready orders them that way. Thisway you dont need 2 hooks because 1 is enough.

k but somehow you need to know where to start asking maya..

get numOfItems
import
ask ls numOfItems -> end of array?

I know stringArrayRemove is a heavy script though..

QUOTE
get numOfItems
import
ask ls numOfItems -> end of array?

CODE
$size=size(ls());
Import;
$nulist=ls();
string $return[];
for ($i=$size;$i<size(ls());$i+=1)
  $return[size($return)]=$nulist[$i];

Or simply put somerthing that works if you want say to see the newly imported things in a new set, if the import command was invoked form the default file menu, you could do:
CODE
global proc makeSetOnImport(){
  $size=size(ls());
  Import;
  $nulist=ls();
  string $return[];
  for ($i=$size;$i<size(ls());$i+=1)
    $return[size($return)]=$nulist[$i];
  sets -n "newItems" $return;
}

menuItem -e -c "makeSetOnImport" MayaWindow|mainFileMenu|importFileItem;

Or use a 2 parted script with scriptJob; Former works better for normal users and is way less things to do.

QUOTE(ewerybody @ 05/15/09, 06:18 PM) [snapback]307818[/snapback]
I know stringArrayRemove is a heavy script though..

Yes

A tip for all of you for objects you can and should use set intersections.

Let us assume your node is of type foobar hen list objects of type foobar:

$foobars=ls -et foobar;

Now if you add objects to set at start of type foobar

sets -n mySetToCompareTo ls -et foobar;

You now know what you seek after si NOT in the set, ergo just check

$new=sets -n new (ls("-et","foobar"));
delete sets -sub $new mySetToCompareTo;
delete $new;

would delete newer copies of type foobar that have arrived since you last updated mySetToCompareTo. This is FAST or atelast as fast as you could possibly get with maya since sets are full c++ operands and optimized for this. Not even api code would with any sane likelihood be much faster than this.

Hi !
Thanks everybody for all answers, this is all very interesting. I even found something else few posts below:
"file -returnNewNodes"

This all have one problem, I need to somehow override default maya open/import actions to register nodes before and after it.Now I'm considering redesigning the way I keep info of scene assets, maybe it should be less obscure and more user-controllable. I dunno which of the two is better.
Thx for all answer, at least I know my options

cheers

Just override the Import command on disk. (ie type whatIs Import) copy thet file and modify it. This catches most users, but not scripts,

QUOTE
I need to somehow override default maya open/import actions to register nodes before and after it.

Thats what i did above. NOTHING will however override stuffs you do in scripts save a 2 parted scriptjob. But then the scriptjob can be killed and needs to be resurected all the time.

QUOTE
Now I'm considering redesigning the way I keep info of scene assets,

So how do you do it then? And why would you need to i mean you should probably take assets as references.

right now I have a simple checkIn/checkOut system for maya scenes, so a small team can work safely without losing file (lost or overwriten). I connect a scene with an asset name by maitaining a node with special attribute( asset type and name, etc.). It all works pretty ok, untill other asset nodes come into the scene, then theres a conflict - scene tries to be many assets at the same time.

PS. my assets has nothing to do with assets introduced in maya2009. sorry for any confusion

QUOTE(ogre @ 05/18/09, 05:20 PM) [snapback]307928[/snapback]
so a small team can work safely without losing file (lost or overwriten).

Isnt that why you have progrems like perforce, svn etc...

So shouldnt the chekin be mated with save, and check out with load/import instead?

svn doesnt solve my problem here, which is identyfying which asset current scene represents.

QUOTE(ogre @ 05/18/09, 09:48 PM) [snapback]307939[/snapback]
which is identyfying which asset current scene represents.

my svn seems to be able to tell me whats inside the file without any bigger problem. Without needing to open it in maya. Thats called metadata.

Ok please explain more. Whats your target. I cant instruct on how to solve your problem unless i know what it is.*

Have you tried to use fileInfo? Why exactly is not file name enough for identifying a unique asset type?

Anyway are you sure your not over complicating the problem

QUOTE
right now I have a simple checkIn/checkOut system for maya scenes

Im sorry don't exactly SOUND simple. Thing is dont over complicate stuff, i used to work with a company that insisted in letting users save things to whatever file name keeping a database up to speed on what the file actually was. This to save user form confusion of loosing a file. The problem with this was that users no longer understood what happened they saved a file but it didnt necessarily load that file even if they pointed to it. So as a result the sytem worked well most of the time, except off course for when it didn't. Files not only got lost (even tough the system prevented that) they got mixed up. Because USERS need to intimately know what goes where and why. Because users WILL try to do things you dont anticipate. Including moving files on disk outside maya.

*im not actually interested in your company secrets. But to be honest I cant think of anything so exciting in the system that would make it worth stealing form you. Trust me ive probably seen it happen before.

Ok tested file infos don't stack so that's probably the easiest thing, do:

fileInfo "AssetType" "Something";

on all scenes different something offcourse. Then just import away and the first set stays as file info.

When you then open the thing that was in import separately it DOES retain the file info set to it but not as part of file.

The cool thing about file infos is that its relatively easy to make them visible outside maya so you could sort even the file browsers based on file info if you wished to do so by writing a little helper that scans the first few bytes of a maya file as a shell extension.

QUOTE(Joojaa @ 05/18/09, 11:21 AM) [snapback]307943[/snapback]
Anyway are you sure your not over complicating the problem

haha! I'm not sure at all !
The system worked pretty ok, while there were 3 persons and they didn't do "wrong" things to it. Now we have more artists and I see my setup won't hold for long. I think I need to come up with smth new and more reliable. What I liked in my setup was that artist could checkOut an asset, save it locally, work for some time on the scene, and checkOut only when artist feels that it's worth to do so. I don't like the idea that every saveScene puts an asset back to repository.

I never looked into SVN as an option, how much hassle there's to setup this ? Do I have to save in mayaAscii ?

looking into fileInfo now, seems interesting

QUOTE(ogre @ 05/19/09, 11:23 AM) [snapback]307980[/snapback]
I liked in my setup was that artist could checkOut an asset, save it locally, work for some time on the scene, and checkOut only when artist feels that it's worth to do so. I don't like the idea that every saveScene puts an asset back to repository.

Well i don't really see how the 2 things are related to each other. I use perforce and i can decide form my perforce whan i do check in check out its not tied to my saving. Its just a command line call after all.

Looks like you want some sytem that reminds the user to do it at some point.