public void HomeViewpoint_Set(out InwOpView oSV) //Get home viewpoint, reset appearences and set as current viewpoint { Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument; //Reset appearences oDoc.Models.ResetAllPermanentMaterials(); oDoc.Models.ResetAllHiddenToModelState(); oDoc.SetGraduatedBackground(Autodesk.Navisworks.Api.Color.FromByteRGB(105, 140, 230), Autodesk.Navisworks.Api.Color.FromByteRGB(210, 240, 255)); //Set properties for home view Viewpoint oVP = new Viewpoint { //Set quaternion for home view Rotation = new Rotation3D(0.425, 0.176, 0.340, 0.821), Projection = ViewpointProjection.Perspective, RenderStyle = ViewpointRenderStyle.Shaded }; Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentViewpoint.CopyFrom(oVP); // Get a hold of the state object (it is a singleton) InwOpState10 myState = ComApiBridge.State; //Set viewpoint to all model myState.ViewAll(); // create a temporary saved viewpoint oSV = myState.ObjectFactory(nwEObjectType.eObjectType_nwOpView); //Set viewpoint oSV.anonview.ViewPoint = myState.CurrentView.ViewPoint.Copy(); }
private void lbTesteSelClash_MouseUp(object sender, MouseEventArgs e) { //var acd = NavisworksApp.ActiveDocument; //DocumentClash documentClash = acd.GetClash(); //DocumentClashTests documentClashTests = documentClash.TestsData; //ClashTest clashTest = documentClashTests.Tests.First() as ClashTest; //var testesave = clashTest.Children; //List<ClashResult> clashResults = new List<ClashResult>(); //foreach (var item in testesave) //{ // clashResults.Add(item as ClashResult); //} //if (clashResults.Count() > 0) //{ // var testeViewpoint = clashResults.First(x => x.DisplayName == "Clash3"); // ClashItem1 = new ModelItemCollection(); // ClashItem2 = new ModelItemCollection(); // ClashSelectionTransparent = new ModelItemCollection(); // ClashItem1.Add(testeViewpoint.Item1); // ClashItem2.Add(testeViewpoint.Item2); // acd.CurrentSelection.AddRange(ClashItem1); // acd.CurrentSelection.AddRange(ClashItem2); // ClashSelectionTransparent = acd.CurrentSelection.SelectedItems; // acd.State.InvertSelection(); // SaveCurrentViewPointClash(); // //var testeData = teste.TestsData.Tests.FirstOrDefault(); // //if (testeData != null) // //{ // // var save = teste.TestsData; // // var testeSave = testeData as ClashTest; // // var listClahs = testeSave.Children.ToList(); // // var ItemFirst = listClahs.First(); // //} //} InwOpState10 oState; oState = ComApiBridge.State; //find the clash detective plugin InwOpClashElement m_clash = null; foreach (InwBase oPlugin in oState.Plugins()) { if (oPlugin.ObjectName == "nwOpClashElement") { m_clash = (InwOpClashElement)oPlugin; break; } } if (m_clash == null) { System.Windows.Forms.MessageBox.Show( "cannot find clash test plugin!"); return; } //Run all clash test or specific clash //or assume the UI has the results already //m_clash.RunAllTests(null); // get the plug-in of exporting image InwOaPropertyVec options = oState.GetIOPluginOptions("lcodpimage"); // set to the format to png foreach (InwOaProperty opt in options.Properties()) { if (opt.name == "export.image.format") { opt.value = "lcodpexpng"; } } try { // get the first Test and its first clash result InwOclClashTest clashTest = m_clash.Tests()[1]; InwOclTestResult clashResult = clashTest.results()[1]; // create a temporary saved viewpoint InwOpView oSV = oState.ObjectFactory( nwEObjectType.eObjectType_nwOpView); oSV.name = "temp-view"; oSV.anonview.ViewPoint = clashResult.GetSuitableViewPoint().Copy(); oState.SavedViews().Add(oSV); // apply the temp saved viewpoint oState.ApplyView(oState.SavedViews().Last()); // export it to an image //string tempFileName = // "c:\\temp\\" + // clashTest.name + "- " + // clashResult.name + ".PNG"; //oState.DriveIOPlugin( // "lcodpimage", // tempFileName, // options); // delete the temp saved viewpoint oState.SavedViews().RemoveLast(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
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); }