CollectEvent(object sender, CollectorEventArgs e) { // cast the sender object to the SnoopCollector we are expecting Collector snoopCollector = sender as Collector; if (snoopCollector == null) { Debug.Assert(false); // why did someone else send us the message? return; } BoundarySegment boundSeg = e.ObjToSnoop as BoundarySegment; if (boundSeg != null) { Stream(snoopCollector.Data(), boundSeg); return; } List <BoundarySegment> boundSegArray = e.ObjToSnoop as List <BoundarySegment>; if (boundSegArray != null) { Stream(snoopCollector.Data(), boundSegArray); return; } }
CollectEvent(object sender, CollectorEventArgs e) { // cast the sender object to the SnoopCollector we are expecting Collector snoopCollector = sender as Collector; if (snoopCollector == null) { Debug.Assert(false); // why did someone else send us the message? return; } BoundarySegment bndSeg = e.ObjToSnoop as BoundarySegment; if (bndSeg != null) { Stream(snoopCollector.Data(), bndSeg); return; } BoundarySegmentArray segArray = e.ObjToSnoop as BoundarySegmentArray; // NOTE: this is needed because BoundarySegmentArrayArray will display enumerable Snoop items if (segArray != null) { Stream(snoopCollector.Data(), segArray); return; } }
Stream(ArrayList data, BoundarySegment boundSeg) { data.Add(new Snoop.Data.ClassSeparator(typeof(BoundarySegment))); data.Add(new Snoop.Data.Object("Curve", boundSeg.GetCurve())); data.Add(new Snoop.Data.Object("Element", boundSeg.ElementId)); }
private Room getOtherRoom(Room r1, BoundarySegment seg, XYZ point) { // we already know what one of the rooms is attached to a boundary segment. // this attempts to find the other. Curve crv = seg.GetCurve(); XYZ vector = crv.GetEndPoint(1).Subtract(crv.GetEndPoint(0)).Normalize(); XYZ otherVector = XYZ.BasisZ; if (vector.IsAlmostEqualTo(XYZ.BasisZ)) { otherVector = XYZ.BasisY; } XYZ perp = vector.CrossProduct(otherVector).Normalize(); XYZ testp1 = point.Add(perp.Multiply(0.25)); XYZ testp2 = point.Add(perp.Negate().Multiply(0.25)); Parameter phaseParm = r1.get_Parameter(BuiltInParameter.ROOM_PHASE); Phase p = _doc.GetElement(phaseParm.AsElementId()) as Phase; Room roomP1 = _doc.GetRoomAtPoint(testp1, p); Room roomP2 = _doc.GetRoomAtPoint(testp2, p); if ((roomP1 != null) && (roomP1.Id != r1.Id)) { return(roomP1); } if ((roomP2 != null) && (roomP2.Id != r1.Id)) { return(roomP2); } return(null); }
/// <summary> /// Finds the angle of the longest bounrady segment of the first wall enclosing a room /// </summary> /// <param name="r">room used to find boundary</param> /// <returns>the angle in radians to rotate the elevation marker by</returns> public double AngletoRotateElev(Room r) { IList <IList <BoundarySegment> > segmentList = r.GetBoundarySegments(new SpatialElementBoundaryOptions()); IList <BoundarySegment> wallList = segmentList[0]; BoundarySegment segment = null; foreach (BoundarySegment wbs in wallList) { if (segment == null) { segment = wbs; } else if (wbs.GetCurve().Length > segment.GetCurve().Length) { segment = wbs; } } XYZ EP1 = segment.GetCurve().GetEndPoint(0); XYZ EP2 = segment.GetCurve().GetEndPoint(1); Debug("segment" + segment); Debug("EP1" + EP1); Debug("EP2" + EP2); double angleLineEP1EP2 = Math.Atan2((EP2.Y) - (EP1.Y), (EP2.X) - (EP1.X)); Debug("angleLineEP1EP2" + angleLineEP1EP2); return(angleLineEP1EP2); }
/// <summary> /// Appends a list of the room's near-corner points to a pre-existing list. /// </summary> /// <remarks> /// A near-corner point is offset from the room boundaries by 1.5 ft (18 inches). The points are calculated geometrically and some situations may not return /// all logical near-corner points, or may return points which are inside furniture, casework or other design elements. Only the first boundary region of the room is /// currently processed. /// </remarks> /// <param name="room"></param> /// <param name="nearCornerPoints"></param> /// <returns></returns> private static void AppendRoomNearCornerPoints(Room room, List <XYZ> nearCornerPoints) { IList <IList <BoundarySegment> > segments = room.GetBoundarySegments(new SpatialElementBoundaryOptions()); if (segments == null || segments.Count == 0) { return; } // First region only IList <BoundarySegment> firstSegments = segments[0]; int numSegments = firstSegments.Count; for (int i = 0; i < numSegments; i++) { BoundarySegment seg1 = firstSegments.ElementAt(i); BoundarySegment seg2 = firstSegments.ElementAt(i == numSegments - 1 ? 0 : i + 1); Curve curve1 = seg1.GetCurve(); Curve curve2 = seg2.GetCurve(); Curve offsetCurve1 = curve1.CreateOffset(-1.5, XYZ.BasisZ); Curve offsetCurve2 = curve2.CreateOffset(-1.5, XYZ.BasisZ); IntersectionResultArray intersections = null; SetComparisonResult result = offsetCurve1.Intersect(offsetCurve2, out intersections); // First intersection only if (result == SetComparisonResult.Overlap && intersections.Size == 1) { nearCornerPoints.Add(intersections.get_Item(0).XYZPoint); } } }
Stream(ArrayList data, BoundarySegment boundSeg) { data.Add(new Snoop.Data.ClassSeparator(typeof(BoundarySegment))); data.Add(new Snoop.Data.Object("Curve", boundSeg.GetCurve())); data.Add(new Snoop.Data.Object("ElementId", boundSeg.ElementId)); }
private void Stream(ArrayList data, BoundarySegment seg) { data.Add(new Snoop.Data.ClassSeparator(typeof(BoundarySegment))); data.Add(new Snoop.Data.Object("Curve", seg.Curve)); data.Add(new Snoop.Data.Object("Document", seg.Document)); data.Add(new Snoop.Data.Object("Element", seg.Element)); }
Stream(ArrayList data, BoundarySegment seg) { data.Add(new Snoop.Data.ClassSeparator(typeof(BoundarySegment))); data.Add(new Snoop.Data.Object("Curve", seg.Curve)); data.Add(new Snoop.Data.Object("Document", seg.Document)); data.Add(new Snoop.Data.Object("Element", seg.Element)); }
/// <summary> /// 获取墙段对应墙的材质 /// </summary> /// <param name="boundarySegment">墙段</param> /// <param name="document">文档</param> /// <returns></returns> public Material GetWallMaterial(BoundarySegment boundarySegment, Document document) { Material material = null; Wall wall = document.GetElement(boundarySegment.ElementId) as Wall; if (wall != null) { material = wall.Category.Material; } return(material); }
Room GetRoomNeighbourAt(BoundarySegment bs, Room r) { Document doc = r.Document; Element e = doc.GetElement(bs.ElementId); Wall w = e as Wall; double wallThickness = w.Width; double wallLength = (w.Location as LocationCurve).Curve.Length; Transform derivatives = bs.GetCurve() .ComputeDerivatives(0.5, true); XYZ midPoint = derivatives.Origin; Debug.Assert( midPoint.IsAlmostEqualTo( bs.GetCurve().Evaluate(0.5, true)), "expected same result from Evaluate and derivatives"); XYZ tangent = derivatives.BasisX.Normalize(); XYZ normal = new XYZ(tangent.Y, tangent.X * (-1), tangent.Z); XYZ p = midPoint + wallThickness * normal; Room otherRoom = doc.GetRoomAtPoint(p); if (null != otherRoom) { if (otherRoom.Id == r.Id) { normal = new XYZ(tangent.Y * (-1), tangent.X, tangent.Z); p = midPoint + wallThickness * normal; otherRoom = doc.GetRoomAtPoint(p); Debug.Assert(null == otherRoom || otherRoom.Id != r.Id, "expected different room on other side"); } } return(otherRoom); }
private void fetchSegmentElemInfo(RoomObject obj, BoundarySegment seg, Level refLevel, Segment target) { Curve crv = seg.GetCurve(); target.Curve = crv; target.Length = crv.ApproximateLength; target.MidPoint = crv.Evaluate(0.5, true); Element e = obj.Document.GetElement(seg.ElementId); if (e is RevitLinkInstance) { RevitLinkInstance inst = e as RevitLinkInstance; Document doc = inst.GetLinkDocument(); e = null; if (doc != null) { e = doc.GetElement(seg.LinkElementId); } } if (e == null) { target.ElementType = "UNKNOWN!?"; target.Thickness = 0; return; } target.ElementType = e.Category.Name; if (e is Wall) { Wall w = e as Wall; target.Thickness = w.WallType.Width; target.IsExterior = (w.WallType.Function == WallFunction.Exterior); target.WallKind = w.WallType.Kind; } else { target.Thickness = 0; } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet) { Document doc = commandData.Application.ActiveUIDocument.Document; List <string> liste = new List <string>(); Form1 form = new Form1(doc); bool RoomName = false; bool RoomWalls = false; bool RoomFurniture = false; bool RoomDoors = false; bool RoomAddFurniture = false; bool RoomFinishes = false; if (form.DialogResult == System.Windows.Forms.DialogResult.Cancel) { return(Result.Cancelled); } if (DialogResult.OK == form.ShowDialog()) { //Nom du paramètre de type "oui/non" permettant de détecter les locaux confidentiels string param = "G6_Confidentiel"; //Nom des éléments pour le remplacement des familles string wall_type = "XXXX"; string door_type = "XXXX_P:XXXX"; string furniture_type = "XXXX_M:XXXX"; string plumbing_type = "XXXX_S:XXXX"; string furniture_param = "Dimension"; string plumbing_param = "Dimension"; //Valeur attribuée aux paramètres cryptés string change = "XXXX"; //Clé de décryptage List <string> key = new List <string>(); string phase = "Nouvelle construction"; string phase2 = "New Construction"; ElementId levelID = null; FamilySymbol door_fs = null; FamilySymbol furniture_fs = null; FamilySymbol plumbing_fs = null; ElementId eid = null; Line newWallLine_2 = null; List <Curve> curves = new List <Curve>(); int count = 0; Random rnd = new Random(); int Offset = rnd.Next(4, 6); double random = rnd.NextDouble() * Offset; //double random = Offset; using (Transaction t = new Transaction(doc, "Crypter la maquette")) { t.Start(); RoomName = form.RoomName(); RoomWalls = form.RoomWalls(); RoomFurniture = form.RoomFurniture(); RoomDoors = form.RoomDoors(); RoomAddFurniture = form.RoomAddFurnitures(); RoomFinishes = form.RoomFinishes(); //Sélection du type de porte de remplacement FamilySymbol fs = (from element in new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_Doors).Cast <FamilySymbol>() where element.Family.Name + ":" + element.Name == door_type select element).ToList <FamilySymbol>().First(); door_fs = fs; //Sélection du type de mobilier de remplacement FamilySymbol fs_furniture = (from element in new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_Furniture).Cast <FamilySymbol>() where element.Family.Name + ":" + element.Name == furniture_type select element).ToList <FamilySymbol>().First(); furniture_fs = fs_furniture; //Sélection du type de sanitaire de remplacement FamilySymbol fs_plumbing = (from element in new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_PlumbingFixtures).Cast <FamilySymbol>() where element.Family.Name + ":" + element.Name == plumbing_type select element).ToList <FamilySymbol>().First(); plumbing_fs = fs_plumbing; //Sélection du type de mur de remplacement WallType walltype = (from element in new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType() where element.Name == wall_type select element).Cast <WallType>().ToList <WallType>().First(); eid = walltype.Id; //Remplacement du mobilier if (RoomFurniture == true) { foreach (FamilyInstance furniture_instance in new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Furniture).Cast <FamilyInstance>()) { if (furniture_instance.Room != null && furniture_instance.Room.LookupParameter(param).AsInteger() == 1) { try { string original = furniture_instance.Name; furniture_instance.Symbol = furniture_fs; Random rd = new Random(); double random_dimension = 0.5 + rd.NextDouble(); furniture_instance.LookupParameter(furniture_param).Set(UnitUtils.ConvertToInternalUnits(random_dimension, DisplayUnitType.DUT_METERS)); key.Add("F;" + furniture_instance.Id.ToString() + ";" + original + ";" + furniture_instance.Room.Id.ToString() + ";" + furniture_instance.Room.Name); } catch { } } } foreach (FamilyInstance plumbing_instance in new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_PlumbingFixtures).Cast <FamilyInstance>()) { if (plumbing_instance.Room != null && plumbing_instance.Room.LookupParameter(param).AsInteger() == 1) { string original = plumbing_instance.Name; plumbing_instance.Symbol = plumbing_fs; Random rd = new Random(); double random_dimension = 0.5 + rd.NextDouble(); plumbing_instance.LookupParameter(plumbing_param).Set(UnitUtils.ConvertToInternalUnits(random_dimension, DisplayUnitType.DUT_METERS)); key.Add("P;" + plumbing_instance.Id.ToString() + ";" + original + ";" + plumbing_instance.Room.Id.ToString() + ";" + plumbing_instance.Room.Name); } } } //Lister les pièces confidentielles et appartenant à la phase désignée List <Room> rooms = (from element in new FilteredElementCollector(doc).OfClass(typeof(SpatialElement)).OfCategory(BuiltInCategory.OST_Rooms).Cast <Room>() where element.LookupParameter(param).AsInteger() == 1 && (element.get_Parameter(BuiltInParameter.ROOM_PHASE).AsValueString() == phase || element.get_Parameter(BuiltInParameter.ROOM_PHASE).AsValueString() == phase2) select element).ToList <Room>(); //Première boucle sur les pièces confidentielles pour renseigner la clé foreach (Room r in rooms) { Parameter name = r.get_Parameter(BuiltInParameter.ROOM_NAME); Parameter number = r.get_Parameter(BuiltInParameter.ROOM_NUMBER); Parameter floor = r.get_Parameter(BuiltInParameter.ROOM_FINISH_FLOOR); LocationPoint lp = r.Location as LocationPoint; XYZ point = lp.Point; //Ajout des valeurs de paramètres initiaux à la clé de déchiffrement key.Add("R;" + r.Id.ToString() + ";" + name.AsString() + ";" + number.AsString() + ";" + floor.AsString() + ";" + point.X + ";" + point.Y + ";" + point.Z); } //Deuxième boucle sur les pièces confidentielles pour modifier paramètres et géométrie foreach (Room r in rooms) { Parameter name = r.get_Parameter(BuiltInParameter.ROOM_NAME); Parameter number = r.get_Parameter(BuiltInParameter.ROOM_NUMBER); Parameter floor = r.get_Parameter(BuiltInParameter.ROOM_FINISH_FLOOR); LocationPoint lp = r.Location as LocationPoint; XYZ point = lp.Point; //Remplacement des valeurs de paramètres des pièces par le code if (RoomName == true) { name.Set(change); number.Set(change + count.ToString()); } if (RoomFinishes == true) { floor.Set(change); } //Incrémentation du nombre de pièces cryptées count += 1; //Retrouver les limites des pièces IList <IList <Autodesk.Revit.DB.BoundarySegment> > segments = r.GetBoundarySegments(new SpatialElementBoundaryOptions()); int segments_number = 0; int boundaries_number = 0; BoundarySegment bd0 = null; BoundarySegment bd1 = null; BoundarySegment bd2 = null; if (null != segments) //la pièce peut ne pas être fermée { foreach (IList <Autodesk.Revit.DB.BoundarySegment> segmentList in segments) { segments_number += 1; foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in segmentList) { boundaries_number += 1; if (boundaries_number == 1) { bd0 = boundarySegment; } if (boundaries_number == 3) { bd1 = boundarySegment; } if (boundaries_number == 4) { bd2 = boundarySegment; } //Retrouver l'élément qui forme la limite de pièce Element elt = r.Document.GetElement(boundarySegment.ElementId); //Déterminer si cet élément est un mur bool isWall = false; if (elt as Wall != null) { isWall = true; } //Si c'est un mur, continuer if (isWall == true) { Wall wall = elt as Wall; Parameter function = wall.WallType.get_Parameter(BuiltInParameter.FUNCTION_PARAM); //Ne traiter que les murs intérieurs if (function.AsValueString() == "Interior" || function.AsValueString() == "Intérieur") { if (RoomDoors == true) { //Changer les types de portes IList <ElementId> inserts = (wall as HostObject).FindInserts(true, true, true, true); foreach (ElementId id in inserts) { Element e = doc.GetElement(id); try { FamilyInstance fi = e as FamilyInstance; if (fi.get_Parameter(BuiltInParameter.PHASE_CREATED).AsValueString() == phase || fi.get_Parameter(BuiltInParameter.PHASE_CREATED).AsValueString() == phase2) { string original = fi.Name; fi.Symbol = door_fs; LocationPoint doorPoint = fi.Location as LocationPoint; XYZ pt = doorPoint.Point; key.Add("D;" + fi.Id.ToString() + ";" + original + ";" + pt.X + ";" + pt.Y + ";" + pt.Z); } } catch { } } } //Récupérer les points de départ et d'extrémité des murs LocationCurve wallLine = wall.Location as LocationCurve; XYZ endPoint0 = wallLine.Curve.GetEndPoint(0); XYZ endPoint1 = wallLine.Curve.GetEndPoint(1); //Ajout des coordonnées initiales des murs à la clé de déchiffrement key.Add("W;" + wall.Id.ToString() + ";" + wall.WallType.Name + ";" + endPoint0.X.ToString() + ";" + endPoint0.Y.ToString() + ";" + endPoint1.X.ToString() + ";" + endPoint1.Y.ToString()); levelID = wall.LevelId; //Changer le type des murs if (RoomWalls == true) { wall.ChangeTypeId(eid); } } } } } if (RoomAddFurniture == true && r.Area > UnitUtils.ConvertToInternalUnits(7, DisplayUnitType.DUT_SQUARE_METERS)) { //Créer de nouveaux meubles de façon aléatoire dans les pièces confidentielles Random rd = new Random(); int offset = rnd.Next(0, 10); XYZ new_point = new XYZ(point.X + offset * 0.5, point.Y + offset * 0.3, point.Z); if (offset > 1 && offset < 9) { FamilyInstance nf = doc.Create.NewFamilyInstance(new_point, furniture_fs, r.Level, StructuralType.NonStructural); key.Add("NF;" + nf.Id.ToString()); } } } } SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Title = "Choisir le chemin du fichier de chiffrement"; saveFileDialog1.Filter = "Fichier texte (*.txt)|*.txt"; saveFileDialog1.RestoreDirectory = true; DialogResult result = saveFileDialog1.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { string txt_filename = saveFileDialog1.FileName; if (File.Exists(txt_filename)) { File.Delete(txt_filename); } //Ecrire dans le fichier clé using (StreamWriter sw = new StreamWriter(txt_filename)) { foreach (string s in key) { sw.WriteLine(s); } } //Process.Start(txt_filename); } t.Commit(); return(Result.Succeeded); } } return(Result.Succeeded); }
/// <summary> /// 根据BoundarySegment获取与房间交界的墙 /// </summary> /// <param name="boundarySegment">墙段</param> /// <param name="document">文档</param> /// <returns></returns> public Wall GetWall(BoundarySegment boundarySegment, Document document) { return(document.GetElement(boundarySegment.ElementId) as Wall); }
/// <summary> /// 根据BoundarySegment获取与房间交界的墙段的长度 /// </summary> /// <param name="boundarySegment">墙段</param> /// <returns></returns> public double GetWallLength(BoundarySegment boundarySegment) { return(boundarySegment.GetCurve().Length); }
public static Curve GetSegmentCurve(this BoundarySegment s) { return(s.GetCurve()); }
public MyBoundarySegment(BoundarySegment b) { Curve = b.GetCurve(); ElementId = b.ElementId; }