How to export Clash Test Results to HTML and XML using Navisworks API?

How to export Clash Test Results to HTML and XML using Navisworks API?

Anonymous
Not applicable
3,732 Views
9 Replies
Message 1 of 10

How to export Clash Test Results to HTML and XML using Navisworks API?

Anonymous
Not applicable

Navis.PNG

Does Navisworks API have predefined functions for exporting Clash Test Results to HTML and XML?

0 Likes
3,733 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Hi, did you find a solution? I'm having the same problem... Thanks in advance!

0 Likes
Message 3 of 10

Anonymous
Not applicable

It would seem that Navisworks API does not provide the functions for exporting to HTML and XML, but it does provide the means to extract all information about the clash result (Element IDs, paths, clash points and etc.) except for the clash image.

Message 4 of 10

Anonymous
Not applicable

That's what I thought... So, in order to run all the clash tests and create the reports I should do something like this, right?

 

DocumentClash documentClash = DocumentExtensions.GetClash(Application.ActiveDocument);
DocumentClashTests oDCT = documentClash.TestsData;


oDCT.TestsRunAllTests();

 

foreach (ClashTest test in oDCT.Tests)
{
     //Create each report
}

 

Thank you very much!

0 Likes
Message 5 of 10

Anonymous
Not applicable

I am personally using the Navisworks COM API because I couldn't figure out how to extract the item paths and IDs. But to Run the Clash Tests, yes your code is correct.

ComApi.InwOpState10 oState;
oState = ComApiBridge.ComApiBridge.State;
ComApi.InwOpClashElement m_clash = null;

foreach (ComApi.InwOclClashTest clashTest in m_clash.Tests()) {
    if (clashTest.results().Count <= 0) {
        continue;
    }

    foreach (ComApi.InwOclTestResult clashResult in clashTest.results()) {
       // do your thing
    }
}

  

Message 6 of 10

Anonymous
Not applicable

Hello again!

I'm assuming "item paths" are the equivalent to Item 1 and Item 2 that appear as columns in HTML reports, right?

Do you know how to get its ElementID and Type values, as they appear in HTML reports given a InwOclTestResult? 

 

Thank you very much.

 

0 Likes
Message 7 of 10

Anonymous
Not applicable

This code for Element IDs works for me, not sure if it will work for you:

private string getItem1ElementID(ComApi.InwOpState10 oState, ComApi.InwOclTestResult clashResult) {
	List < string > element_1_IDs = new List < string > ();
	List < string > element_1_junk = new List < string > ();
	string[] properties = {
		"LcOaNat64AttributeValue",
		"LcRevitPropertyElementName",
		"LcRevitPropertyElementType",
		"LcRevitPropertyElementFamily",
		"LcRevitPropertyElementCategory",
		"LcOaNat64AttributeValue"
	};

	foreach(ComApi.InwOaNode node in clashResult.Path1.Nodes()) {
		//System.Diagnostics.Debug.WriteLine("****************");
		foreach(ComApi.InwOaAttribute nodeAttr in node.Attributes()) {
			ComApi.InwOaPropertyVec pVec = oState.GetAttributeProperties(nodeAttr);

			foreach(ComApi.InwOaProperty nodeProp in pVec.Properties()) {
				String string_val = nodeProp.value as String;
				if (properties.Any(s = >s.Equals(nodeProp.name))) {
					//System.Diagnostics.Debug.WriteLine(nodeProp.name + ": " + string_val);
					element_1_junk.Add(string_val);
				}
			}
		}
	}

	int temp;
	element_1_IDs = element_1_junk.Where(x = >int.TryParse(x, out temp)).ToList();

	if (element_1_IDs.Count > 1) {
		return element_1_IDs[1];
	} else {
		return element_1_IDs[0];
	}

}


