Domanda

Ho due progetti Revit, MainProject.rvt e ProjectTolink.rvt. Mainproject.rvt contiene un collegamento a ProjectTolink.rvt. Utilizzando il codice seguente mentre nel documento MainProject.rvt posso accedere al link stesso:

FilteredElementCollector linkedModelCollector = new FilteredElementCollector(document);
linkedModelCollector.OfCategory(BuiltInCategory.OST_RvtLinks);

foreach (Element linkedModel in linkedModelCollector)
{
   //Do something
}

Come posso accedere agli elementi all'interno del modello collegato ProjectTolink.rvt da MainProject.rvt? Posso usare l'elemento di collegamento stesso come nel codice sopra o c'è un altro meccanismo?

PS - Ho bisogno di questo per funzionare per Revit 2011

È stato utile?

Soluzione

In Revit 2012 uso le seguenti funzioni:

public IEnumerable<ExternalFileReference> GetLinkedFileReferences()
        {
            //ElementFilter categoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_RvtLinks);
            //ElementFilter typeFilter = new ElementClassFilter(typeof(Instance));
            //ElementFilter logicalFilter = new LogicalAndFilter(categoryFilter, typeFilter);

            var collector = new FilteredElementCollector(_document);
            var linkedElements = collector
                .OfClass(typeof (RevitLinkType))
                //.OfCategory(BuiltInCategory.OST_RvtLinks)
                //.WherePasses(logicalFilter)
                .Select(x => x.GetExternalFileReference())
                .ToList();

            return linkedElements;                       
        }

e

public IEnumerable<Document> GetLinkedDocuments()
        {
            var linkedfiles = GetLinkedFileReferences();
            //List<String> linkedFileName = new List<string>(linkedfiles.Count);            

            var linkedFileNames = linkedfiles                
                .Select(x => ModelPathUtils.ConvertModelPathToUserVisiblePath(x.GetAbsolutePath()))                
                .ToList();

            //linkedFileName.AddRange
            //    (from linkedfile in linkedfiles 
            //     select linkedfile.GetTypeId() into typeId 
            //     where typeId != null 
            //     select document.get_Element(typeId).Name);

            return _document.Application.Documents
                .Cast<Document>()
                .Where(doc => linkedFileNames
                    .Any(fileName => doc.PathName.Equals(fileName)));
        }

Il primo ottiene collegamenti a file collegati (come nel codice) e il secondo - ottieni docimenti che rappresentano i file collegati. Quindi, quando si dispone di un documento puoi ottenere qualsiasi elemento da esso tramite FiltereDelementCollector. Ma ricorda che non puoi modificare gli elementi nei file collegati.

Prova a trovare funzioni simili nell'API Revit 2011. E leggi Questo articolo

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top