Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Navisworks API 2022: Writing Collision Data to XML

OmarovKK
Contributor

Navisworks API 2022: Writing Collision Data to XML

OmarovKK
Contributor
Contributor

Hello,

I need to write the Id parameter of the collision element from Revit and the GUID of the collision to an XML file using the Navisworks COM. Could you please guide me on how to achieve this correctly?

Thank you!

OmarovKK_0-1725365146245.png

private static void ExportResultsToXml(NavisworksIntegratedAPI19.InwClashTestsColl clashResults, string filePath)
{
    using (var writer = new StreamWriter(filePath))
    {
        writer.WriteLine("<ClashResults>");
        foreach (NavisworksIntegratedAPI19.InwOclClashTest2 clashTest in clashResults)
        {
            foreach (NavisworksIntegratedAPI19.InwOclTestResult2 clashResult in clashTest.results())
            {
                writer.WriteLine("  <ClashResult>");
                writer.WriteLine($"    <Name>{clashResult.name}</Name>");

                writer.WriteLine("    <Element1Path>");
                NavisworksIntegratedAPI19.InwOaPath2 Path1 = (InwOaPath2)clashResult.Path1;

                GetAttributeValue(Path1, "LcRevitPropertyElementId"); //here is a method to find the parameter values

                WritePathNodesToXml(writer, Path1);
                writer.WriteLine("    </Element1Path>");
                // Записываем все узлы для Element2Path
                writer.WriteLine("    <Element2Path>");
                NavisworksIntegratedAPI19.InwOaPath2 Path2 = (InwOaPath2)clashResult.Path2;
                WritePathNodesToXml(writer, Path1);
                writer.WriteLine("    </Element2Path>");                        

                string bound = ExtractBoundFromComObject(clashResult.Bound);
                writer.WriteLine($"    <Bound>{bound}</Bound>");


                writer.WriteLine($"    <Status>{clashResult.status}</Status>");
                writer.WriteLine($"    <Distance>{clashResult.distance}</Distance>");

                writer.WriteLine("  </ClashResult>");
            }
        }
        writer.WriteLine("</ClashResults>");
    }
}

private static string GetAttributeValue(NavisworksIntegratedAPI19.InwOaPath2 inwOaPath2, string attributeName)
{
    try
    {
        var attribute = inwOaPath2.FindAttribute(attributeName, true);
        if (attribute != null)
        {
            return attribute.UserName; // Предполагается, что значение атрибута можно преобразовать в строку
        }
    }
    catch
    {
        return " NA";
    }
    return "NA";
}

 

0 Likes
Reply
Accepted solutions (1)
618 Views
5 Replies
Replies (5)

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @OmarovKK ,

 

It appears that you're able to access and retrieve most of the necessary data. The challenge seems to be extracting the element ID, and then writing the collision data to XML using the COM API. Is that correct?

To assist you better, I need some additional details. Could you please describe your workflow? A detailed description will help me understand the situation more clearly and provide you with a more effective solution.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes

OmarovKK
Contributor
Contributor

Hi @naveen.kumar.t
My workflow is that I try to automatically write all clashes and their parameters to an XML file. To do this, I look at the results of the clash check and write the parameters. I get the parameters of the clashes, but I can't get the parameters of the elements that are involved in the clash (namely the Revit ID).
Maybe you know how to get the parameters of the element that is involved in the clash?

0 Likes

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @OmarovKK ,

 

1. Obtain DocumentClash
2. Retrieve ClashTest
3. Within ClashTest, access Selection A and Selection B
4. Selection A and Selection B are instances of ModelItemCollection.
5. From ModelItemCollection, access ModelItems, and then retrieve the associated parameters from ModelItems

Here are the useful links

https://forums.autodesk.com/t5/navisworks-api/accessing-specific-clash-test-object-to-find-object-s-... 

https://adndevblog.typepad.com/aec/2012/05/navisworks-net-api-2013-new-feature-clash-1.html 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes

OmarovKK
Contributor
Contributor

Thank you! I managed to extract the ID via SmartTeg!
Do you know how to get a GUID collision via COM?
Via the NET API it exists as a parameter (see screenshot 1), but in COM it is absent (see screenshot 2).

OmarovKK_1-1725633375188.pngOmarovKK_2-1725633430926.png

 

0 Likes

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @OmarovKK ,

 

Sorry, I'm not an expert on the COM API.

The COM API is too old and Autodesk has stopped supporting the COM API for Navisworks.
If a case is about the possibility of a COM API, you can try searching the blog or SDK sample for any quick clue. Note that Autodesk no longer supports the COM API when it comes to troubleshooting.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes