public override void Calculate() { List <object> clashResultList = new List <object>(); var input = InputPorts[0].Data; //Get clashes from document Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument; //Check for null in input if (MainTools.IsList(input)) { foreach (var i in (System.Collections.IEnumerable)input) { if (i.GetType() == typeof(SavedItemReference)) { ClashTest item = doc.ResolveReference(i as SavedItemReference) as ClashTest; foreach (var t in item.Children) { clashResultList.Add(t); } } } OutputPorts[0].Data = clashResultList; } if (input.GetType() == typeof(SavedItemReference)) { ClashTest item = doc.ResolveReference(input as SavedItemReference) as ClashTest; foreach (var t in item.Children) { clashResultList.Add(t); } OutputPorts[0].Data = clashResultList; } }
public static void GroupClashes(ClashTest selectedClashTest, GroupingMode groupingMode, GroupingMode subgroupingMode, bool keepExistingGroups) { //Get existing clash result List <ClashResult> clashResults = GetIndividualClashResults(selectedClashTest, keepExistingGroups).ToList(); List <ClashResultGroup> clashResultGroups = new List <ClashResultGroup>(); //Create groups according to the first grouping mode CreateGroup(ref clashResultGroups, groupingMode, clashResults, ""); //Optionnaly, create subgroups if (subgroupingMode != GroupingMode.None) { CreateSubGroups(ref clashResultGroups, subgroupingMode); } //Remove groups with only one clash List <ClashResult> ungroupedClashResults = RemoveOneClashGroup(ref clashResultGroups); //Backup the existing group, if necessary if (keepExistingGroups) { clashResultGroups.AddRange(BackupExistingClashGroups(selectedClashTest)); } //Process these groups and clashes into the clash test ProcessClashGroup(clashResultGroups, ungroupedClashResults, selectedClashTest); }
private static IEnumerable <ClashResultGroup> BackupExistingClashGroups(ClashTest clashTest) { for (var i = 0; i < clashTest.Children.Count; i++) { if (clashTest.Children[i].IsGroup) { yield return((ClashResultGroup)clashTest.Children[i].CreateCopy()); } } }
private void Group_Button_Click(object sender, WIN.RoutedEventArgs e) { if (ClashTestListBox.SelectedItems.Count != 0) { //Unsubscribe temporarly UnRegisterChanges(); foreach (object selectedItem in ClashTestListBox.SelectedItems) { CustomClashTest selectedClashTest = (CustomClashTest)selectedItem; ClashTest clashTest = selectedClashTest.ClashTest; if (clashTest.Children.Count != 0) { //Some selection check if (comboBoxGroupBy.SelectedItem == null) { comboBoxGroupBy.SelectedItem = GroupingMode.None; } if (comboBoxThenBy.SelectedItem == null) { comboBoxThenBy.SelectedItem = GroupingMode.None; } if ((GroupingMode)comboBoxThenBy.SelectedItem != GroupingMode.None || (GroupingMode)comboBoxGroupBy.SelectedItem != GroupingMode.None) { if ((GroupingMode)comboBoxThenBy.SelectedItem == GroupingMode.None && (GroupingMode)comboBoxGroupBy.SelectedItem != GroupingMode.None) { GroupingMode mode = (GroupingMode)comboBoxGroupBy.SelectedItem; GroupingFunctions.GroupClashes(clashTest, mode, GroupingMode.None, (bool)keepExistingGroupsCheckBox.IsChecked); } else if ((GroupingMode)comboBoxGroupBy.SelectedItem == GroupingMode.None && (GroupingMode)comboBoxThenBy.SelectedItem != GroupingMode.None) { GroupingMode mode = (GroupingMode)comboBoxThenBy.SelectedItem; GroupingFunctions.GroupClashes(clashTest, mode, GroupingMode.None, (bool)keepExistingGroupsCheckBox.IsChecked); } else { GroupingMode byMode = (GroupingMode)comboBoxGroupBy.SelectedItem; GroupingMode thenByMode = (GroupingMode)comboBoxThenBy.SelectedItem; GroupingFunctions.GroupClashes(clashTest, byMode, thenByMode, (bool)keepExistingGroupsCheckBox.IsChecked); } } } } //Resubscribe RegisterChanges(); } }
public static void UnGroupClashes(ClashTest selectedClashTest) { List <ClashResultGroup> groups = new List <ClashResultGroup>(); List <ClashResult> results = GetIndividualClashResults(selectedClashTest, false).ToList(); List <ClashResult> copiedResult = new List <ClashResult>(); foreach (ClashResult result in results) { copiedResult.Add((ClashResult)result.CreateCopy()); } //Process this empty group list and clashes into the clash test ProcessClashGroup(groups, copiedResult, selectedClashTest); }
/// <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 IEnumerable <ClashResult> GetIndividualClashResults(ClashTest clashTest) { for (var i = 0; i < clashTest.Children.Count; i++) { if (clashTest.Children[i].IsGroup) { IEnumerable <ClashResult> GroupResults = GetGroupResults((ClashResultGroup)clashTest.Children[i]); foreach (ClashResult clashResult in GroupResults) { yield return(clashResult); } } else { yield return((ClashResult)clashTest.Children[i]); } } }
public static void GroupClashes(ClashTest selectedClashTest, GroupingMode groupingMode, GroupingMode renamingMode) { //Get existing clash result IEnumerable <ClashResult> clashResults = GetIndividualClashResults(selectedClashTest); List <ClashResultGroup> clashResultGroups = new List <ClashResultGroup>(); //group all clashes switch (groupingMode) { case GroupingMode.None: return; case GroupingMode.ByLevel: clashResultGroups = GroupByLevel(clashResults.ToList()); break; case GroupingMode.ByGridIntersection: clashResultGroups = GroupByGridIntersection(clashResults.ToList()); break; case GroupingMode.BySelectionA: case GroupingMode.BySelectionB: clashResultGroups = GroupByElementOfAGivenSelection(clashResults.ToList(), groupingMode); break; case GroupingMode.ByApprovedBy: case GroupingMode.ByAssignedTo: case GroupingMode.ByStatus: clashResultGroups = GroupByProperties(clashResults.ToList(), groupingMode); break; } //Optionnaly, rename clash groups if (renamingMode != GroupingMode.None) { RemaneGroupBySortingMode(ref clashResultGroups, renamingMode); } //Remove groups with only one clash List <ClashResult> ungroupedClashResults = RemoveOneClashGroup(ref clashResultGroups); //Process these groups and clashes into the clash test ProcessClashGroup(clashResultGroups, ungroupedClashResults, selectedClashTest); }
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(); } }
private void Ungroup_Button_Click(object sender, WIN.RoutedEventArgs e) { if (ClashTestListBox.SelectedItems.Count != 0) { //Unsubscribe temporarly UnRegisterChanges(); foreach (object selectedItem in ClashTestListBox.SelectedItems) { CustomClashTest selectedClashTest = (CustomClashTest)selectedItem; ClashTest clashTest = selectedClashTest.ClashTest; if (clashTest.Children.Count != 0) { GroupingFunctions.UnGroupClashes(clashTest); } } //Resubscribe RegisterChanges(); } }
private void writeClashResult(ClashTest test, ClashResult rt, SqlConnection conn, string grName, string grGuid) { //SqlCommand cmdApproveClash = new SqlCommand("dbo.selectApproved", conn); //cmdApproveClash.CommandType = CommandType.StoredProcedure; //cmdApproveClash.Parameters.Add("@clashGuid", SqlDbType.NVarChar, 50).Value = rt1.Guid.ToString(); //cmdApproveClash.Parameters.Add("@clashStatus", SqlDbType.NVarChar, 50); string rtGuid = rt.Guid.ToString(); string sqlQuery = $"SELECT ClashGuid, ClashStatus, ClashApprovedBy, ClashApprovedTime FROM tblClashResult WHERE ClashGuid={rtGuid}"; SqlCommand myCommand = new SqlCommand(sqlQuery, conn); try { conn.Open(); // Obtain a data reader ExecuteReader(). using (SqlDataReader myDataReader = myCommand.ExecuteReader()) { while (myDataReader.Read()) { if (myDataReader["ClashStatus"].ToString() == "Approved") { string rtApprovedBy = $"{myDataReader["ClashApprovedBy"]}"; oDCT.TestsEditResultStatus(rt, ClashResultStatus.Approved); oDCT.TestsEditResultApprovedBy(rt, rtApprovedBy); } } } } catch (SqlException e) { MessageBox.Show(e.Message.ToString(), "Error Message"); } finally { conn.Close(); } }
private void Group_Button_Click(object sender, WIN.RoutedEventArgs e) { if (ClashTestListBox.SelectedItem != null) { CustomClashTest selectedClashTest = (CustomClashTest)ClashTestListBox.SelectedItem; ClashTest clashTest = selectedClashTest.ClashTest; if (comboBoxGroupBy.SelectedItem != null) { if (comboBoxThenBy.SelectedItem == null) { GroupingMode mode = (GroupingMode)((EnumerationExtension.EnumerationMember)comboBoxGroupBy.SelectedItem).Value; GroupingFunctions.GroupClashes(clashTest, mode, GroupingMode.None); } else { GroupingMode byMode = (GroupingMode)((EnumerationExtension.EnumerationMember)comboBoxGroupBy.SelectedItem).Value; GroupingMode thenByMode = (GroupingMode)((EnumerationExtension.EnumerationMember)comboBoxThenBy.SelectedItem).Value; GroupingFunctions.GroupClashes(clashTest, thenByMode, byMode); } } } }
public CustomClashTest(ClashTest test) { _clashTest = test; }
public override int Execute(params string[] parameters) { //Obtain user Input for Focus Zone (calls UserInput Form) UserInput UIReturn = new UserInput(); UIReturn.ShowDialog(); string fz = UIReturn.Returnfz; Dictionary <string, string> modDiscipline = UIReturn.Returnpd; if (fz == "" || modDiscipline == null) { //MessageBox.Show("Cancelled Operation"); return(0); } Document document = Autodesk.Navisworks.Api.Application.ActiveDocument; DocumentClash documentClash = document.GetClash(); DocumentClashTests allTests = documentClash.TestsData; DocumentModels docModel = document.Models; List <string> discipline = new List <string>(); List <int> objTot = new List <int>(); List <string> tradeAll = new List <string>(); List <string> focusZone = new List <string>(); List <string> testDate = new List <string>(); List <string> fileName = new List <string>(); Dictionary <string, int> objCnt = new Dictionary <string, int>(); foreach (string disValue in modDiscipline.Values) { objCnt.Add(disValue, 0); //Add discipline to list by object tradeAll.Add(disValue); } objCnt.Add("Misc", 0); tradeAll.Add("Misc"); try { string date = ""; if (allTests.Tests.Count != 0) { //Record last date of clash test run ClashTest test = allTests.Tests[0] as ClashTest; if (test.LastRun == null) { date = "No Test Runs"; } else { date = test.LastRun.Value.ToShortDateString(); } } else { date = "No Test Runs"; } //Record file name string file = document.CurrentFileName.ToString(); if (file == "") { file = "File not yet saved."; } if (docModel.Count != 0) { //Count total objects in project foreach (Model model in docModel) { ModelItem root = model.RootItem as ModelItem; foreach (ModelItem item in root.Children) { List <ModelItem> dList = item.DescendantsAndSelf.ToList(); foreach (ModelItem subItem in dList) { if (subItem.IsComposite == true || subItem.ClassDisplayName == "Block") { List <ModelItem> aList = subItem.Ancestors.ToList(); string tradeName = Discipline_Search(aList, modDiscipline); if (objCnt.ContainsKey(tradeName)) { objCnt[tradeName] += 1; } else { objCnt["Misc"] += 1; } } else if (subItem.IsLayer == true) { foreach (ModelItem obj in subItem.Children) { if (obj.IsInsert == false && obj.IsComposite == false && obj.IsCollection == false && obj.ClassDisplayName != "Block") { List <ModelItem> aList = subItem.Ancestors.ToList(); string tradeName = Discipline_Search(aList, modDiscipline); if (objCnt.ContainsKey(tradeName)) { objCnt[tradeName] += 1; } else { objCnt["Misc"] += 1; } } } } } } } } else { MessageBox.Show("No models currently appended in project." + "\n" + "Load models first."); return(0); } //Create Discipline list from each clash by discipline involvement foreach (string name in tradeAll) { if (!discipline.Contains(name)) { discipline.Add(name); } } //Record user inputted focus zone to total rows int fzIdx = 0; while (fzIdx < discipline.Count) { focusZone.Add(fz); fzIdx++; } //Record last Test run date to match #rows int idxDate = 0; while (idxDate < discipline.Count) { testDate.Add(date); idxDate++; } //Record file name to match # of rows int idxFile = 0; while (idxFile < discipline.Count) { fileName.Add(file); idxFile++; } //Add total trade object counts to objTot List in order of discipline List foreach (string name in discipline) { if (objCnt.ContainsKey(name)) { objTot.Add(objCnt[name]); } } //Launch or access Excel via COM Interop: Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook; if (xlApp == null) { MessageBox.Show("Excel is not properly installed!"); } //Create New Workbook & Worksheets xlWorkbook = xlApp.Workbooks.Add(Missing.Value); Excel.Worksheet xlWorksheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1); xlWorksheet.Name = "Total Objects by Trade"; //Label Column Headers - Total Objects Worksheet xlWorksheet.Cells[1, 1] = "Date"; xlWorksheet.Cells[1, 2] = "Discipline"; xlWorksheet.Cells[1, 3] = "Total Objects"; xlWorksheet.Cells[1, 4] = "Focus Zone"; xlWorksheet.Cells[1, 5] = "File"; int counterDate = 2; foreach (string day in testDate) { string cellName = "A" + counterDate.ToString(); var range = xlWorksheet.get_Range(cellName, cellName); range.Value2 = day; counterDate++; } int counterDis = 2; foreach (string valueDis in discipline) { string cellName = "B" + counterDis.ToString(); var range = xlWorksheet.get_Range(cellName, cellName); range.Value2 = valueDis; counterDis++; } int counterObj = 2; foreach (int valueObj in objTot) { string cellName = "C" + counterObj.ToString(); var range = xlWorksheet.get_Range(cellName, cellName); range.Value2 = valueObj; counterObj++; } int counterFz = 2; foreach (string valueFz in focusZone) { string cellName = "D" + counterFz.ToString(); var range = xlWorksheet.get_Range(cellName, cellName); range.Value2 = valueFz; counterFz++; } int fileNameCount = 2; foreach (string fName in fileName) { string cellName = "E" + fileNameCount.ToString(); var range = xlWorksheet.get_Range(cellName, cellName); range.Value2 = fName; fileNameCount++; } //Locate Excel file save location string modDate = ""; if (allTests.Tests.Count != 0) { string[] clashDate = testDate[0].Split('/'); if (clashDate[0].Length == 1) { clashDate[0] = "0" + clashDate[0]; } if (clashDate[1].Length == 1) { clashDate[1] = "0" + clashDate[1]; } modDate = clashDate[2] + clashDate[0] + clashDate[1]; } else { modDate = "YYYYMMDD"; } SaveFileDialog saveClashData = new SaveFileDialog(); saveClashData.Title = "Save to..."; saveClashData.Filter = "Excel Workbook | *.xlsx|Excel 97-2003 Workbook | *.xls"; saveClashData.FileName = modDate + "-Total_Objects_Data-" + focusZone[0].ToString(); if (saveClashData.ShowDialog() == DialogResult.OK) { string path = saveClashData.FileName; xlWorkbook.SaveCopyAs(path); xlWorkbook.Saved = true; xlWorkbook.Close(true, Missing.Value, Missing.Value); xlApp.Quit(); } xlApp.Visible = false; } catch (Exception exception) { MessageBox.Show("Error! Original Message: " + exception.Message); } return(0); }
private void writeClashResult(ClashTest test, ClashResult rt, StreamWriter sw, SqlConnection conn, string gName, string gGuid, string gStatus) { //if (rt.Status.ToString() == "Approved") //{ sw.WriteLine("Clash Test: " + test.DisplayName); sw.WriteLine(" clash Name: " + rt.DisplayName); sw.WriteLine(" clash Guid: " + rt.Guid.ToString()); SqlCommand cmdClashData = new SqlCommand("dbo.Procedure", conn); cmdClashData.CommandType = CommandType.StoredProcedure; cmdClashData.Parameters.Add("@testName", SqlDbType.NVarChar, 100).Value = test.DisplayName; cmdClashData.Parameters.Add("@testGuid", SqlDbType.NVarChar, 50).Value = test.Guid.ToString(); if (test.LastRun != null) { cmdClashData.Parameters.Add("@testLastRunDate", SqlDbType.Date).Value = test.LastRun.Value.ToShortDateString(); cmdClashData.Parameters.Add("@testLastRunTime", SqlDbType.Time).Value = test.LastRun.Value.ToShortTimeString(); } cmdClashData.Parameters.Add("@testStatus", SqlDbType.NVarChar, 50).Value = test.Status.ToString(); cmdClashData.Parameters.Add("@testType", SqlDbType.NVarChar, 50).Value = test.TestType.ToString(); cmdClashData.Parameters.Add("@testTolerance", SqlDbType.Float, 53).Value = test.Tolerance; cmdClashData.Parameters.Add("@groupName", SqlDbType.NVarChar, 50).Value = gName; cmdClashData.Parameters.Add("@groupGuid", SqlDbType.NVarChar, 50).Value = gGuid; cmdClashData.Parameters.Add("@groupStatus", SqlDbType.NVarChar, 50).Value = gStatus; cmdClashData.Parameters.Add("@clashName", SqlDbType.NVarChar, 50).Value = rt.DisplayName; cmdClashData.Parameters.Add("@clashGuid", SqlDbType.NVarChar, 50).Value = rt.Guid.ToString(); if (rt.CreatedTime != null) { sw.WriteLine(" Created Time: " + rt.CreatedTime.ToString()); cmdClashData.Parameters.Add("@clashTime", SqlDbType.SmallDateTime).Value = rt.CreatedTime.Value.ToShortDateString(); } cmdClashData.Parameters.Add("@clashStatus", SqlDbType.NVarChar, 50).Value = rt.Status.ToString(); cmdClashData.Parameters.Add("@clashApprovedBy", SqlDbType.NVarChar, 50).Value = rt.ApprovedBy; cmdClashData.Parameters.Add("@clashApprovedTime", SqlDbType.SmallDateTime).Value = rt.ApprovedTime.Value.ToShortDateString(); cmdClashData.Parameters.Add("@clashX", SqlDbType.Float, 53).Value = rt.Center.X; cmdClashData.Parameters.Add("@clashY", SqlDbType.Float, 53).Value = rt.Center.Y; cmdClashData.Parameters.Add("@clashZ", SqlDbType.Float, 53).Value = rt.Center.Z; try { conn.Open(); cmdClashData.ExecuteNonQuery(); } catch (SqlException e) { MessageBox.Show(e.Message.ToString(), "Error Message"); } finally { conn.Close(); } sw.WriteLine(" Status: " + rt.Status.ToString()); sw.WriteLine(" Approved By: " + rt.ApprovedBy); sw.WriteLine(" Approved Date: " + rt.ApprovedTime.ToString()); //if (rt.Center != null) // sw.WriteLine(" Centre[{0}, {1}, {2}]: ", rt.Center.X, rt.Center.Y, rt.Center.Z); //sw.WriteLine(" Simulation Type: " + rt.SimulationType.ToString()); //} }
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); }