XRef Obj update script/question

Good evening wizards of Xref-land!

I'm working on a script for updating XrefObjs in scenes with identical numbers of objects and running into some trouble...

Before executing the script "C:\\test\\srcScn1.max" exists in the local scene as an Xref record.

These two scenes ("srcScn1" and "SrcScn2") are currently identical in content, I'm just trying to flip the switch to change the 'Xref Object' 'File Name' field before running the update script it's path is "C:\\test\\srcScn1.max"

xr = objXRefMgr
Record = xr.GetRecord 1
a = #()
x = Record.GetItems #XRefAllType a
for i = 1 to x do 
	XRefItem = Record.GetItem i #XRefObjectType 
	if XRefObjectType = true 
	xr.SetXRefItemSrcFile XRefItem "C:\\test\\srcScn2.max"

Listener reports:

-- Error occurred in i loop; filename: S:\net_exe\scripts\maxscript\musevfx\_Referenced-Scripts\___WIP\XRef-Objects\_XrefObjUpdate_v.07.ms; position: 513; line: 14
--  Frame:
--   XRefObjectType: true
--   i: 1
** system exception **

Also I notice that the "old" Xref record and the new are both listed still active, (srcScn1 record still holds the type->'Xref Controller', while srcScn2 now contains the type->'Xref Object. Assuming I need to find a way to move the controller and then use then use 'CombineRecords' to put them together after all Xref paths are set to be sourced from the same file?

I'm assuming I have two distinct problems here (one with the exception caused by my "for" formatting and another where I'm not changing the path on my controller). Hoping I'm close to a breakthrough on this, can anyone point me in the right direction?

I've been heavily referencing

Thanks in advance!



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ehance's picture

A big chunk of the solution...

Alrighty, changed up the way I was iterating bc it was causing the XRef record to freak out (moving entries out at bad intervals I think). Happily this works for swapping out Xref Objects under the entries:

xr = objXRefMgr
Record = xr.GetRecord 1
XRefItem = Record.GetItem 1 #XRefObjectType
a = objXRefs.getAllXRefObjects()
UpdateA = "C:\\test\\srcScn2.max"
for i in a do
	print i.srcItemName
	objName = i.srcItemName as string
	objSel = execute ("select $" + objName + "*")
	XRefItem = Record.GetItem 1 #XRefObjectType
	updatePath = xr.SetXRefItemSrcFile XRefItem UpdateA 

This cleared up any system exceptions with type->'Xref Object.

Are there any brave souls who can help me with the matter of managing the leftover XRef controllers in the old entry? I can't find any reference to those in the docs, open to advice...

The alternative is to just give up on this "replacement" method and scrape out the old entry and replacing with the new, and than creating dictionaries for items (like Obj ID, etc.) I'd like to preserve between versions.

Thanks in advance for any help you can give.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.