public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument UIdoc = commandData.Application.ActiveUIDocument; Document doc = UIdoc.Document; this.application = commandData.Application.Application; try { List <KeyValuePair <ViewSection, String> > newNames = new List <KeyValuePair <ViewSection, string> >(); List <ViewSection> intElevlist = InteriorElevations(doc); foreach (ViewSection ie in intElevlist) { List <Room> phasedRooms = RoomHelpers.GetPhasedRooms(doc, ie.CreatedPhaseId); Room r = GetElevRoom(ie, phasedRooms, doc); String ieNewName = RenameElevation(doc, ie, r); newNames.Add(new KeyValuePair <ViewSection, String>(ie, ieNewName)); } RenameElevationsDialog ieDialog = new RenameElevationsDialog(this.application, newNames); DialogResult dialogResult = ieDialog.ShowDialog(); if (dialogResult == DialogResult.OK) { using (Transaction tx = new Transaction(doc)) { tx.Start("Rename Elevations"); foreach (ViewSection ie in intElevlist) { String ieNewName = newNames.Find(kv => kv.Key.Id == ie.Id).Value; AssignName(ie, ieNewName); } tx.Commit(); } } else { return(Result.Cancelled); } } catch (Exception ex) { message = ex.ToString(); return(Result.Failed); } return(Result.Succeeded); }
public ElevationMarker PlaceMarker(Document doc, BoundingBoxXYZ wallbb, Wall w) { XYZ wallbbmin = wallbb.Min; XYZ wallbbmax = wallbb.Max; ViewPlan plan = DocumentElevPlanViews(doc); Parameter p = plan.get_Parameter(BuiltInParameter.VIEW_PHASE); //Debug("p equals " + p.AsElementId() + " phase called " + p.AsValueString()); ////Element planPhase = doc.GetElement(p.AsElementId()); ////Debug("planPhase equals " + planPhase); //List<Room> allRooms = RoomHelpers.GetAllRooms(doc); //foreach(Room room in allRooms) //{ // //Parameter roomPhase = room.get_Parameter(BuiltInParameter.VIEW_PHASE); // //Debug("Room Phase View Phase " + room.Name + " - " + roomPhase + " (" + roomPhase.AsValueString() + ")"); // Parameter roomPhase2 = room.get_Parameter(BuiltInParameter.PHASE_CREATED); // Debug("Room Phase Phase Created " + room.Name + " - " + roomPhase2.AsElementId().ToString() + " (" + roomPhase2.AsValueString() + ")"); // Parameter roomPhase3 = room.get_Parameter(BuiltInParameter.ROOM_PHASE); // Debug("Room Phase Room Phase " + room.Name + " - " + roomPhase3.AsElementId().ToString() + " (" + roomPhase3.AsValueString() + ")"); // //ElementId roomPhase1 = room.CreatedPhaseId; // //Debug("Room Phase 1 " + room.Name + " - " + roomPhase1 + " (" + roomPhase1.ToString() + ")"); //} //Debug("Wallbb min " + wallbbmin); //Debug("Wallbb max " + wallbbmax); //Debug("Plan phase Id " + p.AsElementId().ToString()); ////Debug("Plan phase Name " + planPhase.Name); XYZ wallCenter = new XYZ( (wallbbmax.X + wallbbmin.X) / 2, (wallbbmax.Y + wallbbmin.Y) / 2, wallbbmin.Z ); List <Room> phasedRooms = RoomHelpers.GetPhasedRooms(doc, p.AsElementId()); //Debug("Phase of wall " + w.CreatedPhaseId.ToString()); //Debug("Phase of wall name " + w.get_Parameter(BuiltInParameter.PHASE_CREATED).AsValueString()); XYZ wallCenterYTranslatedPositive = new XYZ( wallCenter.X, wallCenter.Y + 10, wallCenter.Z ); XYZ wallCenterYTranslatedNegative = new XYZ( wallCenter.X, wallCenter.Y - 10, wallCenter.Z ); XYZ wallCenterXTranslatedPositive = new XYZ( wallCenter.X + 10, wallCenter.Y, wallCenter.Z ); XYZ wallCenterXTranslatedNegative = new XYZ( wallCenter.X - 10, wallCenter.Y, wallCenter.Z ); //Debug("wall center " + wallCenter); //Debug("wallCenterYTranslatedPositive " + wallCenterYTranslatedPositive); //Debug("wallCenterYTranslatedNegative " + wallCenterYTranslatedNegative); //Debug("wallCenterXTranslatedPositive " + wallCenterXTranslatedPositive); //Debug("wallCenterXTranslatedNegative " + wallCenterXTranslatedNegative); XYZ markerLocation = wallCenter; Debug("markerLocation before the loops " + markerLocation); Debug("length of list phasedrooms " + phasedRooms.Count); if ((wallbbmax.X - wallbbmin.X) > (wallbbmax.Y - wallbbmin.Y)) { foreach (Room r in phasedRooms) { if (r.IsPointInRoom(wallCenterYTranslatedPositive)) { Debug("room name " + r.Name); Debug("is Y positive in room " + r.IsPointInRoom(wallCenterYTranslatedPositive)); markerLocation = wallCenterYTranslatedNegative; break; } else if (r.IsPointInRoom(wallCenterYTranslatedNegative)) { Debug("room name " + r.Name); Debug("is Y negative in room " + r.IsPointInRoom(wallCenterYTranslatedNegative)); markerLocation = wallCenterYTranslatedPositive; break; } } Debug("is Y check done"); } else { foreach (Room r in phasedRooms) { if (r.IsPointInRoom(wallCenterXTranslatedPositive)) { Debug("room name " + r.Name); Debug("is X positive in room " + r.IsPointInRoom(wallCenterXTranslatedPositive)); markerLocation = wallCenterXTranslatedNegative; break; } else if (r.IsPointInRoom(wallCenterXTranslatedNegative)) { Debug("room name " + r.Name); Debug("is X negative in room " + r.IsPointInRoom(wallCenterXTranslatedNegative)); markerLocation = wallCenterXTranslatedPositive; break; } } Debug("is X check done"); } Debug("selected marker location after loops " + markerLocation); //change scale to user input ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, FindFamilyTypeId(doc), markerLocation, 96); marker.get_Parameter(BuiltInParameter.PHASE_CREATED).Set(p.AsElementId()); if (marker.IsAvailableIndex(0)) { ViewSection extElev = marker.CreateElevation(doc, plan.Id, 0); extElev.get_Parameter(BuiltInParameter.VIEW_PHASE).Set(p.AsElementId()); } return(marker); }