Beispiel #1
0
        public List <object> RenameClashes(object Guids, object Names)
        {
            //Get clashes from document
            Document      doc            = Application.ActiveDocument;
            DocumentClash documentClash  = doc.GetClash();
            var           output         = new List <object>();
            var           TemplistOfTest = new List <ClashTest>();

            if (MainTools.IsList(Guids) && MainTools.IsList(Names))
            {
                var guidlist  = (List <object>)Guids;
                var namesList = (List <object>)Names;

                if (guidlist.Count == namesList.Count)
                {
                    for (int i = 0; i < guidlist.Count; i++)
                    {
                        Guid guid           = new Guid(guidlist[i].ToString().Replace("\"", ""));
                        var  clashReference = documentClash.TestsData.ResolveGuid(guid);
                        var  name           = namesList[i].ToString();
                        documentClash.TestsData.TestsEditDisplayName(clashReference, name);;
                        output.Add(clashReference);
                    }
                }
                else
                {
                    output.Add("Error, be sure you have same amount of guids and names");
                }
            }
            return(output);
        }
        public void FilesCheck(string PathCheck)
        {
            //Tools for work with files creation
            DS_DirTools dS_DirTools = new DS_DirTools();

            bool fe = dS_DirTools.DirCheckForFiles(PathCheck, out string[] FilesList, "nwf");

            if (fe == false)
            {
                return;
            }

            //Through each file iterating
            foreach (string f in FilesList)
            {
                //Open Navisworks document
                Navisworks_Tools   navisworks_Tools = new Navisworks_Tools(f);
                Document           oDoc             = navisworks_Tools.OpenDoc();
                DocumentClash      documentClash    = oDoc.GetClash();
                DocumentClashTests oDCT             = documentClash.TestsData;

                if (oDCT.Tests.Count != 0)
                {
                    oDCT.TestsRunAllTests();

                    //Through each clash test iterating
                    Clash_Viewpoints clash_Viewpoints = new Clash_Viewpoints(oDoc);

                    clash_Viewpoints.CheckHomeView();

                    clash_Viewpoints.ClashElementSearch();
                    clash_Viewpoints.ViewpointsCreation(out bool ClashTestsResultsExist);

                    if (ClashTestsResultsExist == false)
                    {
                        FilesWithNoClashRes.Add(f);
                    }
                    else
                    {
                        //Set current view
                        DS_NW_Viewpoint_tools dS_NW_Viewpoint_Tools = new DS_NW_Viewpoint_tools();
                        dS_NW_Viewpoint_Tools.HomeViewpoint_Set(out _);

                        navisworks_Tools.FilesSave();

                        SavedFiles.Add(f);
                    }
                }
                else
                {
                    FilesWithNoClashTests.Add(f);
                }
            }
        }
        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();
            }
        }
