/// <summary> /// Aula 11 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lbCkeck_MouseUp(object sender, MouseEventArgs e) { var acd = NavisworksApp.ActiveDocument; var allItems = new ModelItemCollection(); allItems.AddRange(acd.CurrentSelection.SelectedItems); var cb = new ModelItemCollection(); foreach (var modelItem in allItems) { cb.Clear(); cb.AddRange(allItems); cb.Remove(modelItem); // Cria o teste de clash var ct = new ClashTest { CustomTestName = modelItem.DisplayName }; ct.DisplayName = ct.CustomTestName; ct.TestType = ClashTestType.Hard; //Scala de conversão var sc = UnitConversion.ScaleFactor(acd.Models.First.Units, Units.Millimeters); ct.Tolerance = Convert.ToDouble(1 / sc); ct.SelectionA.SelfIntersect = false; ct.SelectionA.PrimitiveTypes = PrimitiveTypes.Triangles; ct.SelectionB.SelfIntersect = false; ct.SelectionB.PrimitiveTypes = PrimitiveTypes.Triangles; ct.SelectionA.Selection.CopyFrom(new ModelItemCollection() { modelItem }); ct.SelectionB.Selection.CopyFrom(cb); try { var dc = acd.Clash as DocumentClash; var tcopy = (ClashTest)ct.CreateCopy(); dc.TestsData.TestsAddCopy(tcopy); } catch (Exception) { return; } } }
private static void ProcessClashGroup(List <ClashResultGroup> clashGroups, List <ClashResult> ungroupedClashResults, ClashTest selectedClashTest) { using (Transaction tx = Application.MainDocument.BeginTransaction("Group clashes")) { ClashTest copiedClashTest = (ClashTest)selectedClashTest.CreateCopyWithoutChildren(); //When we replace theTest with our new test, theTest will be disposed. If the operation is cancelled, we need a non-disposed copy of theTest with children to sub back in. ClashTest BackupTest = (ClashTest)selectedClashTest.CreateCopy(); DocumentClash documentClash = Application.MainDocument.GetClash(); int indexOfClashTest = documentClash.TestsData.Tests.IndexOf(selectedClashTest); documentClash.TestsData.TestsReplaceWithCopy(indexOfClashTest, copiedClashTest); int CurrentProgress = 0; int TotalProgress = ungroupedClashResults.Count + clashGroups.Count; Progress ProgressBar = Application.BeginProgress("Copying Results", "Copying results from " + selectedClashTest.DisplayName + " to the Group Clashes pane..."); foreach (ClashResultGroup clashResultGroup in clashGroups) { if (ProgressBar.IsCanceled) { break; } documentClash.TestsData.TestsAddCopy((GroupItem)documentClash.TestsData.Tests[indexOfClashTest], clashResultGroup); CurrentProgress++; ProgressBar.Update((double)CurrentProgress / TotalProgress); } foreach (ClashResult clashResult in ungroupedClashResults) { if (ProgressBar.IsCanceled) { break; } documentClash.TestsData.TestsAddCopy((GroupItem)documentClash.TestsData.Tests[indexOfClashTest], clashResult); CurrentProgress++; ProgressBar.Update((double)CurrentProgress / TotalProgress); } if (ProgressBar.IsCanceled) { documentClash.TestsData.TestsReplaceWithCopy(indexOfClashTest, BackupTest); } tx.Commit(); Application.EndProgress(); } }
public override int Execute(params string[] parameters) { string documentspath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string fileoutpath = documentspath + "\\" + "CoordinationModel.nwd"; Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument; double scalefactor = UnitConversion.ScaleFactor(Units.Meters, doc.Units); DocumentSelectionSets myselectionsets = doc.SelectionSets; ModelItemCollection clipbox = new ModelItemCollection(); foreach (SavedItem childItem in ((GroupItem)myselectionsets.RootItem).Children) { if (childItem.DisplayName == "hidden") { SelectionSet oSet = childItem as SelectionSet; doc.Models.SetHidden(oSet.ExplicitModelItems, false); myselectionsets.Remove((GroupItem)myselectionsets.RootItem, oSet); } else if (childItem.DisplayName == "clipbox") { SelectionSet oSet = childItem as SelectionSet; clipbox.AddRange(oSet.ExplicitModelItems); } } Point3D selbbmin, selbbmax; if (parameters.Length == 0) { ModelItemCollection mysel = doc.CurrentSelection.SelectedItems; selbbmin = mysel.BoundingBox().Min; selbbmax = mysel.BoundingBox().Max; } else { fileoutpath = @parameters[0]; selbbmin = new Point3D(Convert.ToDouble(parameters[1].Replace("neg", "-")) * scalefactor, Convert.ToDouble(parameters[2].Replace("neg", "-")) * scalefactor, Convert.ToDouble(parameters[3].Replace("neg", "-")) * scalefactor); selbbmax = new Point3D(Convert.ToDouble(parameters[4].Replace("neg", "-")) * scalefactor, Convert.ToDouble(parameters[5].Replace("neg", "-")) * scalefactor, Convert.ToDouble(parameters[6].Replace("neg", "-")) * scalefactor); } if (selbbmin.IsOrigin && selbbmax.IsOrigin) { doc.SaveFile(fileoutpath); return(0); } string logfile = documentspath + "\\" + Path.GetFileName(fileoutpath) + ".txt"; List <string> log = new List <string>(); //log.Add("scalefactor###" + scalefactor); //selbbmin = new Point3D(-7.000, 14.000, 17.000); //selbbmax = new Point3D(-5.000, 16.000, 19.000); Point3D mid = selbbmin.ToVector3D().Add(selbbmax).ToVector3D().Divide(2).ToPoint3D(); Vector3D diff = new Point3D(1, 1, 1).ToVector3D(); double deltaval = 0.01; Vector3D delta = new Point3D(deltaval, deltaval, deltaval).ToVector3D(); double clearance = 0; while (diff.X > 0 && diff.Y > 0 && diff.Z > 0) { clearance += deltaval; selbbmax = selbbmax.Subtract(delta); selbbmin = selbbmin.Add(delta); diff = selbbmax.ToVector3D().Subtract(selbbmin.ToVector3D()); } Transform3D EndTransform = new Transform3D(); Transform3DComponents Transform3DComponent = EndTransform.Factor(); Transform3DComponent.Scale = selbbmax.ToVector3D().Subtract(selbbmin.ToVector3D()); Rotation3D ScaleOrientation = new Rotation3D(new UnitVector3D(0, 0, 1), 0); Transform3DComponent.Rotation = ScaleOrientation; Transform3DComponent.Translation = mid.ToVector3D(); EndTransform = Transform3DComponent.Combine(); doc.Models.OverridePermanentTransform(clipbox, EndTransform, true); try { DocumentClash documentClash = doc.GetClash(); DocumentClashTests myClashTests = documentClash.TestsData; ClashTest myClashTestorg = myClashTests.Tests[0] as ClashTest; ClashTest myClashTest = myClashTestorg.CreateCopy() as ClashTest; myClashTest.TestType = ClashTestType.Clearance; myClashTest.Tolerance = Math.Pow((3 * Math.Pow(clearance, 2)), 0.5); myClashTest.Status = ClashTestStatus.New; myClashTests.TestsEditTestFromCopy(myClashTestorg, myClashTest); myClashTests.TestsRunTest(myClashTestorg); myClashTest = myClashTests.Tests[0] as ClashTest; ModelItemCollection myClashingElements = new ModelItemCollection(); for (var i = 0; i < myClashTest.Children.Count; i++) { ClashResult myClash = myClashTest.Children[i] as ClashResult; myClashingElements.AddRange(myClash.Selection2); } myClashingElements.Invert(doc); doc.Models.SetHidden(myClashingElements, true); SelectionSet allhidden = new SelectionSet(myClashingElements); allhidden.DisplayName = "hidden"; myselectionsets.AddCopy(allhidden); myClashTests.TestsClearResults(myClashTest); //clipbox.AddRange((doc.SelectionSets.RootItem.Children[0] as SelectionSet).GetSelectedItems()); doc.Models.ResetPermanentTransform(clipbox); doc.SaveFile(fileoutpath); } catch (Exception e) { log.Add(e.Message + "###" + e.StackTrace); } finally { File.WriteAllText(logfile, string.Join("\r\n", log)); } return(0); }