public override int Execute(params string[] parameters)
        {
            // current document
            Document doc = Application.ActiveDocument;
            // COM state object
            InwOpState10 cdoc = ComApiBridge.State;
            // current selected items
            ModelItemCollection items = doc.CurrentSelection.SelectedItems;
            // convert ModelItem to COM Path
            InwOaPath citem = ComApiBridge.ToInwOaPath(items[0]);
            // Get item's PropertyCategoryCollection object
            InwGUIPropertyNode2 cpropcates = (InwGUIPropertyNode2)cdoc.GetGUIPropertyNode(citem, true);
            // Get PropertyCategoryCollection data
            InwGUIAttributesColl propCol = cpropcates.GUIAttributes();

            // loop propertycategory
            foreach (InwGUIAttribute2 i in propCol)
            {
                // if category's name match
                if (i.UserDefined && i.ClassUserName == "Premier League")
                {
                    // overwritten the existing propertycategory with
                    // newly created propertycategory(existing + new)
                    cpropcates.SetUserDefined(1, "Premier League", "PremierLeague_InternalName",
                                              AddNewPropertyToExtgCategory(i));
                }
            }

            return(0);
        }
Beispiel #2
0
        private static void SetValues(ModelItem m, string CategoryName, string PropertyName, string value)
        {
            state = ComApiBridge.State;
            InwOaPath oPath = ComApiBridge.ToInwOaPath(m);

            // get properties collection of the path

            InwGUIPropertyNode2 propertyNode = state.GetGUIPropertyNode(oPath, true) as InwGUIPropertyNode2;

            // creating tab (Category), property null variables as placeholders
            InwGUIAttribute2 existingCategory = null;

            //Index of userDefined Tab
            int index = 1;

            //Case 1: Look for an existing category with the same CategoryName

            foreach (Autodesk.Navisworks.Api.Interop.ComApi.InwGUIAttribute2 attribute in propertyNode.GUIAttributes())
            {
                if (attribute.UserDefined)
                {
                    if (attribute.ClassUserName == CategoryName)
                    {
                        existingCategory = attribute;
                        NavisProperties properties = new NavisProperties(PropertyName, value, existingCategory);
                        setProperty(properties, index, propertyNode);
                        return;
                    }

                    index++;
                }
            }


            //Case 2: Category doesn´t exist, create category and property
            if (existingCategory == null)
            {
                NavisProperties properties = new NavisProperties(PropertyName, value, CategoryName);
                setCategoryAndProperty(properties, propertyNode);
                return;
            }
        }