Beispiel #4
0
        public void process(object Guids, object Names)
        {
            //Get clashes from document
            Document      doc           = Application.ActiveDocument;
            DocumentClash documentClash = doc.GetClash();

            var TemplistOfTest = new List <ClashTest>();

            if (MainTools.IsList(Guids) && MainTools.IsList(Names))
            {
                var guidlist  = (List <object>)Guids;
                var namesList = (List <object>)Names;

                if (guidlist.Count == namesList.Count)
                {
                    for (int i = 0; i < guidlist.Count; i++)
                    {
                        Guid guid           = new Guid(guidlist[i].ToString());
                        var  clashReference = documentClash.TestsData.ResolveGuid(guid);
                        documentClash.TestsData.TestsEditDisplayName(clashReference, namesList[i].ToString());
                    }
                }
            }
        }
        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> trade = UIReturn.Returnpd;

            if (fz == "" || trade == null)
            {
                //MessageBox.Show("Cancelled Operation");
                return(0);
            }

            //Initialize Objects
            List <string> testName       = new List <string>();
            List <int>    resultNew      = new List <int>();
            List <int>    resultActive   = new List <int>();
            List <int>    resultReviewed = new List <int>();
            List <int>    resultApproved = new List <int>();
            List <int>    resultResolved = new List <int>();
            List <string> testDate       = new List <string>();
            List <string> fileName       = new List <string>();
            List <string> sumTestDate    = new List <string>();

            List <string> tradeStatus      = new List <string>();
            List <string> tradeClash       = new List <string>();
            List <string> tradeDiscipline1 = new List <string>();
            List <string> tradeDiscipline2 = new List <string>();
            List <string> tradeDate        = new List <string>();
            List <string> tradeFile        = new List <string>();
            List <string> tradeAll         = new List <string>();
            List <string> clashAssignTo    = new List <string>();
            List <string> clashApprovedBy  = new List <string>();
            List <string> clashApproveTime = new List <string>();
            List <string> clashDescription = new List <string>();
            List <string> discipline       = new List <string>();
            List <string> indiTest         = new List <string>();
            List <double> indiCoordX       = new List <double>();
            List <double> indiCoordY       = new List <double>();
            List <double> indiCoordZ       = new List <double>();
            List <string> focusZone        = new List <string>();
            List <string> level            = new List <string>();
            List <double> lvlElev          = new List <double>();
            List <string> clashLevel       = new List <string>();
            List <double> gridXMinCoord    = new List <double>();
            List <double> gridXMaxCoord    = new List <double>();
            List <double> gridYMinCoord    = new List <double>();
            List <double> gridYMaxCoord    = new List <double>();

            string tradeName1 = "";
            string tradeName2 = "";

            int countNew      = 0;
            int countActive   = 0;
            int countReviewed = 0;
            int countApproved = 0;
            int countResolved = 0;

            try
            {
                Document           document      = Autodesk.Navisworks.Api.Application.ActiveDocument;
                DocumentClash      documentClash = document.GetClash();
                DocumentClashTests allTests      = documentClash.TestsData;
                DocumentModels     docModel      = document.Models;

                DocumentGrids docGrids   = document.Grids;
                GridSystem    docGridSys = docGrids.ActiveSystem;

                foreach (GridLevel lvl in docGridSys.Levels)
                {
                    level.Add(lvl.DisplayName);
                    lvlElev.Add(lvl.Elevation);
                }

                //-----------------------------------------------------------------------------------------//
                //Check if Clash Test have even been created
                //If no clash tests created, exit program
                int check = allTests.Tests.Count;
                if (check == 0)
                {
                    MessageBox.Show("No clash tests currently exist!");
                    return(0);
                }
                //-----------------------------------------------------------------------------------------//

                //-----------------------------------------------------------------------------------------//
                //Begin storing clash data by created tests
                foreach (ClashTest test in allTests.Tests)
                {
                    testName.Add(test.DisplayName);

                    //Reset Clash Status counts per test in Clash Detective Summary.  Matches Results tab in Clash Detective (ungrouped clashes)
                    countNew      = 0;
                    countActive   = 0;
                    countReviewed = 0;
                    countApproved = 0;
                    countResolved = 0;

                    if (test.LastRun == null)
                    {
                        sumTestDate.Add("No Test Runs");
                    }
                    else
                    {
                        sumTestDate.Add(test.LastRun.Value.ToShortDateString());
                    }

                    //Count number of instances per Clash Status
                    //(based on how user grouped clashes)
                    foreach (SavedItem issue in test.Children)
                    {
                        ClashResultGroup group = issue as ClashResultGroup;

                        //Check if clash groups exist.  If null, clash result is not grouped
                        if (null != group)
                        {
                            foreach (SavedItem subissue in group.Children)
                            {
                                ClashResult item = subissue as ClashResult;

                                //Checking if Item1 is null (due to resolved) and need to use Selection-A
                                if (item.Item1 != null)
                                {
                                    List <ModelItem> lItem1 = item.Item1.Ancestors.ToList();

                                    tradeName1 = ClashDiscipline_Search(lItem1, trade);
                                }
                                else
                                {
                                    ModelItemCollection oSelA  = test.SelectionA.Selection.GetSelectedItems();
                                    List <ModelItem>    lItemA = new List <ModelItem>();

                                    if (oSelA.First.HasModel == true)
                                    {
                                        lItemA.Add(oSelA.First);
                                    }
                                    else
                                    {
                                        lItemA = oSelA.First.Ancestors.ToList();
                                    }

                                    tradeName1 = ClashDiscipline_Search(lItemA, trade);
                                }

                                //Checking if Item2 is null (due to resolved) and need to use Selection-B
                                if (item.Item2 != null)
                                {
                                    List <ModelItem> lItem2 = item.Item2.Ancestors.ToList();

                                    tradeName2 = ClashDiscipline_Search(lItem2, trade);
                                }
                                else
                                {
                                    ModelItemCollection oSelB  = test.SelectionB.Selection.GetSelectedItems();
                                    List <ModelItem>    lItemB = new List <ModelItem>();
                                    //MessageBox.Show(oSelB.First.DisplayName);

                                    if (oSelB.First.HasModel == true)
                                    {
                                        lItemB.Add(oSelB.First);
                                    }
                                    else
                                    {
                                        lItemB = oSelB.First.Ancestors.ToList();
                                    }

                                    tradeName2 = ClashDiscipline_Search(lItemB, trade);
                                }

                                //Prompt User when no Discipline match found
                                //User may be missing a discipline/trade in initial input
                                if (tradeName1 == "" || tradeName2 == "")
                                {
                                    MessageBox.Show("Discipline Missing.  Check Project Disciplines Input File (.txt)." + "\n"
                                                    + "Clash Test: " + test.DisplayName + "\n"
                                                    + "Clash Name: " + item.DisplayName + "\n"
                                                    + "Discipline 1: " + tradeName1 + "\n"
                                                    + "Discipline 2: " + tradeName2);

                                    return(0);
                                }

                                //Store Individual Clash Data
                                testDate.Add(test.LastRun.Value.ToShortDateString());
                                indiTest.Add(test.DisplayName);
                                focusZone.Add(fz);
                                tradeDiscipline1.Add(tradeName1);
                                tradeDiscipline2.Add(tradeName2);
                                tradeClash.Add(item.DisplayName.ToString());
                                tradeStatus.Add(item.Status.ToString());
                                indiCoordX.Add(item.Center.X);
                                indiCoordY.Add(item.Center.Y);
                                indiCoordZ.Add(item.Center.Z);
                                fileName.Add(document.CurrentFileName.ToString());
                                clashAssignTo.Add(item.AssignedTo);
                                clashApprovedBy.Add(item.ApprovedBy);
                                clashApproveTime.Add(item.ApprovedTime.ToString());
                                clashDescription.Add(item.Description);

                                if (test.LastRun == null)
                                {
                                    testDate.Add("Test Not Run");
                                }
                                else
                                {
                                    tradeDate.Add(test.LastRun.Value.ToShortDateString());
                                }

                                tradeFile.Add(document.CurrentFileName.ToString());

                                //for Clash Summary
                                if (null != item && item.Status.ToString() == "New")
                                {
                                    countNew = countNew + 1;
                                }
                                else if (null != item && item.Status.ToString() == "Active")
                                {
                                    countActive = countActive + 1;
                                }
                                else if (null != item && item.Status.ToString() == "Reviewed")
                                {
                                    countReviewed = countReviewed + 1;
                                }
                                else if (null != item && item.Status.ToString() == "Approved")
                                {
                                    countApproved = countApproved + 1;
                                }
                                else
                                {
                                    countResolved = countResolved + 1;
                                }
                            }
                        }
                        else
                        {
                            ClashResult rawItem = issue as ClashResult;

                            //Checking if Item1 is null (due to resolved) and need to use Selection-A
                            if (rawItem.Item1 != null)
                            {
                                List <ModelItem> lItem1 = rawItem.Item1.Ancestors.ToList();

                                tradeName1 = ClashDiscipline_Search(lItem1, trade);
                            }
                            else
                            {
                                ModelItemCollection oSelA  = test.SelectionA.Selection.GetSelectedItems();
                                List <ModelItem>    lItemA = new List <ModelItem>();

                                if (oSelA.First.HasModel == true)
                                {
                                    lItemA.Add(oSelA.First);
                                }
                                else
                                {
                                    lItemA = oSelA.First.Ancestors.ToList();
                                }

                                tradeName1 = ClashDiscipline_Search(lItemA, trade);
                            }

                            //Checking if Item1 is null (due to resolved) and need to use Selection-B
                            if (rawItem.Item2 != null)
                            {
                                List <ModelItem> lItem2 = rawItem.Item2.Ancestors.ToList();

                                tradeName2 = ClashDiscipline_Search(lItem2, trade);
                            }
                            else
                            {
                                ModelItemCollection oSelB  = test.SelectionB.Selection.GetSelectedItems();
                                List <ModelItem>    lItemB = new List <ModelItem>();

                                if (oSelB.First.HasModel == true)
                                {
                                    lItemB.Add(oSelB.First);
                                }
                                else
                                {
                                    lItemB = oSelB.First.Ancestors.ToList();
                                }

                                tradeName2 = ClashDiscipline_Search(lItemB, trade);
                            }

                            if (tradeName1 == "" || tradeName2 == "")
                            {
                                MessageBox.Show("Discipline Missing.  Check Project Disciplines Input File (.txt)." + "\n"
                                                + "Clash Test: " + test.DisplayName + "\n"
                                                + "Clash Name: " + rawItem.DisplayName + "\n"
                                                + "Discipline 1: " + tradeName1 + "\n"
                                                + "Discipline 2: " + tradeName2);

                                return(0);
                            }

                            //write to second sheet by discipline involvement
                            testDate.Add(test.LastRun.Value.ToShortDateString());
                            indiTest.Add(test.DisplayName);
                            focusZone.Add(fz);
                            tradeDiscipline1.Add(tradeName1);
                            tradeDiscipline2.Add(tradeName2);
                            tradeClash.Add(rawItem.DisplayName.ToString());
                            tradeStatus.Add(rawItem.Status.ToString());
                            tradeFile.Add(document.CurrentFileName.ToString());
                            indiCoordX.Add(rawItem.Center.X);
                            indiCoordY.Add(rawItem.Center.Y);
                            indiCoordZ.Add(rawItem.Center.Z);
                            fileName.Add(document.CurrentFileName.ToString());
                            clashAssignTo.Add(rawItem.AssignedTo);
                            clashApprovedBy.Add(rawItem.ApprovedBy);
                            clashApproveTime.Add(rawItem.ApprovedTime.ToString());
                            clashDescription.Add(rawItem.Description);

                            if (test.LastRun == null)
                            {
                                testDate.Add("Test Not Run");
                            }
                            else
                            {
                                tradeDate.Add(test.LastRun.Value.ToShortDateString());
                            }

                            if (rawItem.Status.ToString() == "New")
                            {
                                countNew = countNew + 1;
                            }
                            else if (rawItem.Status.ToString() == "Active")
                            {
                                countActive = countActive + 1;
                            }
                            else if (rawItem.Status.ToString() == "Reviewed")
                            {
                                countReviewed = countReviewed + 1;
                            }
                            else if (rawItem.Status.ToString() == "Approved")
                            {
                                countApproved = countApproved + 1;
                            }
                            else
                            {
                                countResolved = countResolved + 1;
                            }
                        }
                    }

                    //inputs values into Clash Status List by Test
                    resultNew.Add(countNew);
                    resultActive.Add(countActive);
                    resultReviewed.Add(countReviewed);
                    resultApproved.Add(countApproved);
                    resultResolved.Add(countResolved);
                }

                //-----------------------------------------------------------------------------------------//
                //call grid intersection function to return min and max grid coordinate values
                GridIntersectCoord gridValueReturn = new GridIntersectCoord();

                var gridCoordValues = gridValueReturn.GridCoord();

                double gridXMin = gridCoordValues.gridXMin;
                double gridXMax = gridCoordValues.gridXMax;
                double gridYMin = gridCoordValues.gridYMin;
                double gridYMax = gridCoordValues.gridYMax;

                foreach (string clash in tradeClash)
                {
                    gridXMinCoord.Add(gridXMin);
                    gridXMaxCoord.Add(gridXMax);
                    gridYMinCoord.Add(gridYMin);
                    gridYMaxCoord.Add(gridYMax);
                }
                //-----------------------------------------------------------------------------------------//

                //-----------------------------------------------------------------------------------------//
                //Record level clashes occur for Clash Level
                int clashIdx = 0; int cnt1 = 0;

                while (clashIdx < indiCoordZ.Count)
                {
                    int  lvlIdx    = 0;
                    bool lvlAssign = false;

                    while (lvlIdx < level.Count && lvlAssign == false)
                    {
                        if (indiCoordZ[clashIdx] >= lvlElev[lvlIdx] && indiCoordZ[clashIdx] < lvlElev[lvlIdx + 1])
                        {
                            clashLevel.Add(level[lvlIdx]);
                            lvlAssign = true;
                            cnt1++;
                        }
                        else if (lvlIdx == level.Count - 1 && indiCoordZ[clashIdx] >= lvlElev[lvlIdx])
                        {
                            clashLevel.Add(level[lvlIdx]);
                            lvlAssign = true;
                            cnt1++;
                        }
                        else if (lvlIdx == 0 && indiCoordZ[clashIdx] < lvlElev[lvlIdx])
                        {
                            clashLevel.Add("UNDERGROUND");
                            lvlAssign = true;
                            cnt1++;
                        }
                        lvlIdx++;
                    }
                    clashIdx++;
                }
                //-----------------------------------------------------------------------------------------//

                //-----------------------------------------------------------------------------------------//
                //Totals current Open(New + Active), Closed(Resolved + Approved), Field Coordinate(Reviewed)
                int totOpen     = resultNew.Aggregate((a, b) => a + b) + resultActive.Aggregate((a, b) => a + b);
                int totClosed   = resultResolved.Aggregate((a, b) => a + b) + resultApproved.Aggregate((a, b) => a + b);
                int totReviewed = resultReviewed.Aggregate((a, b) => a + b);
                int totNew      = resultNew.Aggregate((a, b) => a + b);
                int totActive   = resultActive.Aggregate((a, b) => a + b);
                int totApproved = resultApproved.Aggregate((a, b) => a + b);
                int totResolved = resultResolved.Aggregate((a, b) => a + b);
                //-----------------------------------------------------------------------------------------//

                //-----------------------------------------------------------------------------------------//
                //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);
                Excel.Worksheet xlWorksheet_trade = (Excel.Worksheet)xlWorkbook.Worksheets.Add();
                xlWorksheet.Name       = "Clash Detective Summary";
                xlWorksheet_trade.Name = "Individual Clashes";

                //Label Column Headers - Summary Worksheet
                xlWorksheet.Cells[1, 1]  = "Test Date";
                xlWorksheet.Cells[1, 2]  = "Test Name";
                xlWorksheet.Cells[1, 3]  = "New";
                xlWorksheet.Cells[1, 4]  = "Active";
                xlWorksheet.Cells[1, 5]  = "Reviewed";
                xlWorksheet.Cells[1, 6]  = "Approved";
                xlWorksheet.Cells[1, 7]  = "Resolved";
                xlWorksheet.Cells[1, 9]  = "Total New";
                xlWorksheet.Cells[1, 10] = "Total Active";
                xlWorksheet.Cells[1, 11] = "Total Reviewed";
                xlWorksheet.Cells[1, 12] = "Total Approved";
                xlWorksheet.Cells[1, 13] = "Total Resolved";
                xlWorksheet.Cells[1, 15] = "Total Open (New + Active)";
                xlWorksheet.Cells[1, 16] = "Total Closed (Approved + Resolved)";
                xlWorksheet.Cells[1, 17] = "Total Deferred to Field Coordination (Reviewed)";

                //Label Column Headers - Worksheet By Trade Involvement
                xlWorksheet_trade.Cells[1, 1]        = "Date";
                xlWorksheet_trade.Cells[1, 2]        = "Focus Zone";
                xlWorksheet_trade.Cells[1, 3]        = "Test Name";
                xlWorksheet_trade.Cells[1, 4]        = "Discipline 1";
                xlWorksheet_trade.Cells[1, 5]        = "Discipline 2";
                xlWorksheet_trade.Cells[1, 6]        = "Clash";
                xlWorksheet_trade.Cells[1, 7]        = "Clash Level";
                xlWorksheet_trade.Cells[1, 8]        = "Status";
                xlWorksheet_trade.Cells.Cells[1, 9]  = "Clash Location (X)";
                xlWorksheet_trade.Cells.Cells[1, 10] = "Clash Location (Y)";
                xlWorksheet_trade.Cells.Cells[1, 11] = "Clash Location (Z)";
                xlWorksheet_trade.Cells.Cells[1, 12] = "Min X Grid Coordinate";
                xlWorksheet_trade.Cells.Cells[1, 13] = "Min Y Grid Coordinate";
                xlWorksheet_trade.Cells.Cells[1, 14] = "Max X Grid Coordinate";
                xlWorksheet_trade.Cells.Cells[1, 15] = "Max Y Grid Coordinate";
                xlWorksheet_trade.Cells.Cells[1, 16] = "File Path";
                xlWorksheet_trade.Cells.Cells[1, 17] = "Assigned To";
                xlWorksheet_trade.Cells.Cells[1, 18] = "Approved By";
                xlWorksheet_trade.Cells.Cells[1, 19] = "Approved Time";
                xlWorksheet_trade.Cells.Cells[1, 20] = "Description";


                //write clash statuses to excel file by Test
                int counterSumDate = 2;
                foreach (string name in sumTestDate)
                {
                    string cellName = "A" + counterSumDate.ToString();
                    var    range    = xlWorksheet.get_Range(cellName, cellName);
                    range.Value2 = name;
                    counterSumDate++;
                }

                int counterTest = 2;
                foreach (string name in testName)
                {
                    string cellName = "B" + counterTest.ToString();
                    var    range    = xlWorksheet.get_Range(cellName, cellName);
                    range.Value2 = name;
                    counterTest++;
                }

                int counterNew = 2;
                foreach (int valueNew in resultNew)
                {
                    string cellName = "C" + counterNew.ToString();
                    var    range    = xlWorksheet.get_Range(cellName, cellName);
                    range.Value2 = valueNew;
                    counterNew++;
                }

                int counterActive = 2;
                foreach (int valueActive in resultActive)
                {
                    string cellName = "D" + counterActive.ToString();
                    var    range    = xlWorksheet.get_Range(cellName, cellName);
                    range.Value2 = valueActive;
                    counterActive++;
                }

                int counterReviewed = 2;
                foreach (int valueReviewed in resultReviewed)
                {
                    string cellName = "E" + counterReviewed.ToString();
                    var    range    = xlWorksheet.get_Range(cellName, cellName);
                    range.Value2 = valueReviewed;
                    counterReviewed++;
                }

                int counterApproved = 2;
                foreach (int valueApproved in resultApproved)
                {
                    string cellName = "F" + counterApproved.ToString();
                    var    range    = xlWorksheet.get_Range(cellName, cellName);
                    range.Value2 = valueApproved;
                    counterApproved++;
                }

                int counterResolved = 2;
                foreach (int valueResolved in resultResolved)
                {
                    string cellName = "G" + counterResolved.ToString();
                    var    range    = xlWorksheet.get_Range(cellName, cellName);
                    range.Value2 = valueResolved;
                    counterResolved++;
                }

                //write totals Open, Closed, Field Coordinate to Cells
                xlWorksheet.Cells[2, 9]  = totNew;
                xlWorksheet.Cells[2, 10] = totActive;
                xlWorksheet.Cells[2, 11] = totReviewed;
                xlWorksheet.Cells[2, 12] = totApproved;
                xlWorksheet.Cells[2, 13] = totResolved;
                xlWorksheet.Cells[2, 15] = totOpen;
                xlWorksheet.Cells[2, 16] = totClosed;
                xlWorksheet.Cells[2, 17] = totReviewed;

                //Complete Data on Worksheet (per Discipline Clash Involvement)
                int tradeDateCount = 2;
                foreach (string date in tradeDate)
                {
                    string cellName = "A" + tradeDateCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = date;
                    tradeDateCount++;
                }

                int counterFz = 2;
                foreach (string valueFz in focusZone)
                {
                    string cellName = "B" + counterFz.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = valueFz;
                    counterFz++;
                }

                int testNameCount = 2;
                foreach (string tn in indiTest)
                {
                    string cellName = "C" + testNameCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = tn;
                    testNameCount++;
                }

                int dis1Count = 2;
                foreach (string dis1 in tradeDiscipline1)
                {
                    string cellName = "D" + dis1Count.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = dis1;
                    dis1Count++;
                }

                int dis2Count = 2;
                foreach (string dis2 in tradeDiscipline2)
                {
                    string cellName = "E" + dis2Count.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = dis2;
                    dis2Count++;
                }

                int tradeClashCount = 2;
                foreach (string clash in tradeClash)
                {
                    string cellName = "F" + tradeClashCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = clash;
                    tradeClashCount++;
                }

                int levelCount = 2;
                foreach (string lvl in clashLevel)
                {
                    string cellName = "G" + levelCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = lvl;
                    levelCount++;
                }

                int tradeStatusCount = 2;
                foreach (string status in tradeStatus)
                {
                    string cellName = "H" + tradeStatusCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = status;
                    tradeStatusCount++;
                }

                int coordXCount = 2;
                foreach (double x in indiCoordX)
                {
                    string cellName = "I" + coordXCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = x;
                    coordXCount++;
                }

                int coordYCount = 2;
                foreach (double y in indiCoordY)
                {
                    string cellName = "J" + coordYCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = y;
                    coordYCount++;
                }

                int coordZCount = 2;
                foreach (double z in indiCoordZ)
                {
                    string cellName = "K" + coordZCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = z;
                    coordZCount++;
                }

                int xMinCount = 2;
                foreach (double xMin in gridXMinCoord)
                {
                    string cellName = "L" + xMinCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = xMin;
                    xMinCount++;
                }

                int yMinCount = 2;
                foreach (double yMin in gridYMinCoord)
                {
                    string cellName = "M" + yMinCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = yMin;
                    yMinCount++;
                }

                int xMaxCount = 2;
                foreach (double xMax in gridXMaxCoord)
                {
                    string cellName = "N" + xMaxCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = xMax;
                    xMaxCount++;
                }

                int yMaxCount = 2;
                foreach (double yMax in gridYMaxCoord)
                {
                    string cellName = "O" + yMaxCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = yMax;
                    yMaxCount++;
                }

                int tradeFileCount = 2;
                foreach (string file in tradeFile)
                {
                    string cellName = "P" + tradeFileCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = file;
                    tradeFileCount++;
                }

                int assignToCount = 2;
                foreach (string assign in clashAssignTo)
                {
                    string cellName = "Q" + assignToCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = assign;
                    assignToCount++;
                }

                int approvedByCount = 2;
                foreach (string approve in clashApprovedBy)
                {
                    string cellName = "R" + approvedByCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = approve;
                    approvedByCount++;
                }

                int approveTimeCount = 2;
                foreach (string time in clashApproveTime)
                {
                    string cellName = "S" + approveTimeCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = time;
                    approveTimeCount++;
                }

                int descriptionCount = 2;
                foreach (string description in clashDescription)
                {
                    string cellName = "T" + descriptionCount.ToString();
                    var    range    = xlWorksheet_trade.get_Range(cellName, cellName);
                    range.Value2 = description;
                    descriptionCount++;
                }

                //Locate file save location
                string[] clashDate = tradeDate[0].Split('/');
                string   modDate   = "";

                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];


                SaveFileDialog saveClashData = new SaveFileDialog();

                saveClashData.Title    = "Save to...";
                saveClashData.Filter   = "Excel Workbook | *.xlsx|Excel 97-2003 Workbook | *.xls";
                saveClashData.FileName = modDate + "-Clash_Test_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! Check if clash test(s) exist or previously run.  Original Message: " + exception.Message);
            }

            return(0);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        public override int Execute(params string[] parameters)
        {
            //MessageBox.Show("Hello World", "Execute", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //return 0;

            string grName   = "";
            string grGuid   = "";
            string grStatus = "";

            string connstring = Properties.Settings.Default.ConnectionString;

            SqlConnection conn = new SqlConnection(connstring);

            //string delstring = "TRUNCATE TABLE tblClashResult";
            //SqlCommand cmdDelete = new SqlCommand(delstring, conn);
            //cmdDelete.CommandType = CommandType.Text;

            //try
            //{
            //    conn.Open();
            //    cmdDelete.ExecuteNonQuery();
            //    MessageBox.Show("All Data deleted");

            //}
            //catch (SqlException e)
            //{
            //    MessageBox.Show(e.Message.ToString(), "Error Message");
            //}
            //finally
            //{
            //    conn.Close();
            //}


            MessageBox.Show("will dump clash to c:\\sqlite\\dumpClash.txt");
            StreamWriter sw       = File.CreateText("c:\\sqlite\\dumpClash.txt");
            Document     document = Autodesk.Navisworks.Api.Application.ActiveDocument;

            DocumentClash      documentClash = document.GetClash();
            DocumentClashTests oDCT          = documentClash.TestsData;

            foreach (ClashTest test in oDCT.Tests)
            {
                sw.WriteLine("Connection String:" + connstring);
                sw.WriteLine("***Test: " + test.DisplayName + "***");
                //sw.WriteLine(" Status: " + test.Status.ToString());
                //sw.WriteLine(" Test Type: " + test.TestType.ToString());
                if (test.LastRun != null)
                {
                    sw.WriteLine(" Last Run: " + test.LastRun.Value.ToShortDateString());
                }
                //sw.WriteLine(" tolerance: " + test.Tolerance);
                //sw.WriteLine(" comments: " + test.Comments);
                //sw.WriteLine(" Simulation Type: " + test.SimulationType.ToString());
                //sw.WriteLine(" Simulation Step: " + test.SimulationStep.ToString());
                sw.WriteLine("    ---Results---");

                foreach (SavedItem issue in test.Children)
                {
                    ClashResultGroup group = issue as ClashResultGroup;
                    if (null != group)
                    {
                        sw.WriteLine(" test result group: " + group.DisplayName);
                        sw.WriteLine(" group status: " + group.Status.ToString());

                        grName   = group.DisplayName;
                        grGuid   = group.Guid.ToString();
                        grStatus = group.Status.ToString();

                        foreach (SavedItem issue1 in group.Children)
                        {
                            ClashResult rt1 = issue1 as ClashResult;
                            if (null != rt1)
                            {
                                writeClashResult(test, rt1, sw, conn, grName, grGuid, grStatus);
                            }
                        }
                    }
                    ClashResult rt = issue as ClashResult;

                    if (null != rt)
                    {
                        writeClashResult(test, rt, sw, conn, grName, grGuid, grStatus);
                    }
                }
            }
            MessageBox.Show("done");
            sw.Close();
            return(0);
        }
