View Full Version : convert selected object(s) to Xrefs...

01 January 2009, 09:07 AM
Hi guys,
I want to do thing like the UI button "convert selected object(s) to Xrefs..."
The purpose of this process is swap Object via Xref.
I try the follow code

boneAry = #($bone01,$bone02)
saveNodes boneAry "d:\\123.max" quite:true
bName = for n in boneAry collect
xrefs.addNewXRefObject "d:\\123.max" bName

-- change the srcfilename --
iXref = objXRefMgr.GetRecord 1
iXref.srcFileName = "d:\\123_new.max"

now I have done convert bone to XrefObj.
Change to the source file that i want.
But it become two bone01 and two bone02 in my scenes, not replace.
I have no idea to do the convert part...
Any one knows ... ?

01 January 2009, 10:09 AM
Changing the filename of an xref record shouldn't add new objects to the scene. However, the first part of your code imports the xref with the original nodes still in the scene. Simply delete the nodes after saving should fix that:
boneAry = #($bone01, $bone02)
if saveNodes boneAry "d:\\123.max" quiet:true then
bName = for n in boneAry collect
if xrefs.addNewXRefObject "d:\\123.max" bName != undefined then
delete boneAry
) -- else addNewXRefObject failed
) -- else saveNodes failed

-- change the srcfilename --
--iXref = objXRefMgr.GetRecord 1
--iXref.srcFileName = "d:\\123_new.max"

01 January 2009, 11:07 AM
Thank's for reply!
but my situation is more complicated
because there is a obj have skin modifier refer to the bones.
so i can't delete the origin bone... i need exactly the UI button do, "convert it to Xref...",
I still can't find a way to do it.
Maybe I need to save my skin data to file. Remove the skin mod than add it with new Xref Bone...

but there is a small should in my mind say...the sould be a smart way.

CGTalk Moderation
01 January 2009, 11:07 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.