Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Plugin doesnt work in linked models

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
yfrankley
224 Views, 3 Replies

Plugin doesnt work in linked models

Hello everyone, I hope this message find you well.

In the last few days I have been work on a plugin that place interior elevations in the center of specifics rooms (bathroom and kitchen). Finally, I reached my goal, and the plugin worked perfect for my needs. But I have a probem, this plugin just works in model, but doesnt work in linked models. I'm missing some small detail about document access, do you guys have some clue?

 

Below you can see parts of my code, mainly about document access.
I appreciate your time, thanks.

 

 

namespace PlaceInteriorElevation
{
    [Transaction(TransactionMode.Manual)]
    public class Command5 : IExternalCommand
    {
        //Variables members
        UIApplication _uiapp;
        UIDocument _uidoc;
        Document _doc;

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            _uiapp = commandData.Application;
            _uidoc = _uiapp.ActiveUIDocument;
            _doc = _uidoc.Document;

            FilteredElementCollector rCollector = RoomCollector();

            ////List all rooms.
            //ListAllRooms();

            ///List all templates.
            //ListAllViewTemplatesInCurrentDoc();

            ViewFamilyType viewFamilyType = ViewFamilyTypeFilter();

            if (viewFamilyType != null)
            {

                using (Transaction tx = new Transaction(_doc))
                {
                    try
                    {
                        tx.Start("Command5");

                        //code continue...

                        tx.Commit();
                     }
                     catch (Exception e)
                     {
                         Debug.Print(e.Message);
                         tx.RollBack();
                     }
                }

 

 

Tags (3)
3 REPLIES 3
Message 2 of 4
harrymattison
in reply to: yfrankley

Are you calling 

RevitLinkInstance..::..GetLinkDocument
 for each linked Revit file, and then finding all the rooms in those linked documents?
You likely will also need to account for the transformation of the Revit Link (see https://thebuildingcoder.typepad.com/blog/2011/07/linked-element-geometry-access.html)
Message 3 of 4
Mohamed_Arshad
in reply to: yfrankley

HI @yfrankley 

    Kindly Pass the Linked Document while Filtering, Ensure the Passing Document as Linked Document. to get the Linked Document, Kindly check the below code.

 

Reference Code:

 

//Get the Linked Document Instance (I'm Choosing First Linked Document From the List)
            RevitLinkInstance linkedDocInstance = new FilteredElementCollector(doc)
                .OfClass(typeof(RevitLinkInstance))
                .First() as RevitLinkInstance;

            //Get the Linked Instance Document
            Document linkedDoc = linkedDocInstance.GetLinkDocument();


            //To Filter Room Inside the Linked Document
            List<Room> rooms = new FilteredElementCollector(linkedDoc)
                .OfClass(typeof(SpatialElement))
                .Cast<Room>()
                .ToList();

 

 

Hope this will Helps 🙂

Thanks & Regards,
Mohamed Arshad K
Message 4 of 4
yfrankley
in reply to: yfrankley

Thanks a lot @harrymattison and @harrymattison , a reached my goal.

Below are my function to return all rooms in the current view of linked model

 

#region RoomCollectorLink()
/// <summary>
/// Filter the document looking for rooms in linked doc.
/// </summary>
/// <returns>All rooms in the current view linked</returns>
public static FilteredElementCollector RoomCollectorLink2(Document doc)
{
    FilteredElementCollector linkedDocCollector = new FilteredElementCollector(doc);

    ICollection<ElementId> linkedInstanceIds = linkedDocCollector
        .OfCategory(BuiltInCategory.OST_RvtLinks)
        .ToElementIds();

    foreach (ElementId linkedInstanceId in linkedInstanceIds)
    {
        RevitLinkInstance linkedDocInstance = doc.GetElement(linkedInstanceId) as RevitLinkInstance;

        if (linkedDocInstance != null)
        {
            Document linkedDoc = linkedDocInstance.GetLinkDocument();

            FilteredElementCollector rCollector = new FilteredElementCollector(linkedDoc)
                .OfCategory(BuiltInCategory.OST_Rooms)
                .WhereElementIsNotElementType();

            IList<Element> roomsInLinkedModel = rCollector.ToElements();

            string s = "Rooms in linked model: \r\n";
            int num = 1;
            foreach (Element room in roomsInLinkedModel)
            {
                s += $"{num} - {room.Name}\n";
                num++;
            }

            TaskDialog.Show("Rooms", s);
            return rCollector;
        }
    }
    return null;
}
#endregion

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report