[Closed] Is modifier in scene?
I have stored reference to a modifier in the scene in a maxObjectTab. Now I want to know if that modifier still exists in the scene. Is there a method for this that I’m missing?
pseudoCode:
isModifierInScene theModifierInstance
it will return the stored modifier as well… beacuse the stored modifier is in the scene
Besides getClassInstances returns all instances of a given class, and from what PEN said I think hes is looking for a SPECIFIC modifier. I’m guessing you are looking for something a bit more “elegant” than a pure bruteforce method?
Ya I have a brute force method. I guess it can’t really work as it is a instance of a class. getClassInstances doesn’t work for that reason. I can still add that modifier to other objects. For now I have it working by searching for what I think it should be on.
Well you could use a getClassInstances for the modifier class of your modifier, and the compare the results with your original item. It’s not perfect, but maybe it’s efficient enough or what you need.
fn findModInScene theModifier =
(
local theModArray = (getClassInstances (classOf theModifier))
local theResult
FOR theMod in theModArray DO
(
IF theResult == undefined AND theMod == theModifier DO theResult = theMod
)
theResult
)
If you have an instance of a modifier stored and you want to know if it is in the scene, you could check the content of the refs.dependents() to see what nodes depend on it:
I created some objects and applied a Bend modifier to one of them.
Then I grabbed the modifier into a variable and did this:
a = $.modifiers[1]
-->Bend:Bend
refs.dependents a
-->#(ReferenceTarget:ModApp, ReferenceTarget:DerivedObject, $Editable_Mesh:Sphere02 @ [7.269565,-36.786465,0.000000])
If you create a new modifier not applied to anything and do the same, nothing depends on it:
b= bend()
-->Bend:Bend
refs.dependents b
-->#()
Unless I am missing something…
Thanks bobo, I tried that but because it is being held in a maxObjectTab in another scripted modifier it returns everything that modifier depends on as well it seams. I didn’t expect and and I guess I should try and set up a simple test to make sure that was the case but that is what I was getting.
if modifier is not applied to any node in the scene and doesn’t exist in any modifier stack this modifier doesn’t have dependency with ModApp Reference Target.
if you call refs.dependents <modifier> for unused modifier you will not see ModApp in dependents list.
fn isUsedAsModifier modi = iskindof modi Modifier and
(
local yes = off
for d in (refs.dependents modi) while not yes do yes = (d as string == "ReferenceTarget:ModApp")
yes
)
Ah yes, didn’t notice that. Thanks Denis. I will see if that is working in my instance.