[Closed] Transfering CAs when merging max files
What I want is to transfer information(string in this case) between max files when one file is merged to another. This is the code that I use – CA is added to rootNode and when the files are opened separately everything work. But when I merge(using maxscript or manually) one file to the other the CA from the merged file is lost.
I have tried to add CA to Layer 0 but the same happens: the CA from the merged file is not “transfered” to the current scene.
Is there any way to be achieved what I want? It have to work even when one empty scene is merged to another empty scene.
(
resetmaxFile #noPrompt
t = teapot()
-- "save to rootNode"
myData_CA_Def = attributes myDataCA1 version:1 attribID:#(0x51bd3311, 0x1d487e11)
(
parameters main
(
myString type:#string default:"Teapot CA"
)
)
CustAttributes.add rootnode myData_CA_Def
saveMaxFile @"D:\Teapot_01.max"
resetmaxFile #noPrompt
s = sphere()
-- "save to rootNode"
myData_CA_Def = attributes myDataCA2 version:1 attribID:#(0x51bd3312, 0x1d487e12)
(
parameters main
(
myString type:#string default:"Sphere CA"
)
)
CustAttributes.add rootnode myData_CA_Def
saveMaxFile @"D:\Sphere_01.max"
-- "load Teapot_01.max"
resetmaxFile #noPrompt
loadMaxFile @"D:\Teapot_01.max"
-- "print CAs"
MSCustAttribArray = rootnode.custAttributes
for ca in MSCustAttribArray do
(
format "Teapot_01 CA: % \n" ca.myString
)
-- "load Sphere_01.max"
resetmaxFile #noPrompt
loadMaxFile @"D:\Sphere_01.max"
-- "print CAs"
MSCustAttribArray = rootnode.custAttributes
for ca in MSCustAttribArray do
(
format "Sphere_01 CA: % \n" ca.myString
)
-- "merge Teapot_01.max"
mergeMAXFile @"D:\Teapot_01.max"
-- "print CAs"
MSCustAttribArray = rootnode.custAttributes
for ca in MSCustAttribArray do
(
format "Merged CA: % \n" ca.myString
)
)
Is it possible to use a helper and apply CA to it in every max file that you use?
The goal is to avoid any objects that will hold the CA.
If I send you a max file that have such a helper and you merge only few of the objects from this max file in your scene and the helper is not among the merged objects the CA will not be “loaded” in your scene. Because of this I am trying to find a way where even merging one empty scene to another empty scene will transfer the CA from merged scene. So far AppData, CA to rootNode/Layer0 not works as I want.
what do mean by “merging” of CA?
do you need CA instance or CA definition?
as I remember all persistence globals have to be merge with merged scene. It was causing a problem with overwriting of some globals in the current scene. But in your case it might work
Check the code in my first post. Two max files with different CA added to the rootNode of the two files.
When I load Teapot_01.max the added CA is “loaded” and the script prints the value of myString = "Teapot CA"
(myDataCA1 ).
When I load Sphere_01.max the added CA is “loaded” and the script prints the value of myString = "Sphere CA"
(myDataCA2 ).
But when I load Sphere_01.max and then I merge Teapot_01.max in the scene only “Sphere CA”(myDataCA2 ) exist in MSCustAttribArray. The “Teapot CA”(myDataCA1 ) is missing.
What I want is when I merge Teapot_01.max the MSCustAttribArray to hold “Teapot CA”(myDataCA1 ) and “Sphere CA”(myDataCA2 ) so I can access both of them when I want.
I want to avoid this overwritting. Even maxscript help file advice to use CAs instead of persistent globals. But tomorrow I will tray again with persiscent globals.
it seems like the “bug” with persistence globals was fixed since the last time I checked.
so the trick with merged CA doesn’t work. lets look for anything else
i just want to tell… i had a project where was needed to know what objects were merged from.
i used my own “merging” system for it, which actually was:
- xref scene first
- read all tags from this xreffed scene
- merge xreffed scene
the system does do exactly the same – xref and merge/collapse, but if you do it your own you have a chance to do something in-between
It seams that nothng works as I want.
Persistent globals are “merged” but:
When merging or XRef-ing in a file (scene/object XRefs are a special case of merge), when reading in persistent global variables,
1) If the variable being read from the scene file already exists as a persistent global variable, the value of the persistent global is not overwritten. (It was overwritten in versions prior to 3ds Max 8).
2) If the variable exists as a non-persistent global variable, the global variable's value is overwritten.
3) If the variable does not exist as a global variable, a non-persistent global variable will be created. The last 2 behaviors are the same as in previous versions of 3ds Max.
The 3) is the problem. When one file is merged to another the persistent global from the merged file is no longer persistent and persistents.gather()
can’t finds it.