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); }
GetSortedFragments(ModelItemCollection modelItems) { ComApi.InwOpState oState = ComBridge.State; ComApi.InwOpSelection oSel = ComBridge.ToInwOpSelection(modelItems); // To be most efficient, you need to lookup an efficient // EqualityComparer for the int[] key var pathDict = new Dictionary <int[], Stack <ComApi.InwOaFragment3> >(); foreach (ComApi.InwOaPath3 path in oSel.Paths()) { // This yields ONLY unique fragments // ordered by geometry they belong to foreach (ComApi.InwOaFragment3 frag in path.Fragments()) { int[] pathArr = ((Array)frag.path.ArrayData).ToArray <int>(); if (!pathDict.TryGetValue(pathArr, out Stack <ComApi.InwOaFragment3> frags)) { frags = new Stack <ComApi.InwOaFragment3>(); pathDict[pathArr] = frags; } frags.Push(frag); } } return(pathDict); }
public NavisGeometry() { // Add Selected Items to oModelColl Property oModelColl = NavisApplication.ActiveDocument.CurrentSelection.SelectedItems; //convert to COM selection oSel = ComBridge.ToInwOpSelection(oModelColl); }
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()); } } } }
private void ClashByCOMAPI() { try { ComAPI.InwOpState10 oState; oState = COMBridge.State; //find the clash detective plugin ComAPI.InwOpClashElement m_clash = null; foreach (ComAPI.InwBase oPlugin in oState.Plugins()) { if (oPlugin.ObjectName == "nwOpClashElement") { m_clash = (ComAPI.InwOpClashElement)oPlugin; break; } } if (m_clash == null) { System.Windows.Forms.MessageBox.Show( "cannot find clash test plugin!"); } System.Globalization.CultureInfo cultureInfo = System.Globalization.CultureInfo.CreateSpecificCulture("en-US"); string format = "ddd MMM d HH:mm:ss zz00 yyyy"; List <ClashTestCls> tests_array = new List <ClashTestCls>(); foreach (ComAPI.InwOclClashTest test in m_clash.Tests()) { ClashTestCls oEachTest = new ClashTestCls(); oEachTest.DisplayName = test.name; List <ClashResultCls> test_results_array = new List <ClashResultCls>(); foreach (ComAPI.InwOclTestResult issue in test.results()) { ClashResultCls oEachResult = new ClashResultCls(); oEachResult.DisplayName = issue.name; oEachResult.ApprovedBy = issue.ApprovedBy; oEachResult.Status = issue.status.ToString(); //oEachResult.Found = issue.CreatedTime.ToUniversalTime().ToString(); ModelItem oMI1 = COMBridge.ToModelItem(issue.Path1); string path1_id = oMI1.PropertyCategories.FindPropertyByDisplayName("Entity Handle", "Value").Value.ToDisplayString(); oEachResult.path1ID = path1_id; ModelItem oMI2 = COMBridge.ToModelItem(issue.Path2); string path2_id = oMI2.PropertyCategories.FindPropertyByDisplayName("Entity Handle", "Value").Value.ToDisplayString(); oEachResult.path2ID = path2_id; oEachResult.viewpoint = new ClashResultVP(); ComAPI.InwNvViewPoint vp = issue.GetSuitableViewPoint(); oEachResult.viewpoint.Position = new double[3] { vp.Camera.Position.data1, vp.Camera.Position.data2, vp.Camera.Position.data3 }; ComAPI.InwLVec3f oDirVec = vp.Camera.GetViewDir(); oEachResult.viewpoint.Target = new double[3] { vp.Camera.Position.data1 + vp.FocalDistance * oDirVec.data1, vp.Camera.Position.data2 + vp.FocalDistance * oDirVec.data2, vp.Camera.Position.data3 + vp.FocalDistance * oDirVec.data3 }; ComAPI.InwLVec3f upVec = vp.Camera.GetUpVector(); oEachResult.viewpoint.UpVec = new double[3] { upVec.data1, upVec.data2, upVec.data3 }; ComAPI.InwLRotation3f rot = vp.Camera.Rotation; oEachResult.viewpoint.RotAxis = new double[3] { rot.GetAxis().data1, rot.GetAxis().data2, rot.GetAxis().data3 }; oEachResult.viewpoint.RotAngle = rot.angle; test_results_array.Add(oEachResult); } oEachTest.ClashResults = test_results_array.ToArray(); tests_array.Add(oEachTest); } //Test string jsonStr = JsonConvert.SerializeObject(tests_array.ToArray()); const String strClient = "http://localhost:3001"; RestClient _thisclient = new RestClient(strClient); RestRequest authReq = new RestRequest(); authReq.Resource = "ClashTestRoute/postNewClash"; authReq.Method = Method.POST; byte[] fileData = System.Text.Encoding.Default.GetBytes(jsonStr); authReq.AddParameter("Content-Length", fileData.Length); authReq.AddHeader("Content-Type", "application/octet-stream"); authReq.AddFile("file", fileData, "clashtestresult.json", "application/octet-stream"); IRestResponse result = _thisclient.Execute(authReq); if (result.StatusCode == System.Net.HttpStatusCode.OK) { System.Windows.Forms.MessageBox.Show("The updated clash json has been sent to server successfully!"); } else { System.Windows.Forms.MessageBox.Show("failed to upload clash json to server! " + result.StatusCode.ToString()); } } catch (Exception ex) { System.Windows.Forms.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); } } }
public void ViewpointsCreation(out bool ClashTestsResultsExist) { InwOpGroupView TopGroup = null; ProjectionChange_Ort(); ChangeModelColor(); ClashTestsResultsExist = false; try { foreach (InwOclClashTest clashTest in m_clash.Tests()) { clashTest.status = nwEClashTestStatus.eClashTestStatus_OK; if (clashTest.results().Count == 0) { continue; } ClashTestsResultsExist = true; if (TopGroup == null) { TopGroup = TopGroupCreate(); } InwOpGroupView SubGroup = SubGroupCreate(clashTest, TopGroup); // get the first Test and its first clash result foreach (InwOclTestResult clashResult in clashTest.results()) { if (clashResult.status == nwETestResultStatus.eTestResultStatus_ACTIVE | clashResult.status == nwETestResultStatus.eTestResultStatus_NEW) { ModelItem oItem1 = null; ModelItem oItem2 = null; //Get clashed items oItem1 = ComApiBridge.ToModelItem(clashResult.Path1); oItem2 = ComApiBridge.ToModelItem(clashResult.Path2); //Put clashed items to model collection ModelItemCollection ClashedItems = new ModelItemCollection { oItem1, oItem2 }; //Overwrite items color oDoc.Models.OverridePermanentColor(new ModelItem[1] { ClashedItems.ElementAtOrDefault(0) }, Autodesk.Navisworks.Api.Color.Red); oDoc.Models.OverridePermanentColor(new ModelItem[1] { ClashedItems.ElementAtOrDefault(1) }, Autodesk.Navisworks.Api.Color.Green); // Create a copy of current selection ComApi.InwOpSelection ComClashSelection = ComApiBridge.ToInwOpSelection(ClashedItems); // Create a new empty selection InwOpSelection2 AllModel = oState.ObjectFactory(nwEObjectType.eObjectType_nwOpSelection, null, null) as InwOpSelection2; // Get the new selection to contain the entire model AllModel.SelectAll(); // Subtract the current selection, so it contains the unselected part of model AllModel.SubtractContents(ComClashSelection); // create a temporary saved viewpoint InwOpView oSV = oState.ObjectFactory(nwEObjectType.eObjectType_nwOpView); //Apply attributes oSV.ApplyHideAttribs = true; oSV.ApplyMaterialAttribs = true; oSV.name = clashResult.name; //Get and save viewpoint oSV.anonview.ViewPoint = clashResult.GetSuitableViewPoint().Copy(); SubGroup.SavedViews().Add(oSV); oDoc.Models.OverridePermanentColor(new ModelItem[1] { ClashedItems.ElementAtOrDefault(0) }, Autodesk.Navisworks.Api.Color.FromByteRGB(63, 63, 63)); oDoc.Models.OverridePermanentColor(new ModelItem[1] { ClashedItems.ElementAtOrDefault(1) }, Autodesk.Navisworks.Api.Color.FromByteRGB(63, 63, 63)); oDoc.CurrentSelection.Clear(); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } if (TopGroup == null) { return; } oState.SavedViews().Add(TopGroup); }