So,
Xrefs seem to work in Max now… as long you don’t try and get them setup through script it seems.
It is more likely that I am doing it wrong.
Here is the code I am using at the moment:
-- Get all the names of the objects in the target file.
objNames = getMAXFileObjectNames charFile
-- Xref all of the objects.
objXRefMgr.mergeTransforms = False
xrefs.addNewXRefObject charFile objNames modifiers:#merge manipulators:#merge dupMtlNameAction:#useXRefed
-- Set all of the controllers to be local to the scene, so no animation is lost.
for obj in Objects do
(
Try
(
obj.Transform.Controller.xrefCtrlStatus = #Local
)
Catch()
)
This merges the modifiers in, which pretty much defeats the point of setting up the Xrefs, but it keeps the file stable once re-opened.
However, the custom attributes lose their references to other modifier objects which is lovely…
If I xRef the modifiers (as they would be if done through the xRef objects dialogue), then the scene completely loses it’s sh!t when re-opened.
Has anyone else had a poke around with this yet, and if so, had any success xReffing a full and complex rig into a scene?
Thanks in advance.
Anyway, I am not sure if I have found the correct way of doing it, or just the hacky way (as is the norm with max).
I have managed to get it stable and functional doing the following:
- Make sure there are no objects with duplicate names, a normality for rig creation really, but extra relevant now or you will end up having meshes skinned to the incorrect objects etc…
- Run “objXRefs.reloadFile” after the file xRef is initially setup. - Figured this out by sheer happenstance…
It doesn’t seem logical to me, hence why I think it is a bit of a hack but it works. Presumably the reloadFile function adds the correct re-build logic to the file.
here is the completed function that I am using, hope it will help anyone else trying to figure this out for the first time:
fn fn_Char_Imp_Import_Character inFile useXref:True =(
--Get the names of the objects in the target file
Local objNames = getMAXFileObjectNames inFile
if useXref Then
(
objXRefMgr.mergeTransforms = False
--xRef the rig
xRefs.addNewXRefObject inFile objNames modifiers:#xRef manipulators:#merge dupMtlNameAction:#useXRefed
--Set all xReffed controllers to be local, thus allowing animation to occur without being overwritten.
for obj in Objects do
(
Try
(
obj.Transform.Controller.xrefCtrlStatus = #Local
)
Catch()
)
objXRefs.reloadFile inFile
)
Else
(
mergeMAXFile inFile #select #mergeDups #renameMtlDups
)
)
I don’t directly have an answer to your, but I was wondering if you looked into containers?
I have always had bad experiences with Xrefs and I was told by Autodesk once this features was quite deprecated and containers was there to replaced it.
Until their most recent release (2016) this has always been the case. But they have made xRefs functional. We have been using it for a couple of months so far, but I have only started looking into updating our in house tools to use xRefs instead of merging in rigs. It seems to work pretty spot on so far.