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); }
public override int Execute(params string[] parameters) { // current document (.NET) Document doc = Application.ActiveDocument; // current document (COM) InwOpState10 cdoc = ComApiBridge.State; // current selected items ModelItemCollection items = doc.CurrentSelection.SelectedItems; if (items.Count > 0) { // input dialog InputDialog dialog = new InputDialog(); dialog.ShowDialog(); foreach (ModelItem item in items) { // convert ModelItem to COM Path InwOaPath citem = (InwOaPath)ComApiBridge.ToInwOaPath(item); // Get item's PropertyCategoryCollection InwGUIPropertyNode2 cpropcates = (InwGUIPropertyNode2)cdoc.GetGUIPropertyNode(citem, true); // create a new Category (PropertyDataCollection) InwOaPropertyVec newcate = (InwOaPropertyVec)cdoc.ObjectFactory(nwEObjectType.eObjectType_nwOaPropertyVec, null, null); // create a new Property (PropertyData) InwOaProperty newprop = (InwOaProperty)cdoc.ObjectFactory(nwEObjectType.eObjectType_nwOaProperty, null, null); // set PropertyName newprop.name = dialog.PropertyName + "_InternalName"; // set PropertyDisplayName newprop.UserName = dialog.PropertyName; // set PropertyValue newprop.value = dialog.PropertyValue; // add PropertyData to Category newcate.Properties().Add(newprop); // add CategoryData to item's CategoryDataCollection cpropcates.SetUserDefined(0, dialog.CategoryName, dialog.CategoryName + "_InternalName", newcate); } } return(0); }
public override void Stream(IList <Data> datas, object obj) { ComApi.InwOaPath path = ComBridge.ToInwOaPath((ModelItem)obj); StreamInternal(datas, path); }
void oDoc_FileSaving(object sender, System.EventArgs e) { //in theory, since we have removed the tab timely in selection changing, // there should be only one node that still contains the custom tab. this node is the last selected node. //so get it out and remove the properties. //in case there are more nodes, this code can also remove their custom tabs. if (sender != null) { Document oDoc = sender as Document; if (oDoc.Title == "gatehouse.nwd") { try { //firstly use .NET API to get the items with custom tab Search search = new Search(); search.Selection.SelectAll(); search.SearchConditions.Add(SearchCondition.HasCategoryByDisplayName(mytabname)); ModelItemCollection items = search.FindAll(oDoc, false); ComApi.InwOpState9 oState = ComApiBridge.State; foreach (ModelItem oitem in items) { //convert .NET items to COM items ComApi.InwOaPath3 oPath = ComApiBridge.ToInwOaPath(oitem) as ComApi.InwOaPath3; if ((oPath.Nodes().Last() as ComApi.InwOaNode).IsLayer) { //check whether the custom property tab has been added. int customProTabIndex = 1; ComApi.InwGUIPropertyNode2 nodePropertiesOwner = oState.GetGUIPropertyNode(oPath, true) as ComApi.InwGUIPropertyNode2; ComApi.InwGUIAttribute2 customTab = null; foreach (ComApi.InwGUIAttribute2 nwAtt in nodePropertiesOwner.GUIAttributes()) { if (!nwAtt.UserDefined) { continue; } if (nwAtt.ClassUserName == mytabname) { //remove the custom tab nodePropertiesOwner.RemoveUserDefined(customProTabIndex); customTab = nwAtt; break; } customProTabIndex += 1; } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } }
public void Add_newTab(IEnumerable <ModelItem> items, string[] Lines, int N) { // Intialize the parameters ComApi.InwOpState9 oState = ComApiBridge.State; string[] OldCategory = new string[N]; string[] OldParameters = new string[N]; string[] NewParameters = new string[N]; string[] Parameters_hasAdded = new string[N]; int ind = 0; Boolean Parameter_isNotRepeated = true; ComApi.InwOaProperty[] NewProperties = new ComApi.InwOaProperty[N]; // Iterate over all the selected items foreach (ModelItem oItem in items) { if (oItem.Children.Count() > 0) { // Convert the .NET to COM object ComApi.InwOaPath oPath = ComApiBridge.ToInwOaPath(oItem); // Create new property category ComApi.InwOaPropertyVec newPvec = (ComApi.InwOaPropertyVec)oState.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwOaPropertyVec, null, null); // Get properties collection of the path ComApi.InwGUIPropertyNode2 propn = (ComApi.InwGUIPropertyNode2)oState.GetGUIPropertyNode(oPath, true); // Iterate over all properties in textfile ind = 0; for (int i = 1; i < N; i++) { // Check if line is empty if (Lines[i] != null && Lines[i].Length > 1) { // Get Category, old property and new property from the line string[] WordsInLine = Lines[i].Split('\t'); OldCategory[i] = WordsInLine[0]; OldParameters[i] = WordsInLine[1]; NewParameters[i] = WordsInLine[2]; // By default the property is not repeated Parameter_isNotRepeated = true; // Iterate over properties of the item foreach (PropertyCategory oPC in oItem.PropertyCategories) { if (oPC.DisplayName == OldCategory[i]) { foreach (DataProperty oDP in oPC.Properties) { if (oDP.DisplayName == OldParameters[i]) { // Create new property NewProperties[i] = (ComApi.InwOaProperty)oState.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwOaProperty, null, null); NewProperties[i].name = NewParameters[i]; NewProperties[i].UserName = NewParameters[i]; // Check if the property had been added Parameters_hasAdded[ind] = NewParameters[i]; ind = ind + 1; for (int d = 0; d < ind - 1; d++) { if (NewParameters[i] == Parameters_hasAdded[d]) { Parameter_isNotRepeated = false; } } // If the property had not added yet, add it if (Parameter_isNotRepeated) { // Check datatype of the property switch (oDP.Value.DataType) { case VariantDataType.Boolean: bool NewValueBool = oDP.Value.ToBoolean(); NewProperties[i].value = NewValueBool; break; case VariantDataType.DateTime: DateTime NewValueDate = oDP.Value.ToDateTime(); NewProperties[i].value = NewValueDate; break; case VariantDataType.DisplayString: string NewValueDString = oDP.Value.ToDisplayString(); NewProperties[i].value = NewValueDString; break; case VariantDataType.Double: double NewValueDouble = oDP.Value.ToDouble(); NewProperties[i].value = NewValueDouble; break; case VariantDataType.DoubleAngle: double NewValueAngle = oDP.Value.ToDoubleAngle(); NewProperties[i].value = NewValueAngle; break; case VariantDataType.DoubleArea: double NewValueArea = oDP.Value.ToDoubleArea(); NewProperties[i].value = NewValueArea * Math.Pow(meter_scale, 2); break; case VariantDataType.DoubleLength: double NewValueLength = oDP.Value.ToDoubleLength(); NewProperties[i].value = NewValueLength * meter_scale; break; case VariantDataType.DoubleVolume: double NewValueVolume = oDP.Value.ToDoubleVolume(); NewProperties[i].value = NewValueVolume * Math.Pow(meter_scale, 3); break; case VariantDataType.IdentifierString: string NewValueIString = oDP.Value.ToIdentifierString(); NewProperties[i].value = NewValueIString; break; case VariantDataType.Int32: int NewValueInt = oDP.Value.ToInt32(); NewProperties[i].value = NewValueInt; break; case VariantDataType.NamedConstant: NamedConstant NewValueConst = oDP.Value.ToNamedConstant(); String s = NewValueConst.DisplayName; s = s.Substring(s.IndexOf("\"") + 1); s = s.Substring(0, s.IndexOf("\"")); NewProperties[i].value = s; break; case VariantDataType.None: string NewValueNone = oDP.Value.ToString(); NewProperties[i].value = NewValueNone; break; case VariantDataType.Point3D: string NewValuePoint = oDP.Value.ToString(); NewProperties[i].value = NewValuePoint; break; } // Add the new property to the new property category newPvec.Properties().Add(NewProperties[i]); } } } } } } } // Add new tab to the object // The name of the newtab is saved in first line in the textfile propn.SetUserDefined(0, Lines[0], "MyAttribute", newPvec); } } }