[Closed] Check for and correct duplicate names?
I have a file with about 4,000 objects, the majority of which are mirrored across the x-axis (i.e. half on the left, half on the right). Unfortunately, the left-side objects and right-side objects have the same names as their counterparts. I have already manually renamed some of them, but it would be very time consuming to do this for every object in the file.
What I want to do is:
- Check and see if an object shares an identical name with another.
- If it does, rename them both such that the one on the left side has the suffix of “_L” and the one on the right has the suffix of “_R”
What would be the most expedient way to do this?
Hi Kevin,
here is the code to do the trick. Not super optimized, but should work reasonably well. It assumes there are at max TWO objects with the same name with different X positions. The one with smaller X becomes name_L the one with bigger X, becomes name_R. Save before running the script because undo is disabled to make it run faster.
(
with undo off
(
aObjects = Objects as Array
local baItemChecked = #{}
baItemChecked.count = aObjects.count
for i = 1 to aObjects.count do
(
if (baItemChecked[i] == false) do
(
local sItemName = aObjects[i].name
for j = (i+1) to aObjects.count do
(
if (baItemChecked[j] == false) do
(
if (aObjects[j].name == sItemName) do
(
if (aObjects[j].position.x < aObjects[i].position.x) then
(
aObjects[j].name = aObjects[j].name + "_L"
aObjects[i].name = aObjects[i].name + "_R"
)
else
(
aObjects[j].name = aObjects[j].name + "_R"
aObjects[i].name = aObjects[i].name + "_L"
)
baItemChecked[i] = true
baItemChecked[j] = true
)
)
)
)
)
)
)
- Enrico