Naveen Kumar

Working with Local Coordination Models

By Naveen Kumar

To link a local Coordination Model in Revit, you can use Revit's API to automate the process. The goal is to retrieve all existing Coordination Model instances in your document and check their details to find the one you need. If it isn't already present, you can trigger a command to insert a new local Coordination Model.

First, you access the active document through the `UIDocument` class. Using the `DirectContext3DDocumentUtils.GetDirectContext3DHandleInstances` method, you get all the Coordination Model instances in the document. This method returns a collection of element IDs, which you then loop through to examine each instance.

For each element, you retrieve its type element and check the Path parameter to see if it matches the Coordination Model you're looking for. If the desired model isn't found, you can post a command to open the dialog for inserting a local Coordination Model.

The presented code sample effectively illustrates this procedure. Initially, it retrieves the active document and proceeds to retrieve the instances of Coordination Models. Each instance undergoes thorough examination to identify the Path parameter. In case the desired Coordination Model is not found, users have the option to execute a command that will prompt the insertion of a local Coordination Model. This command can be initiated through either `PostableCommand.CoordinationModelLocal` for Revit versions from 2024 onwards, or `PostableCommand.CoordinationModel` for pre-Revit 2023 versions.


UIDocument activeDoc = commandData.Application.ActiveUIDocument;
Document doc = activeDoc.Document;
ICollection<ElementId> instanceIds = DirectContext3DDocumentUtils.GetDirectContext3DHandleInstances(doc, new ElementId(BuiltInCategory.OST_Coordination_Model));
foreach (var id in instanceIds)
{
    Element elem = doc.GetElement(id);
    if (null != elem)
    {
        Element typeElem = doc.GetElement(elem.GetTypeId());
        if (null != typeElem)
        {
            Parameter param = typeElem.LookupParameter("Path");
            string path = param.AsValueString();
            // Check if this is the CM you're looking for by evaluating 'path'
        }
    }
}

// If the CM is not found, post a command to insert a local CM
RevitCommandId coordinationModeCmdId = RevitCommandId.LookupPostableCommandId(PostableCommand.CoordinationModelLocal);
if (coordinationModeCmdId != null)
{
    commandData.Application.PostCommand(coordinationModeCmdId);
}

04/05/2024

06/13/2023

10/04/2022

10/03/2022

05/04/2022

June 2024

Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            

Autodesk Blogs

Share