Adding a list of ClashResults to a new ClashResultGroup

Adding a list of ClashResults to a new ClashResultGroup

WalidGLVEK
Explorer Explorer
607 Views
3 Replies
Message 1 of 4

Adding a list of ClashResults to a new ClashResultGroup

WalidGLVEK
Explorer
Explorer

Hi all, 

 

I would need your help in regards to the above please. 

 

I am writing a code to group clashes based on revit category. I have been successful in getting to a point where I have now a List<ClashResult> that contains the results that I would like to add to a new ClashResultGroup.  Which then will be copied to a clash test copy and then replace the original test. 

 

I have everything working except that when I attempt to add the result or results to the ClashResultGroup, I get an error saying that Childing is read only. 

 

the code I am using to add the results is ClashResultGroup.Childern.Add(clashresult)

 

How do I tackle this issue? Any ideas?

 

kind regards, 

Walid 

0 Likes
Accepted solutions (1)
608 Views
3 Replies
Replies (3)
Message 2 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @WalidGLVEK ,

 

Please try using the below sample code

 private void MyCode(Document doc)
   {
     string groupName = "ClashGroupName1";           
     ClashResultGroup group2 = AddOrGetResultsGroup(doc,groupName);
     MoveClashesInsideGroup(doc,group2);
   }
 private ClashResultGroup AddOrGetResultsGroup(Document doc,string groupName)
        {
            string required_GroupName = groupName;           
            DocumentClash documentClash = doc.GetClash();
            DocumentClashTests oDCT = documentClash.TestsData;
            ClashTest t = oDCT.Tests[0] as ClashTest;
            //add new group if required
            ClashResultGroup group;
            int groupNdx = t.Children.IndexOfDisplayName(required_GroupName);
            if (-1 == groupNdx)
            {
                ClashResultGroup newGroup = new ClashResultGroup();
                newGroup.DisplayName = required_GroupName;
                oDCT.TestsInsertCopy(t, 0, newGroup);
                group = (ClashResultGroup)t.Children[0];
            }
            else
            {
                group = (ClashResultGroup)t.Children[groupNdx];
            }
            return group;
        }
  private void MoveClashesInsideGroup(Document doc,ClashResultGroup group)
        {
            DocumentClash documentClash = doc.GetClash();
            DocumentClashTests oDCT = documentClash.TestsData;
            ClashTest t = oDCT.Tests[0] as ClashTest;
            SavedItemCollection clashes = t.Children;
            int resultsCount = t.Children.Count;
            for (int i = resultsCount - 1; i >= 0; i--)
            {
                SavedItem issue = (SavedItem)t.Children[i];
                ClashResult rt = issue as ClashResult;
                if (null != rt)
                {
                    if (ClashResultStatus.New == rt.Status)
                        oDCT.TestsMove(t, i, group, 0);
                }
            }
        }

For more details,

Please take a look at these below links
https://adndevblog.typepad.com/aec/2012/05/navisworks-net-api-2013-new-feature-clash-1.html 
https://adndevblog.typepad.com/aec/2012/05/navisworks-net-api-2013-new-feature-clash-2.html 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 4

WalidGLVEK
Explorer
Explorer

Hi @naveen.kumar.t , 

 

Thank you so much for the sample code above and the resources provided. They were of great help to me. 

 

kind regards, 

Walid 

0 Likes
Message 4 of 4

AsankaWaga
Observer
Observer

Thanks, this code is working.

0 Likes