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();
}
}
Solved! Go to Solution.
Solved by Mohamed_Arshad. Go to Solution.
Solved by harrymattison. Go to Solution.
Are you calling
RevitLinkInstance..::..GetLinkDocument |
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 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.