Notifications
Clear all

[Closed] ReplaceInstances Undefined Object?

Is it possible to use replaceInstances to effectively remove references to a maxobject?

Practical example being if you had Raytrace maps in a bunch of materials and you just wanted to replace them with nothing.

8 Replies

In this case, this will probably be fine.

For o in getclassinstances raytrace do replaceinstances o (vrayColor color:black)

refs.replaceReference has to be able to replace with undefined

1 Reply
(@davewortley)
Joined: 11 months ago

Posts: 0

I cant seem to find any documentation for refs.replaceReference…

When you cannot find maxscript documentation, turn to the SDK one :wip: Something like this should work:

tmaps = getClassInstances Raytrace

for map in tmaps do
	for ref in refs.dependents map do
		for i = 1 to refs.getNumRefs ref
			where refs.getReference ref i == map do
			(
				refs.replaceReference ref i undefined
				notifyDependents ref
			)


1 Reply
(@polytools3d)
Joined: 11 months ago

Posts: 0

Or search the latest online help. It was previously undocumented.
MAXWrapper Common Properties, Operators, and Methods

refs.replaceReference <max_obj> <int> {<max_obj> | undefined}
Replaces the reference at index <int> with either a new reference or undefined (effectively removing the reference). Note: this is an unsafe method and will crash 3ds Max if you do not know what you are doing.

I like the warning

A Bug Report:

(Note: this is an unsafe method and will crash 3ds Max if you do not know what you are doing)

According to your documentation the Max has to crash in my case, because I’ve completely didn’t know what I was doing. But the Max didn’t crash. What was I doing wrong? Please fix this unexpected behavior.

Isn’t it nice?
I wonder, if I know what I am doing, why would I care to look at the Help?
Otherwise, I should not use it, as I don’t know what I am doing, and no one cares to explain.