Beispiel #8
0
        //using Tuple to return values
        public (double gridXMin, double gridXMax, double gridYMin, double gridYMax) GridCoord()
        {
            Document           document      = Autodesk.Navisworks.Api.Application.ActiveDocument;
            DocumentClash      documentClash = document.GetClash();
            DocumentClashTests allTests      = documentClash.TestsData;
            DocumentModels     docModel      = document.Models;

            DocumentGrids docGrids   = document.Grids;
            GridSystem    docGridSys = docGrids.ActiveSystem;

            List <double> gridXCoord = new List <double>();
            List <double> gridYCoord = new List <double>();

            try
            {
                //get objects in project
                foreach (Model model in docModel)
                {
                    ModelItem root = model.RootItem as ModelItem;

                    string   dn      = root.DisplayName.ToString();
                    string[] disName = dn.Split('_', '-', '.', ' ');

                    //determine source file type by searching model file properties
                    foreach (PropertyCategory oPC in root.PropertyCategories)
                    {
                        if (oPC.DisplayName.ToString() == "Item")
                        {
                            foreach (DataProperty oDP in oPC.Properties)
                            {
                                if (oDP.DisplayName.ToString() == "Source File Name")
                                {
                                    string   val     = oDP.Value.ToDisplayString();
                                    string[] valName = val.Split('.');

                                    //source file is RVT (Revit)
                                    if (valName.Last() == "rvt")
                                    {
                                        foreach (ModelItem item in root.Children)
                                        {
                                            ModelItem subLayer2 = item as ModelItem;

                                            foreach (ModelItem subLaye3 in subLayer2.Children)
                                            {
                                                ModelItem subLayer4 = subLaye3 as ModelItem;

                                                foreach (ModelItem subLayer5 in subLayer4.Children)
                                                {
                                                    ModelItem subLayer6 = subLayer5 as ModelItem;

                                                    foreach (ModelItem subLayer7 in subLayer6.Children)
                                                    {
                                                        ModelItem subLayer8 = subLayer7 as ModelItem;

                                                        foreach (ModelItem subLayer9 in subLayer8.Children)
                                                        {
                                                            //Get object center position (X,Y,Z) by setting a 3D bounding box
                                                            ModelItem subLayer10 = subLayer9 as ModelItem;

                                                            if (subLayer10 != null)
                                                            {
                                                                BoundingBox3D bbox = subLayer10.BoundingBox();

                                                                //find closest grid intersection to object center position using API
                                                                GridIntersection gridCross = docGridSys.ClosestIntersection(bbox.Center);

                                                                //Get closest grid intersection X,Y coord
                                                                gridXCoord.Add(gridCross.Position.X);
                                                                gridYCoord.Add(gridCross.Position.Y);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    //if source file is DWG format (AutoCAD)
                                    else if (valName.Last() == "dwg")
                                    {
                                        foreach (ModelItem item in root.Children)
                                        {
                                            ModelItem subLayer2 = item as ModelItem;

                                            foreach (ModelItem subLayer3 in subLayer2.Children)
                                            {
                                                if (subLayer3 != null)
                                                {
                                                    //Get object center position (X,Y,Z) by setting a 3D bounding box
                                                    BoundingBox3D bbox = subLayer3.BoundingBox();

                                                    //find closest grid intersection to object center position using API
                                                    GridIntersection gridCross = docGridSys.ClosestIntersection(bbox.Center);

                                                    //Get closest grid intersection X,Y coord
                                                    gridXCoord.Add(gridCross.Position.X);
                                                    gridYCoord.Add(gridCross.Position.Y);
                                                }
                                            }
                                        }
                                    }
                                    //if file in selection tree is an NWD file
                                    else if (disName.Last() == "nwd")
                                    {
                                        foreach (ModelItem item in root.Children)
                                        {
                                            ModelItem disfile = item as ModelItem;

                                            string   disNwd     = disfile.DisplayName.ToString();
                                            string[] disNameNwd = disNwd.Split('_', '-', '.');

                                            foreach (PropertyCategory oPCnwd in disfile.PropertyCategories)
                                            {
                                                if (oPCnwd.DisplayName.ToString() == "Item")
                                                {
                                                    foreach (DataProperty oDPnwd in oPCnwd.Properties)
                                                    {
                                                        if (oDPnwd.DisplayName.ToString() == "Source File Name")
                                                        {
                                                            string   valNwd     = oDPnwd.Value.ToDisplayString();
                                                            string[] valNameNwd = valNwd.Split('.');

                                                            if (valNameNwd.Last() == "rvt")
                                                            {
                                                                foreach (ModelItem itemNwd in disfile.Children)
                                                                {
                                                                    ModelItem subLayer2Nwd = itemNwd as ModelItem;

                                                                    foreach (ModelItem subLayer3Nwd in subLayer2Nwd.Children)
                                                                    {
                                                                        ModelItem subLayer4Nwd = subLayer3Nwd as ModelItem;

                                                                        foreach (ModelItem subLayer5Nwd in subLayer4Nwd.Children)
                                                                        {
                                                                            ModelItem subLayer6Nwd = subLayer5Nwd as ModelItem;

                                                                            foreach (ModelItem subLayer7Nwd in subLayer6Nwd.Children)
                                                                            {
                                                                                ModelItem subLayer8Nwd = subLayer7Nwd as ModelItem;

                                                                                foreach (ModelItem subLayer9Nwd in subLayer8Nwd.Children)
                                                                                {
                                                                                    if (subLayer9Nwd != null)
                                                                                    {
                                                                                        //Get object center position (X,Y,Z) by setting a 3D bounding box
                                                                                        BoundingBox3D bbox = subLayer9Nwd.BoundingBox();

                                                                                        //find closest grid intersection to object center position using API
                                                                                        GridIntersection gridCross = docGridSys.ClosestIntersection(bbox.Center);

                                                                                        gridXCoord.Add(gridCross.Position.X);
                                                                                        gridYCoord.Add(gridCross.Position.Y);
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }

                                                            //Source file is DWG format (AutoCAD)
                                                            else if (valNameNwd.Last() == "dwg")
                                                            {
                                                                foreach (ModelItem itemNwd in disfile.Children)
                                                                {
                                                                    ModelItem subLayer2Nwd = itemNwd as ModelItem;

                                                                    foreach (ModelItem subLayer3Nwd in subLayer2Nwd.Children)
                                                                    {
                                                                        if (subLayer3Nwd != null)
                                                                        {
                                                                            //Get object center position (X,Y,Z) by setting a 3D bounding box
                                                                            BoundingBox3D bbox = subLayer3Nwd.BoundingBox();

                                                                            //find closest grid intersection to object center position using API
                                                                            GridIntersection gridCross = docGridSys.ClosestIntersection(bbox.Center);

                                                                            //Get closest grid intersection X,Y coord
                                                                            gridXCoord.Add(gridCross.Position.X);
                                                                            gridYCoord.Add(gridCross.Position.Y);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                //store max & min values to return for scatter plot data
                double gridXMin = gridXCoord.Min();
                double gridXMax = gridXCoord.Max();
                double gridYMin = gridYCoord.Min();
                double gridYMax = gridYCoord.Max();

                return(gridXMin, gridXMax, gridYMin, gridYMax);
            }

            catch (Exception exception)
            {
                MessageBox.Show("Error in Grid Coordinates Analysis!");
                exception.Message.ToString();
            }

            return(0, 0, 0, 0);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        void ClashByNetAPI()
        {
            try
            {
                Document document =
                    Autodesk.Navisworks.Api.Application.ActiveDocument;
                DocumentClash      documentClash = document.GetClash();
                DocumentClashTests oDCT          = documentClash.TestsData;

                List <ClashTestCls> tests_array = new List <ClashTestCls>();

                foreach (ClashTest test in oDCT.Tests)
                {
                    ClashTestCls oEachTest = new ClashTestCls();
                    oEachTest.DisplayName = test.DisplayName;

                    List <ClashResultCls> test_results_array = new List <ClashResultCls>();

                    foreach (SavedItem saveditem in test.Children)
                    {
                        ClashResultGroup group =
                            saveditem as ClashResultGroup;
                        if (null != group)
                        {
                            //foreach (SavedItem issue1 in group.Children)
                            //{
                            //    ClashResult rt1 = issue as ClashResult;
                            // }

                            //skip folder. just for simple demo
                        }
                        else
                        {
                            ClashResult nwissue = (ClashResult)saveditem;

                            ClashResultCls oEachResult = new ClashResultCls();
                            oEachResult.DisplayName = nwissue.DisplayName;
                            oEachResult.ApprovedBy  = nwissue.ApprovedBy;
                            oEachResult.Status      = Enum.GetName(typeof(ClashResultStatus), nwissue.Status);
                            oEachResult.Description = nwissue.Description;
                            oEachResult.Found       = nwissue.CreatedTime.Value.ToString("yyyy-MM-dd HH:mm:ss");

                            //DWG or Revit files
                            DataProperty oDP = nwissue.Item1.PropertyCategories.FindPropertyByDisplayName("Entity Handle", "Value");
                            if (oDP == null)
                            {
                                oDP = nwissue.Item1.PropertyCategories.FindPropertyByDisplayName("Element ID", "Value");
                            }
                            oEachResult.path1ID = oDP.Value.ToDisplayString();

                            oDP = nwissue.Item2.PropertyCategories.FindPropertyByDisplayName("Entity Handle", "Value");
                            if (oDP == null)
                            {
                                oDP = nwissue.Item1.PropertyCategories.FindPropertyByDisplayName("Element ID", "Value");
                            }
                            oEachResult.path2ID = oDP.Value.ToDisplayString();


                            oEachResult.CenterPt = new double[3] {
                                nwissue.Center.X,
                                nwissue.Center.Y,
                                nwissue.Center.Z
                            };


                            oEachResult.BoundingBox = new double[6] {
                                nwissue.BoundingBox.Min.X,
                                nwissue.BoundingBox.Min.Y,
                                nwissue.BoundingBox.Min.Z,
                                nwissue.BoundingBox.Max.X,
                                nwissue.BoundingBox.Max.Y,
                                nwissue.BoundingBox.Max.Z
                            };

                            oEachResult.ViewBoundingBox = new double[6] {
                                nwissue.ViewBounds.Min.X,
                                nwissue.ViewBounds.Min.Y,
                                nwissue.ViewBounds.Min.Z,
                                nwissue.ViewBounds.Max.X,
                                nwissue.ViewBounds.Max.Y,
                                nwissue.ViewBounds.Max.Z
                            };

                            oEachResult.SuitablePosition = new double[3] {
                                nwissue.ViewBounds.Max.X,
                                nwissue.ViewBounds.Min.Y,
                                (nwissue.ViewBounds.Min.Z + nwissue.ViewBounds.Max.Z) / 2.0
                            };



                            oEachResult.viewpoint = new ClashResultVP();

                            test_results_array.Add(oEachResult);
                        }
                    }//Result
                    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());
            }
        }
Beispiel #11
0
        public void Program()
        {
            //Name of input file
            OpenFileDialogForm_1 opFile = new OpenFileDialogForm_1();
            string FilePathTxt          = opFile.OpenFileDialogForm().ToString();

            if (FilePathTxt == "")
            {
                opFile.Close();
                return;
            }

            string newDirName = "";

            //Files pathes reading
            string[] lines       = File.ReadAllLines(FilePathTxt).Where(s => s.Trim() != string.Empty).ToArray();
            string   CurDate     = DateTime.Now.ToString("yyMMdd");
            string   CurDateTime = DateTime.Now.ToString("yyMMdd_HHmmss");

            if (Testing(lines, CurDateTime) == 0)
            {
                //Output folder for Excel
                if (newDirName == "")
                {
                    OpenFolder opFold = new OpenFolder();
                    newDirName = opFold.OpenFolderDialogForm() + ((char)92).ToString();
                    if (newDirName == "")
                    {
                        return;
                    }
                }


                string FileName = CurDate + "_Сводный_отчёт_по_коллизиям.xlsx";

                ExcelCheckActiveWorkbook(FileName);

                //Open Excel
                var excelApp = new Excel.Application
                {
                    Visible = false
                };
                excelApp.Workbooks.Add();
                Excel.Worksheet newWorksheet = null;
                Excel.Sheets    sheets       = excelApp.ActiveWorkbook.Sheets;
                Excel.Worksheet lastSheet    = sheets[1];

                //Intiating main process
                try
                {
                    for (int il = 0; il < lines.Length; il++)
                    {
                        string FilePath    = lines[il];
                        string GetFileName = Path.GetFileName(FilePath);

                        string WorksheetName = NameOfSheet(GetFileName, out string field1, out string field2);

                        Autodesk.Navisworks.Api.Application.FileInteractiveResolving += Application_FileInteractiveResolving;

                        Autodesk.Navisworks.Api.Application.ActiveDocument.TryOpenFile(FilePath);

                        Document           oDoc          = Autodesk.Navisworks.Api.Application.ActiveDocument;
                        DocumentClash      documentClash = oDoc.GetClash();
                        DocumentClashTests oDCT          = documentClash.TestsData;


                        if (oDCT.Tests.Count != 0)
                        {
                            TestSearchResultsInitialising(oDCT, WorksheetName, ref newWorksheet, ref lastSheet, sheets);
                        }
                        else
                        {
                            LogWriter("No clash tests found in the file: ", FilePath, CurDateTime);
                            MessageBox.Show("Process has been stoped because errors occured!" + "\n" + "Log saved: " + LogPath(CurDateTime));
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }


                if (sheets.Count > 1)
                {
                    sheets[1].Delete();
                }

                //Total sheet creating
                TotalSheet(excelApp, newWorksheet, lines);

                try
                {
                    excelApp.ActiveWorkbook.SaveAs(newDirName + FileName);
                }
                catch
                { }

                excelApp.Visible = true;
                MessageBox.Show(Autodesk.Navisworks.Api.Application.Gui.MainWindow, "Done!");
            }
            else
            {
                MessageBox.Show("Process has been stoped because errors occured!" + "\n" + "Log saved: " + LogPath(CurDateTime));
                return;
            }
        }
Beispiel #12
0
        public override int Execute(params string[] parameters)
        {
            MessageBox.Show("Hello World!", "Execute", MessageBoxButtons.OK, MessageBoxIcon.Information);

            string connstr = "Data Source = (localdb)\\ProjectsV13; Initial Catalog = ClashDB; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = True; ApplicationIntent = ReadWrite; MultiSubnetFailover = False";
            //SQL Connection
            SqlConnection conn = new SqlConnection(connstr);

            //SQL Command - Stored Procedure
            SqlCommand cmdClashData = new SqlCommand("dbo.createClashData", conn);

            cmdClashData.CommandType = CommandType.StoredProcedure;

            //Create SQL Parameters

            cmdClashData.Parameters.Add(new SqlParameter("@testName", SqlDbType.NVarChar, 100));
            cmdClashData.Parameters.Add(new SqlParameter("@testStatus", SqlDbType.NVarChar, 50));
            cmdClashData.Parameters.Add(new SqlParameter("@testType", SqlDbType.NVarChar, 50));
            cmdClashData.Parameters.Add(new SqlParameter("@testLastRun", SqlDbType.SmallDateTime));
            cmdClashData.Parameters.Add(new SqlParameter("@testTolerance", SqlDbType.Float, 53));
            cmdClashData.Parameters.Add(new SqlParameter("@groupName", SqlDbType.NVarChar, 50));
            cmdClashData.Parameters.Add(new SqlParameter("@groupStatus", SqlDbType.NVarChar, 50));


            //Navisworks Document Clash Data
            Document           document      = Autodesk.Navisworks.Api.Application.ActiveDocument;
            DocumentClash      documentClash = document.GetClash();
            DocumentClashTests oDCT          = documentClash.TestsData;

            //Loop for getting clash test results
            foreach (ClashTest test in oDCT.Tests)
            {
                cmdClashData.Parameters["@testName"].Value = test.DisplayName;

                cmdClashData.Parameters["@testStatus"].Value = test.Status.ToString();
                cmdClashData.Parameters["@testType"].Value   = test.TestType.ToString();
                if (test.LastRun != null)
                {
                    cmdClashData.Parameters["@testLastRun"].Value = test.LastRun.Value.ToShortDateString();
                }
                cmdClashData.Parameters["@testTolerance"].Value = test.Tolerance;

                conn.Open();

                cmdClashData.ExecuteNonQuery();

                foreach (SavedItem issue in test.Children)
                {
                    ClashResultGroup group = issue as ClashResultGroup;
                    if (null != group)
                    {
                        cmdClashData.Parameters["@groupName"].Value   = group.DisplayName;
                        cmdClashData.Parameters["@groupStatus"].Value = group.Status.ToString();

                        cmdClashData.ExecuteNonQuery();

                        foreach (SavedItem issue1 in group.Children)
                        {
                            ClashResult rt1 = issue1 as ClashResult;
                            if (null != rt1)
                            {
                                writeClashResult(rt1, cmdClashData);
                            }
                        }
                    }

                    ClashResult rt = issue as ClashResult;
                    if (null != rt)
                    {
                        writeClashResult(rt, cmdClashData);
                    }
                }
            }

            MessageBox.Show("Done");
            conn.Close();
            //string sql = "INSERT INTO [ClashDB].[Table] ";
            //SqlCommand cmdAddClashData = new SqlCommand
            return(0);
        }