Room Separation Line - Associated Level

Room Separation Line - Associated Level

gprofile
Enthusiast Enthusiast
3,000 Views
6 Replies
Message 1 of 7

Room Separation Line - Associated Level

gprofile
Enthusiast
Enthusiast

Is it possible to get the associated level of a Room separation Line by creating a simple Macro, as it isn't available in the properties.

iplaod.PNG

 

 

 

I checked in the Revit 2017.1 API documentation but couldnt find  anything related to Room Separation Line.

0 Likes
Accepted solutions (1)
3,001 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

You should be able to get the owner view, cast it as ViewPlan and get the Level from the view plan.

 

 var viewPlan = (ViewPlan) Document.GetElement(modelCurve.OwnerViewId);
 var level = (Level) Document.GetElement(viewPlan.LevelId);
Message 3 of 7

FAIR59
Advisor
Advisor
Accepted solution

the room separation line can be visible in floorplans of a different level, or even in 3D views.

 

this will sound a bit hacky, but the name of the sketchplane of the separationline is equal to the name of the level.

 

                SketchPlane sk = modelcurve.SketchPlane;
                IEnumerable<Level> levels = new FilteredElementCollector(doc)
                	.OfClass(typeof(Level))
                	.Cast<Level>()
                	.Where( l => l.Name.Equals(sk.Name));
                Level LevelofLine = levels.FirstOrDefault();

 

another approach would be to find the level by the height from the sketchplane.Plane  [ height = sk.GetPlane().Origin.Z ]

0 Likes
Message 4 of 7

gprofile
Enthusiast
Enthusiast

Excuse me for my ignorance in C# i tried the code below but couldn't solve the error

 

Error CS0039: The Autodesk.Revit.DB.GeometryObject type cannot be converted to Autodesk.Revit.DB.ModelCurve with a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or NULL type conversion.
 
UIDocument uiDoc = this.ActiveUIDocument;
Document doc = uiDoc.Document;
			
Reference myRef = uiDoc.Selection.PickObject(ObjectType.Element);
Element ele = doc.GetElement(myRef);
			
GeometryObject geomObj = ele.GetGeometryObjectFromReference(myRef);
ModelCurve modelcurve = geomObj as ModelCurve;
			
SketchPlane sk = modelcurve.SketchPlane;
IEnumerable<Level> levels = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast<Level>().Where( l => l.Name.Equals(sk.Name));
Level levelOfLine = levels.FirstOrDefault();
Please guide me.
0 Likes
Message 5 of 7

FAIR59
Advisor
Advisor

The GeometryObject is not needed.

 

you can get the modelcurve directly:

 

ModelCurve modelcurve = doc.GetElement(myRef) as ModelCurve;

Message 6 of 7

gprofile
Enthusiast
Enthusiast

I cannot understand why this code throws a null Exception, when I select a Line

 

UIDocument uiDoc = this.ActiveUIDocument;
			Document doc = uiDoc.Document;
			
			Reference myRef = uiDoc.Selection.PickObject(ObjectType.Element);
			Element e = doc.GetElement(myRef);
			ModelCurve modelcurve = e as ModelCurve;
			
			var viewPlan = (ViewPlan) doc.GetElement(modelcurve.OwnerViewId);
 			var level = (Level) doc.GetElement(viewPlan.LevelId);
 			
 			TaskDialog.Show("Level is : ",e.Name + level.Name);

 warning.png

 

 

 

 

 

0 Likes
Message 7 of 7

FAIR59
Advisor
Advisor

a room separation line is a model element, and as such it doesn't have a OwnerView. ( Only annotation elements have a Ownerview.)

so

modelcurve.OwnerViewId = ElementId.InvalidElementId, resulting in doc.GetElement(modelcurve.OwnerViewId) = null 

0 Likes