From cf7db7486386e0a85997b3e02508a58e1bb39a35 Mon Sep 17 00:00:00 2001
From: NullBite <me@nullbite.com>
Date: Wed, 23 Mar 2022 01:31:05 -0400
Subject: [PATCH] Add function to get all child parts recursively

---
 script.lua | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/script.lua b/script.lua
index 1ed0c8e..2fd0357 100644
--- a/script.lua
+++ b/script.lua
@@ -184,6 +184,21 @@ function debugPrint(var)
 	return var
 end
 
+--- Recursively walk a model tree and return a table containing the group and each of its sub-groups
+--- @param group table The group to recurse
+--- @return table Resulting table
+function recurseModelGroup(group)
+	local t={}
+	table.insert(t, group)
+	if group.getType()=="GROUP" then
+		for k, v in pairs(group.getChildren()) do
+			for _, v2 in pairs(recurseModelGroup(v)) do
+				table.insert(t, v2)
+			end
+		end
+	end
+	return t
+end
 -- }}}
 
 -- master state variables and configuration (do not access within pings) -- {{{