public void addStatic(StaticObject obj)
        {
            String bodyName  = ((CelestialBody)obj.getSetting("CelestialBody")).bodyName;
            String groupName = (string)obj.getSetting("Group");

            //Debug.Log("Creating object in group " + obj.groupName);

            if (!groupList.ContainsKey(bodyName))
            {
                groupList.Add(bodyName, new Dictionary <string, StaticGroup>());
            }

            if (!groupList[bodyName].ContainsKey(groupName))
            {
                //StaticGroup group = new StaticGroup(bodyName, groupName);
                StaticGroup group = new StaticGroup(groupName, bodyName);
                //Ungrouped objects get individually cached. New acts the same as Ungrouped but stores unsaved statics instead.
                if (groupName == "Ungrouped")
                {
                    group.alwaysActive = true;
                    //group.active = true;
                }

                group.active = true;

                groupList[bodyName].Add(groupName, group);
            }

            groupList[bodyName][groupName].addStatic(obj);
        }
        public void addStatic(StaticObject obj)
        {
            String bodyName = ((CelestialBody) obj.getSetting("CelestialBody")).bodyName;
            String groupName = (string) obj.getSetting("Group");

            //Debug.Log("Creating object in group " + obj.groupName);

            if (!groupList.ContainsKey(bodyName))
                groupList.Add(bodyName, new Dictionary<string, StaticGroup>());

            if (!groupList[bodyName].ContainsKey(groupName))
            {
                //StaticGroup group = new StaticGroup(bodyName, groupName);
                StaticGroup group = new StaticGroup(groupName, bodyName);
                //Ungrouped objects get individually cached. New acts the same as Ungrouped but stores unsaved statics instead.
                if (groupName == "Ungrouped")
                {
                    group.alwaysActive = true;
                    //group.active = true;
                }

                group.active = true;

                groupList[bodyName].Add(groupName, group);
            }

            groupList[bodyName][groupName].addStatic(obj);
        }
        public void exportMasters()
        {
            string sBase = "";
            string activeBodyName = "";

            Dictionary<string, Dictionary<string, StaticGroup>> groupList = new Dictionary<string, Dictionary<string, StaticGroup>>();

            foreach (StaticObject obj in getStaticDB().getAllStatics())
            {
                String bodyName = ((CelestialBody)obj.getSetting("CelestialBody")).bodyName;
                String groupName = (string) obj.getSetting("Group");

                if (!groupList.ContainsKey(bodyName))
                {
                    groupList.Add(bodyName, new Dictionary<string, StaticGroup>());
                    Debug.Log("Added " + bodyName);
                }

                if (!groupList[bodyName].ContainsKey(groupName))
                {
                    StaticGroup group = new StaticGroup(groupName, bodyName);
                    groupList[bodyName].Add(groupName, group);
                    Debug.Log("Added " + groupName);
                }
            }

            foreach (CelestialBody cBody in FlightGlobals.Bodies)
            {
                activeBodyName = cBody.name;
                Debug.Log("activeBodyName is " + cBody.name);

                if (!groupList.ContainsKey(activeBodyName)) continue;

                foreach (StaticGroup group in groupList[activeBodyName].Values)
                {
                    sBase = group.groupName;
                    Debug.Log("sBase is " + sBase);

                    foreach (StaticModel model in staticDB.getModels())
                    {
                        ConfigNode staticNode = new ConfigNode("STATIC");
                        ConfigNode modelConfig = GameDatabase.Instance.GetConfigNode(model.config);

                        //Debug.Log("Model is " + model.getSetting("name"));

                        modelConfig.RemoveNodes("Instances");
                        bool bNoInstances = true;

                        foreach (StaticObject obj in staticDB.getObjectsFromModel(model))
                        {
                            string sObjGroup = (string)obj.getSetting("Group");
                            if (sObjGroup != sBase) continue;

                            ConfigNode inst = new ConfigNode("Instances");

                            foreach (KeyValuePair<string, object> setting in obj.settings)
                            {
                                inst.AddValue(setting.Key, KKAPI.getInstanceSettings()[setting.Key].convertValueToConfig(setting.Value));
                            }
                            modelConfig.nodes.Add(inst);
                            bNoInstances = false;
                        }

                        if (bNoInstances) continue;

                        string sModelName = modelConfig.GetValue("name");
                        modelConfig.AddValue("pointername", sModelName);

                        modelConfig.RemoveValue("name");
                        modelConfig.AddValue("name", "Master" + "_" + sBase + "_" + sModelName);

                        staticNode.AddNode(modelConfig);

                        Directory.CreateDirectory(KSPUtil.ApplicationRootPath + "GameData/KerbalKonstructs/ExportedInstances/Master/" + sBase + "/");
                        staticNode.Save(KSPUtil.ApplicationRootPath + "GameData/KerbalKonstructs/ExportedInstances/Master/" + sBase + "/" + sModelName + ".cfg", "Exported master instances by Kerbal Konstructs");
                    }
                }
            }
        }