/// <summary> /// 为选中房间创建专门的floorPlan和ceilingPlan /// Ctrate a New FloorPlan and CeilingPlan for the selected selRoom /// </summary> /// <param name="viewOffseet"></param> /// <param name="view3d"></param> public void CreateNewViewPlan(double viewOffseet, View3D view3d) { //过滤所有的ViewFamilyType var classFilter = new ElementClassFilter(typeof(ViewFamilyType)); FilteredElementCollector collector = new FilteredElementCollector(DocSet.doc); collector = collector.WherePasses(classFilter); ViewPlan view = null; using (Transaction tran = new Transaction(DocSet.doc)) { foreach (ViewFamilyType viewFamilyType in collector) { //当类型为FloorPlan或者CeilingPlan时创建同类型视图 if (viewFamilyType.ViewFamily == ViewFamily.FloorPlan || viewFamilyType.ViewFamily == ViewFamily.CeilingPlan) { tran.Start("Creat view of type " + viewFamilyType.ViewFamily); //创建视图时需要 视图类型ID 相关标高ID view = ViewPlan.Create(DocSet.doc, viewFamilyType.Id, DocSet.selRoom.LevelId); //TaskDialog.Show("CreatLevelView", "A new level's view has been Created"); view.Name = DocSet.selRoom.Name;//生成平面的名称 view.get_Parameter(BuiltInParameter.VIEWER_CROP_REGION).Set(1); view.AreAnalyticalModelCategoriesHidden = false; view.PartsVisibility = PartsVisibility.ShowPartsAndOriginal; view.Scale = 50; view.CropBoxActive = true; view.CropBoxVisible = true; string viewName = "PLAN "; view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set(DocSet.selRoom.Name); if (viewFamilyType.ViewFamily == ViewFamily.CeilingPlan) { PlanViewRange range = view.GetViewRange(); range.SetLevelId(PlanViewPlane.TopClipPlane, DocSet.selRoom.UpperLimit.Id); range.SetLevelId(PlanViewPlane.ViewDepthPlane, DocSet.selRoom.UpperLimit.Id); range.SetLevelId(PlanViewPlane.CutPlane, DocSet.selRoom.LevelId); range.SetLevelId(PlanViewPlane.BottomClipPlane, DocSet.selRoom.LevelId); range.SetOffset(PlanViewPlane.CutPlane, 7.874); range.SetOffset(PlanViewPlane.BottomClipPlane, 7.874); view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set(DocSet.selRoom.Name); view.SetViewRange(range); viewName = "RCP "; view.get_Parameter(BuiltInParameter.VIEW_DESCRIPTION).Set(DocSet.selRoom.Name + " - RCP"); } viewName += _SoANumber + "_" + DocSet.selRoom.Level.Name; view.ViewName = viewName; tran.Commit(); ChangeViewFitRoom(view, tran, viewOffseet); } } } }
public ViewPlan CreateViewPlan(int scale, string viewName) { Document _doc = Level?.Document; if (_doc == null) { return(null); } ViewPlan _viewPlan = ViewPlan.Create(_doc, _floorPlanViewFamilyType.Id, Level.Id); if (ScopeBox != null) { _viewPlan.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP)?.Set(ScopeBox.Id); } else if (ScopeBox == null && Bounds != null) { _viewPlan.CropBoxActive = true; _viewPlan.CropBox = Bounds; } if (string.IsNullOrWhiteSpace(viewName) == false) { _viewPlan.Name = viewName; } _viewPlan.Scale = scale; return(_viewPlan); }
public static ViewPlan CreatePhaseFloorPlan(Document doc, ItemInfo itemInfo, ViewFamilyType viewPlanFamilyType, Level planLevel, bool overwrite) { ViewPlan viewPlan = null; try { string viewName = planLevel.Name + " - " + itemInfo.ItemName; using (Transaction trans = new Transaction(doc)) { try { FilteredElementCollector collector = new FilteredElementCollector(doc); List <ViewPlan> viewPlans = collector.OfClass(typeof(ViewPlan)).ToElements().Cast <ViewPlan>().ToList(); var views = from view in viewPlans where view.Name == viewName select view; if (views.Count() > 0) { if (overwrite) { viewPlan = views.First(); } else { return(viewPlan); } } if (null == viewPlan) { trans.Start("Create Plan View"); viewPlan = ViewPlan.Create(doc, viewPlanFamilyType.Id, planLevel.Id); viewPlan.Name = viewName; Parameter param = viewPlan.get_Parameter(BuiltInParameter.VIEW_PHASE); if (null != param) { if (!param.IsReadOnly) { param.Set(itemInfo.ItemId); } } trans.Commit(); } } catch (Exception ex) { trans.RollBack(); MessageBox.Show("Failed to create a plan view for the phase, " + itemInfo.ItemName + "\n" + ex.Message, "Create Plan View", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception ex) { MessageBox.Show("Failed to create floor plans by phases.\n" + ex.Message, "Create Floor Plans by Phases", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(viewPlan); }
/// <summary> /// Finds the id of the first available level associated with this plan view. /// </summary> /// <param name="view"></param> /// <returns>InvalidElementId if no associated level is found.</returns> /// <seealso cref="Autodesk.Revit.DB.Level.FindAssociatedPlanViewId"/> public static ElementId FindAssociatedLevelId(this ViewPlan view) { if (view.get_Parameter(BuiltInParameter.PLAN_VIEW_LEVEL)?.AsString() is string levelName) { using (var collector = new FilteredElementCollector(view.Document)) { return(collector.OfClass(typeof(Level)). WhereParameterEqualsTo(BuiltInParameter.DATUM_TEXT, levelName). FirstElementId()); } } return(ElementId.InvalidElementId); }
private void Create2DForm_Load(object sender, EventArgs e) { floorPlans = new FloorPlans(m_rvtDoc); var views = floorPlans.floorPlans; for (int i = 0; i < views.Count(); i++) { ViewPlan view = views[i]; Parameter param = view.get_Parameter(BuiltInParameter.VIEW_DEPENDENCY); if (param.AsString() == "Primary" || param.AsString() == "Independent") { selectFloorPlan.Items.Add(view.Name.ToString()); } } }
public void PlaceElevations(Document doc, XYZ center, ViewPlan intElevPlan) { //current scale set to 1/8" ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, FindFamilyTypeId(doc), center, 96); Parameter p = intElevPlan.get_Parameter(BuiltInParameter.VIEW_PHASE); marker.get_Parameter(BuiltInParameter.PHASE_CREATED).Set(p.AsElementId()); for (int markerindex = 0; markerindex < marker.MaximumViewCount; markerindex++) { Debug($"Writing marker at {markerindex}"); if (marker.IsAvailableIndex(markerindex)) { Debug($"Writing market to plan {intElevPlan.Name}"); ViewSection intElev = marker.CreateElevation(doc, intElevPlan.Id, markerindex); intElev.get_Parameter(BuiltInParameter.VIEW_PHASE).Set(p.AsElementId()); } } }
/// <summary> /// Places interior elevation makers and inter elevation views for the room /// </summary> /// <param name="doc">UI Document</param> /// <param name="center">coordinate where marker will be placed</param> /// <param name="intElevPlan">the plan in which the marker will be visible</param> /// <param name="selectedFamilyType">user selected view family type</param> /// <param name="scale">user selected scale for interior elevations</param> /// <returns>a list of the interior elevations created</returns> public List <ViewSection> PlaceElevations(Document doc, XYZ center, ViewPlan intElevPlan, ElementId selectedFamilyType, int scale, out ElevationMarker marker) { marker = ElevationMarker.CreateElevationMarker(doc, selectedFamilyType, center, scale); Parameter p = intElevPlan.get_Parameter(BuiltInParameter.VIEW_PHASE); marker.get_Parameter(BuiltInParameter.PHASE_CREATED).Set(p.AsElementId()); List <ViewSection> intElevList = new List <ViewSection>(); for (int markerindex = 0; markerindex < marker.MaximumViewCount; markerindex++) { if (marker.IsAvailableIndex(markerindex)) { ViewSection intElev = marker.CreateElevation(doc, intElevPlan.Id, markerindex); intElev.get_Parameter(BuiltInParameter.VIEW_PHASE).Set(p.AsElementId()); intElevList.Add(intElev); } } return(intElevList); }
public ElevationMarker PlaceMarker(Document doc, XYZ elevMarkerPosition, Wall w) { ViewPlan plan = DocumentElevPlanViews(doc, w); Parameter p = plan.get_Parameter(BuiltInParameter.VIEW_PHASE); //ElementId[] toHide = new ElementId[1]; //change scale to user input ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, FindFamilyTypeId(doc), elevMarkerPosition, 96); marker.get_Parameter(BuiltInParameter.PHASE_CREATED).Set(p.AsElementId()); //toHide[0] = marker.Id; //move this back into the if statement when code works if (marker.IsAvailableIndex(0)) { ViewSection extElev = marker.CreateElevation(doc, plan.Id, 0); extElev.get_Parameter(BuiltInParameter.VIEW_PHASE).Set(p.AsElementId()); } return(marker); }
public List <ViewSection> PlaceElevations(Document doc, XYZ center, ViewPlan intElevPlan) { //add pop up to input scale //current scale set to 1/8" ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, FindFamilyTypeId(doc), center, 96); Parameter p = intElevPlan.get_Parameter(BuiltInParameter.VIEW_PHASE); marker.get_Parameter(BuiltInParameter.PHASE_CREATED).Set(p.AsElementId()); List <ViewSection> intElevList = new List <ViewSection>(); for (int markerindex = 0; markerindex < marker.MaximumViewCount; markerindex++) { if (marker.IsAvailableIndex(markerindex)) { ViewSection intElev = marker.CreateElevation(doc, intElevPlan.Id, markerindex); intElev.get_Parameter(BuiltInParameter.VIEW_PHASE).Set(p.AsElementId()); intElevList.Add(intElev); } } return(intElevList); }
public ViewPlan CreateViewPlan(int scale) { Document _doc = Level?.Document; if (_doc == null) { return(null); } ViewPlan _viewPlan = ViewPlan.Create(_doc, _floorPlanViewFamilyType.Id, Level.Id); _viewPlan.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP)?.Set(ScopeBox.Id); string _viewName = GetViewName("FloorPlan"); if (string.IsNullOrWhiteSpace(_viewName) == false) { _viewPlan.Name = _viewName; } _viewPlan.Scale = scale; return(_viewPlan); }
public static void CreateViews(Document curDoc, string viewType, string viewFamilyType, string viewTemplate, string scopeBox, string designOpt, List <Level> m_levels) { //creates plan or RCP views for each floor level in the supplied model //set view type ViewFamily viewTypeSetting = default(ViewFamily); if (viewType == "CeilingPlan") { viewTypeSetting = ViewFamily.CeilingPlan; } else if (viewType == "AreaPlan") { viewTypeSetting = ViewFamily.AreaPlan; } else if (viewType == "StructuralPlan") { viewTypeSetting = ViewFamily.StructuralPlan; } else { viewTypeSetting = ViewFamily.FloorPlan; } //get list of view types List <ViewFamilyType> m_vt = new List <ViewFamilyType>(); m_vt = mFunctions.getViewTypes(curDoc); //success and error list List <string> m_s = new List <string>(); List <string> m_e = new List <string>(); //new transaction using (Transaction t = new Transaction(curDoc, "Create views")) { //start transaction if (t.Start() == TransactionStatus.Started) { //create a plan or RCP for specified levels foreach (Level lev in m_levels) { //views for plan only foreach (ViewFamilyType vt in m_vt) { if (vt.Name == viewFamilyType) { try { //create the plan view ViewPlan m_fp = null; m_fp = ViewPlan.Create(curDoc, vt.Id, lev.Id); //rename the view m_fp.Name = lev.Name.ToUpper() + " " + vt.Name.ToUpper(); m_s.Add(lev.Name.ToUpper() + " " + vt.Name.ToUpper()); //modify the view as needed //----------------------------------------------------- //add view template to view if (viewTemplate != "None") { m_fp.ViewTemplateId = mFunctions.getViewTemplateID(viewTemplate, curDoc); } //add scope box to view if (scopeBox != "None") { Parameter curParam = null; curParam = m_fp.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP); if (curParam.Definition.Name.ToString() == "Scope Box") { //check if scope box exist if (mFunctions.doesScopeBoxExist(scopeBox, curDoc)) { try { //set scope box value curParam.Set(mFunctions.getScopeBoxID(scopeBox, curDoc)); } catch (Exception ex) { Debug.Print(ex.Message); } } else { Debug.Print("SCOPE BOX DOESN'T EXIST"); } } } //add design option to view if (designOpt != "None") { //assign selected design option to view DesignOption curDesignOption = mFunctions.getDesignOptionByName(curDoc, designOpt); Parameter desOptParam = m_fp.get_Parameter(BuiltInParameter.VIEWER_OPTION_VISIBILITY); try { desOptParam.Set(curDesignOption.Id); } catch (Exception ex) { TaskDialog.Show("error", "could not set design option paramerter"); } } } catch (Exception ex) { m_e.Add(ex.Message + ": " + lev.Name.ToUpper() + " " + vt.Name.ToUpper()); } } } } //report views created if (m_s.Count > 0) { using (TaskDialog m_td = new TaskDialog("Success")) { m_td.MainInstruction = "Created views:"; foreach (string x_loopVariable in m_s) { m_td.MainContent += x_loopVariable + Constants.vbCr; } m_td.Show(); } } //report errors if any if (m_e.Count > 0) { using (TaskDialog m_td = new TaskDialog("Errors")) { m_td.MainInstruction = "Issues with views:"; foreach (string x_loopVariable in m_e) { m_td.MainContent += x_loopVariable + Constants.vbCr; } m_td.Show(); } } //commit t.Commit(); } } }
/// <summary> /// Main function to create all views /// </summary> /// <param name="doc"></param> /// <returns></returns> private bool makeViews(Document doc) { // Get all View Type Families for Floor Plans IEnumerable <Element> viewFTypesFP = from e in new FilteredElementCollector(_doc).OfClass(typeof(ViewFamilyType)) let type = e as ViewFamilyType where type.ViewFamily == ViewFamily.FloorPlan select type; // Get all View Type Families for Floor Plans IEnumerable <Element> viewFTypesCP = from e in new FilteredElementCollector(_doc).OfClass(typeof(ViewFamilyType)) let type = e as ViewFamilyType where type.ViewFamily == ViewFamily.CeilingPlan select type; // Failures and Success string m_fails = ""; string m_sucess = ""; // Check that atleast on level is checked if (this.checkedListBox1.CheckedItems.Count == 0) { MessageBox.Show("Please choose at least one Level to create a view.", "Hold On Silly..."); return(false); } else { // Loop through each item checked foreach (Object obj in this.checkedListBox1.CheckedItems) { // Step Progress this.progressBar1.Increment(1); System.Windows.Forms.Application.DoEvents(); // Get the level Level level = obj as Level; string viewdiscipline = this.cbViewDiscipline.SelectedValue.ToString(); string viewtype = this.cbViewType.SelectedValue.ToString(); string viewtypename = this.cbViewType.SelectedValue.ToString(); string subdiscipline = this.textSubDiscipline.Text; string viewname = ""; if (app.myProduct == "MEP") { viewname = subdiscipline + " " + level.Name + " " + viewtypename; } else { viewname = viewdiscipline + " " + level.Name + " " + viewtypename; } viewname = viewname.ToUpper(); // Check that sub-discipline box has been filled if (app.myProduct == "MEP" && subdiscipline.Trim() == "") { MessageBox.Show("Sub-Discipline can not be blank.", "Hold On ..."); return(false); } else { // Start Transaction Transaction t = new Transaction(doc, "Create " + viewdiscipline + " " + level.Name + " " + viewtype); t.Start(); // View Name (for errors) string m_viewName = viewdiscipline + " " + level.Name + " " + viewtype; try { // Chcek viewtype if (viewtype == "Floor Plan") { // Create the view ViewPlan viewplan = ViewPlan.Create(_doc, viewFTypesFP.First().Id, level.Id); // Set the discipline based on combobox selection if (viewdiscipline == "Architectural") { viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(1); } else if (viewdiscipline == "Structural") { viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(2); } else if (viewdiscipline == "Mechanical") { viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(4); } else if (viewdiscipline == "Electrical") { viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(8); } else if (viewdiscipline == "Coordination") { viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(4095); } else { MessageBox.Show("Invalid Discipline", "Error"); break; } if (app.myProduct == "MEP") { // Set Sub-Discipline based on text box entry clsParameterData.GetParameterByName(viewplan, "Sub-Discipline").Set(subdiscipline); } } else { // Check viewtype ViewPlan viewplan = ViewPlan.Create(_doc, viewFTypesCP.First().Id, level.Id); // Set the discipline based on combobox selection if (viewdiscipline == "Architectural") { viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(1); } else if (viewdiscipline == "Structural") { viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(2); } else if (viewdiscipline == "Mechanical") { viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(4); } else if (viewdiscipline == "Electrical") { viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(8); } else if (viewdiscipline == "Coordination") { viewplan.get_Parameter(BuiltInParameter.VIEW_DISCIPLINE).Set(4095); } else { MessageBox.Show("Invalid Discipline", "Error"); break; } if (app.myProduct == "MEP") { // Set the discipline based on combobox selection clsParameterData.GetParameterByName(viewplan, "Sub-Discipline").Set(subdiscipline); } } // Commit m_sucess += "\n" + m_viewName.ToUpper(); t.Commit(); } catch { // Rollback on Failure t.RollBack(); m_fails += "\n" + m_viewName.ToUpper(); // return false; } } } } // Report to the user TaskDialog m_td = new TaskDialog("Here's What Happend:"); m_td.MainContent = "Successful Views:" + m_sucess + "\n\nFailed Views:" + m_fails; m_td.MainInstruction = "Created Some Views... or Not:"; m_td.Show(); return(true); }
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); }
public static List <ViewPlan> DuplicateViewPlan(this ViewPlan viewPlan, IEnumerable <Level> levels = null, bool useExisting = false) { if (viewPlan == null || !viewPlan.IsValidObject || viewPlan.IsTemplate) { return(null); } Document document = viewPlan.Document; if (document == null) { return(null); } List <Level> levels_Temp = null; if (levels != null) { levels_Temp = new List <Level>(levels); } if (levels_Temp == null) { levels_Temp = new FilteredElementCollector(document).OfClass(typeof(Level)).Cast <Level>().ToList(); } List <Element> elements_ColorFillLegend = new FilteredElementCollector(document, viewPlan.Id).OfCategory(BuiltInCategory.OST_ColorFillLegends).ToList(); List <ViewPlan> result = new List <ViewPlan>(); foreach (Level level in levels_Temp) { if (level.Id == viewPlan.GenLevel.Id) { continue; } ViewPlan viewPlan_New = null; List <ViewPlan> viewPlans = new FilteredElementCollector(document).OfClass(typeof(ViewPlan)).Cast <ViewPlan>().ToList(); string name = level.Name; if (useExisting) { viewPlan_New = viewPlans.Find(x => x.Name == name); } if (viewPlan_New == null) { viewPlan_New = ViewPlan.Create(document, viewPlan.GetTypeId(), level.Id); // Check name uniqueness string name_Temp = name; int count = 0; while (viewPlans.Find(x => x.Name == name_Temp) != null) { count++; name_Temp = string.Format("{0} {1}", name, count); } viewPlan_New.Name = name_Temp; } foreach (Parameter parameter in viewPlan.ParametersMap) { if (parameter.Id.IntegerValue == (int)BuiltInParameter.VIEW_NAME) { continue; } Definition definition = parameter?.Definition; if (definition == null) { continue; } Parameter parameter_New = viewPlan_New.get_Parameter(parameter.Definition); if (parameter_New == null) { continue; } CopyValue(parameter, parameter_New); } if (elements_ColorFillLegend != null && elements_ColorFillLegend.Count != 0) { ElementTransformUtils.CopyElements(viewPlan, elements_ColorFillLegend.ConvertAll(x => x.Id), viewPlan_New, null, new CopyPasteOptions()); } result.Add(viewPlan_New); IEnumerable <ElementId> elementIds_Dependent = viewPlan.GetDependentViewIds(); if (elementIds_Dependent != null && elementIds_Dependent.Count() != 0) { foreach (ElementId elementId_Dependent in elementIds_Dependent) { ViewPlan viewPlan_Dependent = document.GetElement(elementId_Dependent) as ViewPlan; if (viewPlan_Dependent == null) { continue; } viewPlans = new FilteredElementCollector(document).OfClass(typeof(ViewPlan)).Cast <ViewPlan>().ToList(); string name_Dependent = name; if (viewPlan_Dependent.Name.StartsWith(viewPlan.Name)) { name_Dependent = level.Name + viewPlan_Dependent.Name.Substring(viewPlan.Name.Length); } else { Element scopeBox = viewPlan_Dependent.ScopeBox(); if (scopeBox != null) { name_Dependent = level.Name + " - " + scopeBox.Name; } } ViewPlan viewPlan_Dependent_New = null; if (useExisting) { viewPlan_Dependent_New = viewPlans.Find(x => x.Name == name_Dependent); } if (viewPlan_Dependent_New == null) { ElementId elementId_Dependent_New = viewPlan_New.Duplicate(ViewDuplicateOption.AsDependent); if (elementId_Dependent_New == null || elementId_Dependent_New == ElementId.InvalidElementId) { continue; } viewPlan_Dependent_New = document.GetElement(elementId_Dependent_New) as ViewPlan; if (viewPlan_Dependent_New == null) { continue; } // Check name uniqueness string name_Dependent_Temp = name_Dependent; int count = 0; while (viewPlans.Find(x => x.Name == name_Dependent_Temp) != null) { count++; name_Dependent_Temp = string.Format("{0} {1}", name_Dependent, count); } viewPlan_Dependent_New.Name = name_Dependent_Temp; } foreach (Parameter parameter in viewPlan_Dependent.ParametersMap) { if (parameter.Id.IntegerValue == (int)BuiltInParameter.VIEW_NAME) { continue; } Definition definition = parameter?.Definition; if (definition == null) { continue; } Parameter parameter_New = viewPlan_Dependent_New.get_Parameter(parameter.Definition); if (parameter_New == null) { continue; } CopyValue(parameter, parameter_New); } result.Add(viewPlan_Dependent_New); } } } return(result); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { _uiapp = commandData.Application; _uidoc = _uiapp.ActiveUIDocument; _doc = _uidoc.Document; try { // Get list of all structural levels IList <Level> strLevels = GetAllLevels(_doc, true, true); if (strLevels.Count == 0) { return(Result.Cancelled); } // Get list of all zone de définition IList <Element> zoneList = GetAllBuildingZones(_doc); if (zoneList.Count == 0) { return(Result.Cancelled); } int zoneCount = zoneList.Count; // Num of duplicata // Get the selected view ICollection <ElementId> refIds = _uidoc.Selection.GetElementIds(); if (refIds.Count == 0) { TaskDialog.Show("Revit", "Selecionner au moins d'une vue à dupliquer"); return(Result.Cancelled); } foreach (ElementId refId in refIds) { Element ele = _doc.GetElement(refId); if (ele.Category == null || !ele.Category.Name.Equals(Properties.Settings.Default.CATEGORY_NAME_VIEW)) { TaskDialog.Show("Revit", "Les élément selectionnés doivent être des VUES"); return(Result.Cancelled); } View view = ele as View; ViewFamilyType viewType = _doc.GetElement(view.GetTypeId()) as ViewFamilyType; if (!viewType.FamilyName.Equals(Properties.Settings.Default.FAMILY_TYPE_NAME_STR_PLAN)) { TaskDialog.Show("Revit", $"Les élément selectionnés doivent être des VUES EN PLAN"); return(Result.Cancelled); } } foreach (ElementId refId in refIds) { ViewPlan viewToDuplicate = _doc.GetElement(refId) as ViewPlan; Level level = viewToDuplicate.GenLevel; String levelName = level.Name; Transaction t = new Transaction(_doc, "Duplicate view"); t.Start(); for (int i = 0; i < zoneCount; i++) { ElementId viewId = viewToDuplicate.Duplicate(ViewDuplicateOption.AsDependent); ViewPlan duplicatedView = _doc.GetElement(viewId) as ViewPlan; duplicatedView.Name = $"{levelName} - {zoneList[i].Name}"; duplicatedView.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).Set(zoneList[i].Id); // Associate level to the new viewplan AssociateLevelToNewViewPlan(level, duplicatedView); } t.Commit(); } return(Result.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } }
private bool DuplicatePlanView(ModelInfo sModel, ModelInfo rModel, PlanViewInfo planInfo, ViewFamilyType vFamilyType, out PlanViewInfo createdPlanInfo) { bool duplicated = false; createdPlanInfo = null; try { Document sourceDoc = sModel.ModelDoc; Document recipientDoc = rModel.ModelDoc; using (Transaction trans = new Transaction(recipientDoc)) { trans.Start("Create Plan View"); try { ViewPlan createdView = null; ElementId levelId = GetLinkedItem(sModel, rModel, MapType.Level, planInfo.LevelId); if (levelId != ElementId.InvalidElementId) { if (planInfo.PlanViewType == ViewType.AreaPlan) { ElementId areaSchemeId = GetLinkedItem(sModel, rModel, MapType.AreaScheme, planInfo.AreaSchemeId); if (areaSchemeId != ElementId.InvalidElementId) { createdView = ViewPlan.CreateAreaPlan(recipientDoc, areaSchemeId, levelId); } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Area Scheme", ""); missingItems.Add(missingItem); } } else { createdView = ViewPlan.Create(recipientDoc, vFamilyType.Id, levelId); } if (null != createdView) { if (CanHaveViewName(rModel, planInfo.ViewName)) { createdView.Name = planInfo.ViewName; } createdView.CropBoxActive = planInfo.IsCropBoxOn; createdView.CropBox = planInfo.CropBox; createdView.DisplayStyle = planInfo.Display; foreach (string paramName in planInfo.ViewParameters.Keys) { Parameter sourceParam = planInfo.ViewParameters[paramName]; Parameter recipientParam = createdView.LookupParameter(paramName); if (parametersToSkip.Contains(sourceParam.Id.IntegerValue)) { continue; } if (null != recipientParam && sourceParam.HasValue) { if (!recipientParam.IsReadOnly) { switch (sourceParam.StorageType) { case StorageType.Double: try { recipientParam.Set(sourceParam.AsDouble()); } catch { } break; case StorageType.ElementId: /*try { recipientParam.Set(sourceParam.AsElementId()); } * catch { }*/ break; case StorageType.Integer: try { recipientParam.Set(sourceParam.AsInteger()); } catch { } break; case StorageType.String: try { recipientParam.Set(sourceParam.AsString()); } catch { } break; } } } } if (planInfo.ViewTemplateId != ElementId.InvalidElementId) { ElementId templateId = GetLinkedItem(sModel, rModel, MapType.ViewTemplate, planInfo.ViewTemplateId); if (templateId != ElementId.InvalidElementId && createdView.IsValidViewTemplate(templateId)) { createdView.ViewTemplateId = templateId; } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "View Template", ""); missingItems.Add(missingItem); } } if (planInfo.ScopeBoxId != ElementId.InvalidElementId) { ElementId scopeboxId = GetLinkedItem(sModel, rModel, MapType.ScopeBox, planInfo.ScopeBoxId); if (scopeboxId != ElementId.InvalidElementId) { Parameter param = createdView.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP); if (null != param) { param.Set(scopeboxId); } } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Scope Box", ""); missingItems.Add(missingItem); } } if (planInfo.PhaseId != ElementId.InvalidElementId) { ElementId phaseId = GetLinkedItem(sModel, rModel, MapType.Phase, planInfo.PhaseId); if (phaseId != ElementId.InvalidElementId) { Parameter param = createdView.get_Parameter(BuiltInParameter.VIEW_PHASE); if (null != param) { param.Set(phaseId); } } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Phase", ""); missingItems.Add(missingItem); } } if (viewConfig.ApplyWorksetVisibility && planInfo.WorksetVisibilities.Count > 0) { bool worksetFound = true; foreach (WorksetId wsId in planInfo.WorksetVisibilities.Keys) { WorksetVisibility wsVisibility = planInfo.WorksetVisibilities[wsId]; WorksetId worksetId = GetLinkedWorkset(sModel, rModel, wsId); if (worksetId != WorksetId.InvalidWorksetId) { createdView.SetWorksetVisibility(worksetId, wsVisibility); } else { worksetFound = false; } } if (!worksetFound) { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Workset", ""); missingItems.Add(missingItem); } } createdPlanInfo = new PlanViewInfo(createdView); createdPlanInfo.LinkedViewId = planInfo.ViewId; createdPlanInfo.Linked = true; duplicated = true; } } else { MissingItem missingItem = new MissingItem(planInfo.ViewName, "Level", planInfo.LevelName); missingItems.Add(missingItem); } trans.Commit(); } catch (Exception ex) { trans.RollBack(); string message = ex.Message; } } } catch (Exception ex) { MessageBox.Show(planInfo.ViewName + ": Failed to duplicate a plan view.\n" + ex.Message, "Duplicate Plan View", MessageBoxButton.OK, MessageBoxImage.Warning); } return(duplicated); }