How to set the tolerance for existing Clash Tests

How to set the tolerance for existing Clash Tests

ratno123s
Contributor Contributor
533 Views
1 Reply
Message 1 of 2

How to set the tolerance for existing Clash Tests

ratno123s
Contributor
Contributor

I am trying to Create/Update clash tests with the following code:

private ClashTest GetClashTest(string ClashtestName, double tolerance)
        {
            DocumentClash documentClash = Autodesk.Navisworks.Api.Application.ActiveDocument.GetClash();
            ClashTest ct = documentClash.TestsData.Tests.Where(x => x.DisplayName == ClashtestName).FirstOrDefault() as ClashTest;
            if (ct == null)
            {
                ct = new ClashTest();
                ct.Tolerance = tolerance;
                ct.TestType = ClashType;
                ct.DisplayName = ClashtestName;
                documentClash.TestsData.TestsAddCopy(ct);
                ct = documentClash.TestsData.Tests.Where(x => x.DisplayName == ClashtestName).FirstOrDefault() as ClashTest;
            }
            else
            {
                ct.Tolerance = tolerance;
                ct.TestType = ClashType;
            }
            return ct;
        }

The code works in the If part where I am creating a new Clash Test, but it throws an exception in the Else part where I am trying to set the tolerance of the existing ClashTest ( ct.tolerance=tolerance).

The exception says that the clash test is unmodifiable. 

Please help me in setting the tolerance of existing clash tests

0 Likes
Accepted solutions (1)
534 Views
1 Reply
Reply (1)
Message 2 of 2

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @ratno123s ,

 

For already existing clash test, please try using the below sample code

1. You need to create a copy of your clash test. Let's call it "ClashTestCopy"
2. Edit the parameters of "ClashTestCopy"
3. Use DocumentClashTests.TestsEditTestFromCopy()


Here is the sample code

DocumentClash documentClash = Autodesk.Navisworks.Api.Application.ActiveDocument.GetClash();
DocumentClashTests clashTests = documentClash.TestsData;
ClashTest clashTest = clashTests.Tests.Where(c => c.DisplayName == "Test 1").First() as ClashTest;
if(clashTest!=null)
  {                
   ClashTest new_clashTest = clashTest.CreateCopy() as ClashTest;
   new_clashTest.Tolerance =Tolerance Value in Double;
   new_clashTest.TestType = ClashTestType.HardConservative;
   clashTests.TestsEditTestFromCopy(clashTest, new_clashTest);                
  }

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network