[Closed] How to get the name of a file being merged?
I run the following script
c=transform_script()
c.script="print (\"i am a cone in \"+maxFileName);matrix3 1"
(cone()).controller=c
, and saved the file as “test.max”.
Now if I open this file, Listener will receive a string immediately:
“i am a cone in test.max”
When merging the cone object, especially via drag-and-drop, I hope Listener could get a message like:
“i am a cone merged from text.max”
So, my question is, is there any way, just like using “maxFileName”, to get the name of the file being merged in such a controller’s script.
May be a stupid question
Thanks a lot.
I’m not sure that this is possible, but I think the question I should ask you is why, and what are you trying to do?
J.
Well, it’s a long story;) ,so I try to explain it with a short video, but I “may not post attachments”:sad:
I think you should be able to do so with Custom Attributes…how exactly I can’t say
But I think the easiest way to show which object comes from where would be either to name them appropriately, or put them in named Layers…
You could do something like this:
pseudocode 1:
- open the file you want to merge
- for each object in this file save the name of the file in a CA or userProp or appdata or somehow.
- in the original file register 2 callbacks:
I) preMergeCallback that saves all abjects in the scene into a global array
II) postMergeCallback that finds all objects in the scene that weren’t in the scene before the merge process and print what you need for them.
or you could do something like this:
pseudocode 2:
- like in pseudocode 1.
- for each object in this file add a script controller like you have described only that tell it to print whatever you needed only if there is a global variable in the scene, named for instance “inMerge” and it’s value in true.
- in the original file register 2 callbacks:
I) preMergeCallback that sets “inMerge” to the value true
II) postMergeCallback that sets “inMerge” to the value false
I haven’t checked this but I think it has a good chance to work.
cheers,
Matan.
First of all if you want to keep source info of “merged” objects it’s better to use XRef objects and XRef scenes.
Anyway, how can you tag merged objects?
There is no #merge callback that returns merged file name with callbacks notification. You can just catch the fact of the merging but you can’t say from what source file it was merged. You can use your own script (or tool) for merging and keep tracking all merged objects(#1). But in other cases of merging (using max UI, other scripts or plug-ins, drag-n-drop) you can’t get merged source file name.
I use #1 solution and take care just of the objects merged with my tool (also I add some unique identifier and some info about merging session). Using these tags I can say later which object in the scene was merged with my tool, where from, when, and how.
Also I have (in startup directory) the script that tags all objects in the scene with the file name where this object was created (I’m using #filePreSaveProcess callback). Any merged object keeps its original tag and I can say where this object is originally from.
I am able to upload a little thing now. I am trying to explain my motive with a short video and a .max file saved in Max 2009 on my 32-bit Windows XP.
In the video, I merged a helper object to run a script and start an executable, and later, all the temporary files created on the fly were cleaned up when the object was deleted. It doesn’t matter what all the stuff was, the point is it was embedded in a single .max file. And yes, it’s a weird way.
It works well on my PC, and the main reason I asked the question is that I though, if the temporary files could be created under the same dir with the .max file merged, it would be easier for me to find and clear them manually when something went wrong. But now, I prefer the files just be placed elsewhere simply like $temp, since what I expected seems absolutely not easy to be implemented, and desperately, I may change a .max filename at will.
Many thanks for all your explanations and advices.
video(3.75MB):
http://area.autodesk.com/userdata/forum/d/demo.part1.zip
http://area.autodesk.com/userdata/forum/d/demo.part2.zip