Good morning,
We have a doubt with Revit API, we wanted to relate the floors with their sketch lines, it means, when we get the ID of the lines that make up the floor we want to know the relation that has with the ID of that floor.
How could we do this?
Thank you,
We are looking forward to your response.
Solved! Go to Solution.
Solved by FAIR59. Go to Solution.
Hi,
there is another thread about the relationship between an element and its sketch:
Revitalizer
Thank you so much. We have been checking this code but it has not been useful for us. We are not able to relate the sketch lines with the appropiate floor.
If anyone can help us, we would be very grateful.
Thank you so much
you can find the sketchlines with the TTT (temporary transaction trick)
StringBuilder sb = new StringBuilder(); Dictionary<Floor, List<ModelCurve>> dict_SketchLines = new Dictionary<Floor, List<ModelCurve>>(); Document doc = revit.Application.ActiveUIDocument.Document; List<Element> _floors = new FilteredElementCollector(doc) .OfClass(typeof(Floor)) .ToList(); foreach (Element e in _floors) { Floor f = e as Floor; List<ElementId> _deleted = null; using (Transaction t = new Transaction(doc, "temp")) { t.Start(); _deleted = doc.Delete(e.Id).ToList(); t.RollBack(); } bool SketchLinesFound = false; List<ModelCurve> _sketchCurves = new List<ModelCurve>(); foreach (var id in _deleted) { // find modelcurves. these are the lines in the bounderysketch ModelCurve mc = doc.GetElement(id) as ModelCurve; if (mc != null) { _sketchCurves.Add(mc); SketchLinesFound = true; } else { if (SketchLinesFound) break; } } dict_SketchLines.Add(f, _sketchCurves); } foreach (Floor key in dict_SketchLines.Keys) { List<ModelCurve> _curves = dict_SketchLines[key]; sb.AppendLine(string.Format("floor {0} has sketchlines:", key.Id)); foreach (ModelCurve mc in _curves) { sb.AppendLine(string.Format(" {0} <{1}>", mc.GetType(), mc.Id)); sb.AppendLine(string.Format(" <{0} -- {1}>", mc.GeometryCurve.GetEndPoint(0), mc.GeometryCurve.GetEndPoint(1))); } sb.AppendLine(); } TaskDialog.Show("debug", sb.ToString());
Thank you so much for your answer.
We are able to get the floor's ID and the sketch lines' ID. We want to know how do we relate those IDs with the floor ID.
Thank you and we are grateful for your answers.
there isn't a fixed relation between the ElementId of the floor and ElementId of the SketchLine.
If you need to find the floor from a SketchLine, then you'd have to fill your own Dictionary<Elementid of SketchLine, ElementId of Floor> in the second foreach -loop in my code.
Thank you so much for your answer.
We can already relate the ID of the floor's with the sketch lines' ID.