Example #1
0
        public static void Save(AssemblyDocument document, FieldProperties fieldProps, List <PropertySet> propertySets)
        {
            Inventor.PropertySets inventorPropertySets = document.PropertySets;

            try
            {
                Inventor.PropertySet p = GetPropertySet(inventorPropertySets, "synthesisField");

                // Field Properties
                SetProperty(p, "spawnpoints", JsonConvert.SerializeObject(fieldProps.spawnpoints));
                SetProperty(p, "gamepieces", JsonConvert.SerializeObject(fieldProps.gamepieces));

                // Property Sets
                SetProperty(p, "propertySets", JsonConvert.SerializeObject(propertySets, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Auto
                }));

                // Occurrences
                for (int i = 0; i < propertySets.Count; i++)
                {
                    var tabPage = (Components.ComponentPropertiesTabPage)Program.MAINWINDOW.GetPropertySetsTabControl().TabPages[propertySets[i].PropertySetID];

                    if (tabPage != null)
                    {
                        Components.InventorTreeView treeView = tabPage.ChildForm.inventorTreeView;
                        List <string> occurrences            = new List <string>();
                        foreach (TreeNode node in treeView.Nodes)
                        {
                            CreateOccurrenceList(node, "", occurrences);
                        }

                        SetProperty(p, "propertySets." + propertySets[i].PropertySetID + ".occurrences", JsonConvert.SerializeObject(occurrences));
                    }
                    else
                    {
                        SetProperty(p, "propertySets." + propertySets[i].PropertySetID + ".occurrences", "[]");
                    }
                }
            }
            catch (Exception e)
            {
                throw new FailedToSaveException(e);
            }
        }
Example #2
0
        private static Inventor.PropertySet GetPropertySet(Inventor.PropertySets sets, string name, bool createIfDoesNotExist = true)
        {
            foreach (Inventor.PropertySet set in sets)
            {
                if (set.Name == name)
                {
                    return(set);
                }
            }

            if (createIfDoesNotExist)
            {
                return(sets.Add(name));
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        public static void Load(AssemblyDocument document, out FieldProperties fieldProps, out List <PropertySet> propertySets, out Dictionary <string, List <string> > occurrencePropSets)
        {
            Inventor.PropertySets inventorPropertySets = document.PropertySets;

            try
            {
                Inventor.PropertySet p = GetPropertySet(inventorPropertySets, "synthesisField");

                // Field Properties
                BXDVector3[] spawnpoints = JsonConvert.DeserializeObject <BXDVector3[]>(GetProperty(p, "spawnpoints", "[]"));
                if (spawnpoints == null)
                {
                    spawnpoints = new BXDVector3[0];
                }

                Gamepiece[] gamepieces = JsonConvert.DeserializeObject <Gamepiece[]>(GetProperty(p, "gamepieces", "[]"));
                if (gamepieces == null)
                {
                    gamepieces = new Gamepiece[0];
                }

                fieldProps = new FieldProperties(spawnpoints, gamepieces);

                // Property Sets
                propertySets = JsonConvert.DeserializeObject <List <PropertySet> >(GetProperty(p, "propertySets", "[]"), new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Auto
                });

                // Occurrences
                occurrencePropSets = new Dictionary <string, List <string> >();

                for (int i = 0; i < propertySets.Count(); i++)
                {
                    occurrencePropSets.Add(propertySets[i].PropertySetID,
                                           JsonConvert.DeserializeObject <List <string> >(GetProperty(p, "propertySets." + propertySets[i].PropertySetID + ".occurrences", "[]")));
                }
            }
            catch (Exception e)
            {
                throw new FailedToLoadException(e);
            }
        }
Example #4
0
 private InvPropertySets(Inventor.PropertySets invPropertySets)
 {
     InternalPropertySets = invPropertySets;
 }
Example #5
0
 public static InvPropertySets ByInvPropertySets(Inventor.PropertySets invPropertySets)
 {
     return(new InvPropertySets(invPropertySets));
 }