Code in help Revit api

Code in help Revit api

sonicer
Collaborator Collaborator
477 Views
1 Reply
Message 1 of 2

Code in help Revit api

sonicer
Collaborator
Collaborator

Hello,

Is this code correctly in Revit official webpage? from room, to room and room .

sonicer_0-1591260618749.png

 

I found the correct code on Building Coder webpage as: Or I don't understand code syntax?

Room froom = door.get_FromRoom(phase);

Room troom = door.get_ToRoom(phase);

 

thx.

 

0 Likes
478 Views
1 Reply
Reply (1)
Message 2 of 2

kraftwerk15
Advocate
Advocate

Here's some code. Yep, pretty much you got it. In the last two lines, trying to search for where the from room and to room of a door match a room in a particular phase. Here my (lazy) variable name was called phaser, which is passed in as a Phase element from Revit.

 

Happy Coding!

 

Element elem = doc.GetElement(modifiedElemId);
string phase = elem.GetParameters("Phase").FirstOrDefault().AsValueString();
//Phase phase2 = elem.GetParameters("Phase").FirstOrDefault().Element as Phase;
ElementId phaseid = elem.GetParameters("Phase Id").FirstOrDefault().AsElementId();
Phase phaser = doc.GetElement(phaseid) as Phase;
//TODO consider implementing Parameter Filters instead of pulling items here to LINQ
//IEnumerable<Autodesk.Revit.DB.FamilyInstance> enmu2 = ls.Where(x => x.get_ToRoom(phaser) != null && x.get_FromRoom(phaser) != null);
//IEnumerable<Autodesk.Revit.DB.FamilyInstance> enmu4 = ls.Where(z => z.Name.StartsWith("DR"));
IEnumerable<Autodesk.Revit.DB.FamilyInstance> enmu3 = ls.Where(w => w.GetPhaseStatus(phaseid) == ElementOnPhaseStatus.Existing || w.GetPhaseStatus(phaseid) == ElementOnPhaseStatus.New || w.GetPhaseStatus(phaseid) == ElementOnPhaseStatus.Temporary);

IEnumerable<Autodesk.Revit.DB.FamilyInstance> enmu2 = enmu3.Where(x => x.get_ToRoom(phaser) != null || x.get_FromRoom(phaser) != null);
IEnumerable<Autodesk.Revit.DB.FamilyInstance> enmu = enmu2.Where(y => y.get_ToRoom(phaser).Id == modifiedElemId || y.get_FromRoom(phaser).Id == modifiedElemId);

 

0 Likes