private string getItem2ElementID(ComApi.InwOpState10 oState, ComApi.InwOclTestResult clashResult) {
	List < string > element_2_IDs = new List < string > ();
	List < string > element_2_junk = new List < string > ();
	string[] properties = {
		"LcOaNat64AttributeValue",
		"LcRevitPropertyElementName",
		"LcRevitPropertyElementType",
		"LcRevitPropertyElementFamily",
		"LcRevitPropertyElementCategory",
		"LcOaNat64AttributeValue"
	};

	foreach(ComApi.InwOaNode node in clashResult.Path2.Nodes()) {
		//System.Diagnostics.Debug.WriteLine("****************");
		foreach(ComApi.InwOaAttribute nodeAttr in node.Attributes()) {
			ComApi.InwOaPropertyVec pVec = oState.GetAttributeProperties(nodeAttr);

			foreach(ComApi.InwOaProperty nodeProp in pVec.Properties()) {
				String string_val = nodeProp.value as String;
				if (properties.Any(s = >s.Equals(nodeProp.name))) {
					//System.Diagnostics.Debug.WriteLine(nodeProp.name + ": " + string_val);
					element_2_junk.Add(string_val);
				}
			}
		}
	}

	int temp;
	element_2_IDs = element_2_junk.Where(x = >int.TryParse(x, out temp)).ToList();

	if (element_2_IDs.Count > 1) {
		return element_2_IDs[1];
	} else {
		return element_2_IDs[0];
	}
}

 

As for the Types and Names, you might as well extract them from the Item Paths?

// Item 1 Path
private string getItem1Path(ComApi.InwOclTestResult clashResult) {
	string Item1_Path = "";

	foreach(ComApi.InwOaNode node in clashResult.Path1.Nodes()) {
		string username_node = node.UserName;
		if (username_node.Length == 0) {
			username_node = node.ClassUserName + "_";
		}
		Item1_Path = Item1_Path + "->" + username_node;
	}

	return Item1_Path;
}

// Item 2 Path
private string getItem2Path(ComApi.InwOclTestResult clashResult) {
	string Item2_Path = "";

	foreach(ComApi.InwOaNode node in clashResult.Path2.Nodes()) {
		string username_node = node.UserName;
		if (username_node.Length == 0) {
			username_node = node.ClassUserName + "_";
		}
		Item2_Path = Item2_Path + "->" + username_node;
	}

	return Item2_Path;
}
0 Likes
Message 8 of 10

Anonymous
Not applicable

Thank you for your answer. In the meanwhile I finally found how to get those values from a ClashResult (.NET):

Tuple<string, string> resultsItem2 = getIDAndTypeFromItem(clash.Item2);
...

private Tuple<string, string> getIDAndTypeFromItem(ModelItem item)
{
    PropertyCategoryCollection properties = item.PropertyCategories;

    string type = null;

    foreach (PropertyCategory propertyCategory in properties)
    {
           if (propertyCategory.DisplayName == "Item")
           {
                foreach (DataProperty prop in propertyCategory.Properties)
                {
                      if (prop.DisplayName == "Type")
                      {
                            type = prop.Value.ToDisplayString();
                            break;
                      }
                 }

                 if (type != null)
                 {
                        break;
                 }
          }
     }

     string id = null;
     if (item.Parent != null)
     {
          foreach (PropertyCategory propertyCategory in item.Parent.PropertyCategories)
          {
               if (propertyCategory.DisplayName == "Element ID")
               {
                   foreach (DataProperty prop in propertyCategory.Properties)
                   {
                        if (prop.DisplayName == "Value")
                        {
                             id = prop.Value.ToDisplayString();
                             break;
                        }
                   }

                    if (id != null)
                    {
                          break;
                    }
               }
           }
     }

     return new Tuple<string, string>(id, type);
}
Message 9 of 10

Anonymous
Not applicable

If you still need to know how to export Clash Result Images, I made a post here: https://forums.autodesk.com/t5/navisworks-api/here-s-how-to-export-clash-result-images-using-naviswo...

0 Likes
Message 10 of 10

Anonymous
Not applicable

I'll check it out, thank you!

0 Likes