-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathReferenced handles highlight.lua
78 lines (64 loc) · 1.61 KB
/
Referenced handles highlight.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
sim = require 'sim'
function sysCall_info()
return {
autoStart = sim.getNamedBoolParam('referencedHandlesHighlight.autoStart') ~= false,
menu = 'Misc\nReferences handles highlight',
}
end
function sysCall_init()
toRestore = {}
end
function sysCall_addOnScriptSuspend()
return {cmd = 'cleanup'}
end
function sysCall_cleanup()
restore()
end
function highlight(handle)
table.insert(
toRestore,
{handle = handle, color = sim.getObjectInt32Param(handle, sim.objintparam_hierarchycolor)}
)
sim.setObjectInt32Param(handle, sim.objintparam_hierarchycolor, 1)
end
function restore()
for i, t in ipairs(toRestore) do
-- pcall because during (model) deletion the handle might be already invalid
pcall(sim.setObjectInt32Param, t.handle, sim.objintparam_hierarchycolor, t.color)
end
toRestore = {}
end
function update()
sysCall_selChange {sel = sim.getObjectSel()}
end
function sysCall_selChange(inData)
restore()
if #inData.sel == 1 then
local rh = sim.getReferencedHandles(inData.sel[1])
local handles = {}
for i, h in ipairs(rh) do
handles[h] = true
end
for h in pairs(handles) do
pcall(highlight, h) -- referenced handle might be invalid
end
end
end
function sysCall_beforeCopy(inData)
restore()
end
function sysCall_afterCopy(inData)
update()
end
function sysCall_beforeSave()
restore()
end
function sysCall_afterSave()
update()
end
function sysCall_beforeInstanceSwitch()
restore()
end
function sysCall_afterInstanceSwitch()
update()
end