Xref objects revert to Xref material

Xref objects revert to Xref material

bertv
Enthusiast Enthusiast
968 Views
5 Replies
Message 1 of 6

Xref objects revert to Xref material

bertv
Enthusiast
Enthusiast

Hey,

Recently I started programming a script to control Xref objects in 3Ds max.
Wondering of there is a way to update Xref objects their materials and controllers
to the original Xref materials and controllers by script?

Such as you can do in the UI by right clicking on the sub-objects and choose
"revert to xref material/controller" -> see image below

Also, is their a way to control which controllers are updates?
I like to only update the scale control!

 

objects_001.jpg

This is the code I have so far

Xrefobjects = objXRefMgr		
for i = 1 to Xrefobjects.recordCount do
(
	tmpRecord = Xrefobjects.GetRecord i
 
        --Update the Xref record file
	tmpRecord.Update()
 
        --Try to update the sub items materials and controllers in the record file
	tmpRecordSubList = tmpRecord.GetItems #XRefObjectType $tmpRecord
	objXRefMgr.ApplyXRefMaterialsToXRefObjects $tmpRecordSubList
	objXRefMgr.ApplyXRefControllersToXRefObjects $tmpRecordSubList
)

 

Regards,
Bert

0 Likes
969 Views
5 Replies
Replies (5)
Message 2 of 6

michaelsonbritt
Advocate
Advocate

In MaxScript, the code below seems to work.  Credit for this answer goes to cgsociety member "inert"; see this forum link.

 

 tmp = #($.baseobject)
 objXrefMgr.ApplyXRefMaterialsToXRefObjects tmp


Cheers,

Michaelson Britt

0 Likes
Message 3 of 6

bertv
Enthusiast
Enthusiast

Thanks,

 

I implemented is as follow:

RecordObjects = objXRefs.getAllXRefObjects()

for i = 1 to RecordObjects.count do
(	
	objXRefMgr.ApplyXRefMaterialsToXRefObjects RecordObjects[i]
	objXRefMgr.ApplyXRefControllersToXRefObjects RecordObjects[i]
)

Any idea how to only update the scale property of the call on ApplyXRefControllersToXRefObjects?

 

Regards

Bert

0 Likes
Message 4 of 6

michaelsonbritt
Advocate
Advocate

>> Any idea how to only update the scale property of the call on ApplyXRefControllersToXRefObjects?

 

If the object is using a PRS controller, you can store the Position and Rotation controller, revert to the XRef controller to get the Scale controller, and then re-apply the Position and Rotation.  A difficulty with your code is mapping from XRef records back to Node entities in order to do that.  Try the code below.

for obj in ($Objects as array) do
(
	if (classof obj.baseobject) == XRefObject do
	(
		ctlRot = obj.Controller.Rotation.Controller
		ctlPos = obj.Controller.Position.Controller
		tmp = #(obj.baseobject)
		objXRefMgr.ApplyXRefControllersToXRefObjects tmp
		obj.Controller.Rotation.Controller = ctlRot
		obj.Controller.Position.Controller = ctlPos
	)
)

Regards,

Michaelson Britt

0 Likes
Message 5 of 6

bertv
Enthusiast
Enthusiast

Thanks,

Works perfectly!

 

Regards

Bert

0 Likes
Message 6 of 6

bertv
Enthusiast
Enthusiast

Hey, Thanks for the help.

 

I have an additional problem with the Xref update using multiple copy's of the record.

In code I added an Xref record with local control xrefOptions:

objXrefMgr.AddXrefItemsFromFile tmpPath promptObjNames:true xrefOptions:#(#xrefModifiers,#localControllers)
		

The added objects contain a controller as seen in the image below

ref_01.JPG

 

Then in code I move and rotate the objects

 

When updating the record with the code below, all the objects jumping back to the original Xref location.

for obj in ($Objects as array) do
(
	if (classof obj.baseobject) == XRefObject do
	(
		ctlRot = obj.Controller.Rotation.Controller
		ctlPos = obj.Controller.Position.Controller
		tmp = #(obj.baseobject)
		objXRefMgr.ApplyXRefControllersToXRefObjects tmp
		obj.Controller.Rotation.Controller = ctlRot
		obj.Controller.Position.Controller = ctlPos
	)
)

The objects now contain a new controller as seen in the image below

 ref_02.JPG

 

I'm a bit confused why I cant put them back on the first positioned location.

Even if the controller transform  is changed from local to xrefed, I should be able to position them back with the

stored position and rotation data.

 

I also tried adding an xref record with  xrefControl as xrefOptions:

But crashes occurred. 

 

Regards,

Bert

 

0 Likes