Notifications
Clear all
[Closed] Modifier Name Monitor
Sep 23, 2013 2:46 pm
Following this thread ( http://forums.cgsociety.org/showthread.php?f=98&t=1125151 ) issue I’ve made a Structure and functions set to prevent modifiers from renaming by the system. Using File Pre Save event I store modifier name at its AppData, and using File Post Open and Post Merge events I restore the name stored in the AppData.
global ModifierIdentifierMonitor
(
struct ModifierIdentifierStruct
(
private
currentnodes,
public
callbackID = #modifier_identifier_monitor,
MODI_CH = 4512,
mapped fn setModifierIdentifier modi id: channel:MODI_CH = if iskindof modi Modifier do
(
if id == unsupplied do id = modi.name
setappdata modi channel (id as string)
),
mapped fn getModifierIdentifier modi channel:MODI_CH resetName:off = if iskindof modi Modifier do
(
if (d = getappdata modi channel) != undefined and resetName and d != "" do modi.name = d
d
),
fn filePreMerge = (currentnodes = objects as array),
fn setModifierIdentifiers = for node in objects do setModifierIdentifier (join #() node.modifiers),
fn getModifierIdentifiers event:#custom =
(
case event of
(
#filePostOpen:
(
for node in objects where node.modifiers.count > 0 do getModifierIdentifier (join #() node.modifiers) resetName:on
)
#filePostMerge:
(
for node in objects where node.modifiers.count > 0 do
(
if (currentnodes == undefined or finditem currentnodes node == 0) do getModifierIdentifier (join #() node.modifiers) resetName:on
)
currentnodes = undefined
)
)
),
fn deleteCallbacks = (callbacks.removescripts id:callbackID),
fn setCallbacks =
(
deleteCallbacks()
callbacks.addscript #filePreSave "ModifierIdentifierMonitor.setModifierIdentifiers()" id:callbackID
callbacks.addscript #filePostOpen "ModifierIdentifierMonitor.getModifierIdentifiers event:#filePostOpen" id:callbackID
callbacks.addscript #filePreMerge "ModifierIdentifierMonitor.filePreMerge()" id:callbackID
callbacks.addscript #filePostMerge "ModifierIdentifierMonitor.getModifierIdentifiers event:#filePostMerge" id:callbackID
),
on create do
(
setCallbacks()
)
)
ModifierIdentifierMonitor = ModifierIdentifierStruct()
ok
)
Post Merge event need some mechanism to process only merged nodes to protect modifiers which were renamed after scene was loaded and before scene was saved.
PS… everyone is free to use and extend this code but please don’t forget to give me a credit
1 Reply