private void CollectViews() { try { FilteredElementCollector collector = new FilteredElementCollector(m_doc); List <Element> elements = collector.OfClass(typeof(View3D)).ToElements().ToList(); foreach (Element e in elements) { View3D view3D = e as View3D; if (!view3dDictionary.ContainsKey(view3D.Name)) { view3dDictionary.Add(view3D.Name, view3D); } } collector = new FilteredElementCollector(m_doc); elements = collector.OfClass(typeof(ViewFamilyType)).ToElements().ToList(); foreach (Element element in elements) { ViewFamilyType viewfamilytype = element as ViewFamilyType; if (viewfamilytype.ViewFamily == ViewFamily.ThreeDimensional) { view3dFamilyType = viewfamilytype; } } } catch (Exception ex) { MessageBox.Show("Failed to collect 3d view information.\n" + ex.Message, "CommandForm:CollectView", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public static ViewFamilyType ViewTypeSetup(Document currentDoc) { ViewFamilyType vf1 = new FilteredElementCollector(currentDoc) .OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault <ViewFamilyType>(x => ViewFamily.Elevation == x.ViewFamily); ViewFamilyType vft; FilteredElementCollector vftfilter = new FilteredElementCollector(currentDoc).OfClass(typeof(ViewFamilyType)); ViewFamilyType vcheck = vftfilter.FirstOrDefault <Element>(q => q.Name.Equals("Generated Interior Elevation")) as ViewFamilyType; if (vcheck == null) { vft = vf1.Duplicate("Generated Interior Elevation") as ViewFamilyType; } else { if (vcheck.Name != "Generated Interior Elevation") { vft = vf1.Duplicate("Generated Interior Elevation") as ViewFamilyType; } else { vft = vcheck; } } return(vft); }
public static View3D Create3DView(Document doc, ItemInfo itemInfo, ViewFamilyType view3dFamilyType, bool overwrite) { View3D view3D = null; try { switch (itemInfo.ItemType) { case ViewBy.Workset: view3D = CreateWorkset3DView(doc, itemInfo, view3dFamilyType, overwrite); break; case ViewBy.Phase: view3D = CreatePhase3DView(doc, itemInfo, view3dFamilyType, overwrite); break; case ViewBy.DesignOption: view3D = CreateDesignOption3DView(doc, itemInfo, view3dFamilyType, overwrite); break; case ViewBy.Link: view3D = CreateLink3DView(doc, itemInfo, view3dFamilyType, overwrite); break; } } catch (Exception ex) { MessageBox.Show("Failed to create 3d view.\n" + ex.Message, "Create 3D View", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(view3D); }
private void UpdateLevels() { ViewFamilyType viewType = filterUtils.SelectViewFamilyType(ViewFamily.FloorPlan); //首先全部删除(00层不能删。在REVIT中,必须至少有一个标高) foreach (var level in acturalLevels) { if (level.Elevation != 0) { doc.Delete(level.Id); } else { level.Name = "0.000米层(建筑)"; } } //然后根据MockLevels,全部重新生成 foreach (var mockLevel in MockLevels) { if (mockLevel.Elevation != 0) { Level level = Level.Create(doc, mockLevel.Elevation); string name = (level.Elevation * 304.8 / 1000).ToString("#0.000"); if (mockLevel.IsStructural) { level.Name = name + "米层(结构)"; } else { level.Name = name + "米层(建筑)"; } ViewPlan floorview = ViewPlan.Create(doc, viewType.Id, level.Id); } } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; Document currentDoc = uiApp.ActiveUIDocument.Document; View av = currentDoc.ActiveView; ViewFamilyType vft = GenerateViews.ViewTypeSetup(currentDoc); if (av.ViewType == ViewType.FloorPlan) { RoomFilter filt = new RoomFilter(); ICollection <Element> roomset = new FilteredElementCollector(currentDoc, av.Id).WherePasses(filt).ToElements(); foreach (Element e in roomset) { Room r = e as Room; GenerateViews.GenViews(vft, av, r); } } else { TaskDialog.Show("Error", "Active a plan view!"); } return(Result.Succeeded); }
private Autodesk.Revit.DB.ViewPlan createViewPlan(Level level, string viewName) { ViewFamilyType viewFamilyType = null; FilteredElementCollector collectorViewFamilyType = new FilteredElementCollector(uidoc.Document); var viewFamilyTypes = collectorViewFamilyType.OfClass(typeof(ViewFamilyType)).ToElements(); foreach (Element e in viewFamilyTypes) { ViewFamilyType v = e as ViewFamilyType; if (v.ViewFamily == ViewFamily.FloorPlan) { viewFamilyType = v; break; } } if ((viewFamilyType != null) && (level != null)) { ViewPlan viewPlan = ViewPlan.Create(uidoc.Document, viewFamilyType.Id, level.Id); viewPlan.Name = viewName; return(viewPlan); } return(null); }
public static View3D CreatePhase3DView(Document doc, ItemInfo itemInfo, ViewFamilyType view3dFamilyType, bool overwrite) { View3D view3D = null; try { string viewName = "PH - 3D - " + itemInfo.ItemName; using (Transaction trans = new Transaction(doc)) { FilteredElementCollector collector = new FilteredElementCollector(doc); List <View3D> view3ds = collector.OfClass(typeof(View3D)).ToElements().Cast <View3D>().ToList(); var views = from view in view3ds where view.Name == viewName select view; if (views.Count() > 0) { if (overwrite) { view3D = views.First(); } else { return(view3D); } } if (null == view3D) { trans.Start("Create 3D View"); try { view3D = View3D.CreateIsometric(doc, view3dFamilyType.Id); view3D.Name = viewName; if (view3D.CanModifyViewDiscipline()) { view3D.Discipline = ViewDiscipline.Coordination; } Parameter param = view3D.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 3d view by phases.\n" + ex.Message, "Create 3D View", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } catch (Exception ex) { MessageBox.Show("Failed to create 3d views by phases.\n" + ex.Message, "Create 3D Views by Phases", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(view3D); }
public static ViewPlan CreateFloorPlan(Document doc, ItemInfo itemInfo, ViewFamilyType viewPlanFamilyType, Level planLevel, bool overwrite) { ViewPlan viewPlan = null; try { switch (itemInfo.ItemType) { case ViewBy.Workset: viewPlan = CreateWorksetFloorPlan(doc, itemInfo, viewPlanFamilyType, planLevel, overwrite); break; case ViewBy.Phase: viewPlan = CreatePhaseFloorPlan(doc, itemInfo, viewPlanFamilyType, planLevel, overwrite); break; case ViewBy.DesignOption: viewPlan = CreateDesignOptionFloorPlan(doc, itemInfo, viewPlanFamilyType, planLevel, overwrite); break; } } catch (Exception ex) { MessageBox.Show("Failed to create floor plan.\n" + ex.Message, "Create Floor Plan", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(viewPlan); }
public View3D Get3dView(Document doc) { FilteredElementCollector val = new FilteredElementCollector(doc).OfClass(typeof(View3D)); Regex regex = new Regex("^Shadow Analysis 2 Export [0-9]*$"); Regex regex2 = new Regex("[0-9]*$"); int num = 0; foreach (Element item in val) { View3D val2 = item; Match match = regex.Match(val2.get_Name()); if (match.Success) { int num2 = int.Parse(regex2.Match(match.Value).Value); if (num < num2) { num = num2; } } } Transaction val3 = new Transaction(doc); val3.Start("Create 3D view"); ViewFamilyType val4 = ((IEnumerable) new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))).Cast <ViewFamilyType>().FirstOrDefault <ViewFamilyType>((Func <ViewFamilyType, bool>)((ViewFamilyType x) => 102 == (int)x.get_ViewFamily())); View3D val5 = View3D.CreateIsometric(doc, val4.get_Id()); val5.set_Name("Shadow Analysis 2 Export " + (num + 1).ToString()); val3.Commit(); return(val5); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { try { m_project = commandData.Application.ActiveUIDocument; // Get the selected element and store it to data member. if (!GetSelectedElement()) { message = m_errorInformation; return(Autodesk.Revit.UI.Result.Failed); } // Create a BoundingBoxXYZ instance which used in NewViewSection() method if (!GenerateBoundingBoxXYZ()) { message = m_errorInformation; return(Autodesk.Revit.UI.Result.Failed); } // Create a section view. Transaction transaction = new Transaction(m_project.Document, "CreateSectionView"); transaction.Start(); //ViewSection section = m_project.Document.Create.NewViewSection(m_box); ElementId DetailViewId = new ElementId(-1); IList <Element> elems = new FilteredElementCollector(m_project.Document).OfClass(typeof(ViewFamilyType)).ToElements(); foreach (Element e in elems) { ViewFamilyType v = e as ViewFamilyType; if (v != null && v.ViewFamily == ViewFamily.Detail) { DetailViewId = e.Id; break; } } ViewSection section = ViewSection.CreateDetail(m_project.Document, DetailViewId, m_box); if (null == section) { message = "Can't create the ViewSection."; return(Autodesk.Revit.UI.Result.Failed); } // Modify some parameters to make it look better. section.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(2); transaction.Commit(); // If everything goes right, give successful information and return succeeded. TaskDialog.Show("Revit", "Create view section succeeded."); return(Autodesk.Revit.UI.Result.Succeeded); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } }
public void ViewCreate() { Document doc = this.ActiveUIDocument.Document; // get a ViewFamilyType for a 3D View. created new instance of ViewFamilYType calle 'viewFamilyType' ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc). // Creates new filteredElementCollector to select all ViewFamilyTypes OfClass(typeof(ViewFamilyType)). Cast <ViewFamilyType>() where v.ViewFamily == ViewFamily.ThreeDimensional select v).First(); Categories categories = doc.Settings.Categories; Category dim = categories.get_Item(BuiltInCategory.OST_Dimensions); Category line = categories.get_Item(BuiltInCategory.OST_Lines); XYZ eye = new XYZ(100, 100, 100); XYZ forward = new XYZ(-1, 1, -1); XYZ up = new XYZ(-1, 1, 2); ViewOrientation3D vOrient = new ViewOrientation3D(eye, up, forward); using (Transaction t = new Transaction(doc, "Create view")) { t.Start(); View3D view = View3D.CreateIsometric(doc, viewFamilyType.Id); view.get_Parameter(BuiltInParameter.MODEL_GRAPHICS_STYLE) .Set(4); view.SetOrientation(vOrient); view.HideCategoryTemporary(dim.Id); view.HideCategoryTemporary(line.Id); view.SaveOrientationAndLock(); t.Commit(); } }
View CreateDrafting(Document doc) { FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(ViewFamilyType)); ViewFamilyType viewFamilyType = collector.Cast <ViewFamilyType>().First(vft => vft.ViewFamily == ViewFamily.Drafting); ViewDrafting drafting = ViewDrafting.Create(doc, viewFamilyType.Id); return(drafting as View); }
public static ViewDrafting viewDraftingCreate(Document doc, string viewName) { FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)); ViewFamilyType viewFamilyType = collector.Cast <ViewFamilyType>().First(vft => vft.ViewFamily == ViewFamily.Drafting); ViewDrafting view = ViewDrafting.Create(doc, viewFamilyType.Id); view.ViewName = viewName; return(view); }
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); }
public static View ViewPlan(this Document document, Autodesk.Revit.DB.Level level, string viewName = null, CurveLoop cropBox = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse) { View result = null; ViewFamilyType vft = Query.ViewFamilyType(document, ViewFamily.FloorPlan); result = Autodesk.Revit.DB.ViewPlan.Create(document, vft.Id, level.Id); Modify.SetViewDetailLevel(result, viewDetailLevel); if (cropBox != null) { try { ViewCropRegionShapeManager vcrShapeMgr = result.GetCropRegionShapeManager(); result.CropBoxVisible = true; vcrShapeMgr.SetCropShape(cropBox); } catch (Exception) { BH.Engine.Reflection.Compute.RecordWarning("Could not create the Floor Plan with the provided crop box. Check if the crop box is a valid geometry and if the view's designated template accepts it to change."); } } if (viewTemplateId != null) { try { result.ViewTemplateId = viewTemplateId; } catch (Exception) { BH.Engine.Reflection.Compute.RecordWarning("Could not apply the View Template of Id " + viewTemplateId + "'." + ". Please check if it's a valid ElementId."); } } if (!string.IsNullOrEmpty(viewName)) { try { #if (REVIT2018 || REVIT2019) result.ViewName = viewName; #else result.Name = viewName; #endif } catch { BH.Engine.Reflection.Compute.RecordWarning("There is already a view named '" + viewName + "'." + " It has been named '" + result.Name + "' instead."); } } return(result); }
public static ViewSection CreateSectionAtBottomAndRight(Document doc, Element StructuralFrame, double bottomorleftoffset, double ToporRightoffset) { IList <Parameter> param1 = new List <Parameter>(); IList <XYZ> points = (StructuralFrame.Location as LocationCurve).Curve.Tessellate(); XYZ p1 = points[0], p2 = points[1]; // XYZ v = p1 - p2; double vec_ang1 = 360 - Math.Round(Converter.R2D((p2 - p1).AngleOnPlaneTo(XYZ.BasisX, XYZ.BasisZ))); vec_ang1 = (vec_ang1 == 360) ? 0.0 : vec_ang1; XYZ pt1 = StructuralFrame.get_BoundingBox(doc.ActiveView).Min; XYZ pt2 = StructuralFrame.get_BoundingBox(doc.ActiveView).Max; double len = (p2 - p1).GetLength() * 0.5; ElementId BeamSymid = StructuralFrame.GetTypeId(); Element BeamSym = doc.GetElement(BeamSymid); double wid = BeamSym.GetParameters("Beam Width")[0].AsDouble(); double ht = pt2.Z - pt1.Z; ViewFamilyType view = Filter.ElementFiltering(doc, typeof(ViewFamilyType), "Section", "Building Section", null) as ViewFamilyType; XYZ min = new XYZ(-len - bottomorleftoffset, pt1.Z - 1, -wid); XYZ max = new XYZ(len + ToporRightoffset, pt2.Z + 1, wid); XYZ midpt = p1 + (p2 - p1) / 2; XYZ BeamDir = null; if (((vec_ang1 >= 0) && (vec_ang1 <= 135)) || ((vec_ang1 >= 315) && (vec_ang1 <= 360))) { BeamDir = (p1 - p2).Normalize(); } else { BeamDir = (p2 - p1).Normalize(); } XYZ up = XYZ.BasisZ; XYZ viewdir = BeamDir.CrossProduct(up); Transform t = Transform.Identity; t.Origin = midpt; t.BasisX = BeamDir; t.BasisY = up; t.BasisZ = viewdir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = t; sectionBox.Min = min; sectionBox.Max = max; ViewSection vsec = ViewSection.CreateSection(doc, view.Id, sectionBox); return(vsec); }
public static ViewSection CreateSectionAtBottomAndRight(Document doc, XYZ Start_Point, XYZ End_Point, BoundingBoxXYZ bb, double MaxBeamWidth, double MaxBeamDepth, double bottomorleftoffset, double ToporRightoffset) { IList <Parameter> param1 = new List <Parameter>(); // XYZ v = Start_Point - End_Point; double vec_ang1 = 360 - Math.Round(Converter.R2D((End_Point - Start_Point).AngleOnPlaneTo(XYZ.BasisX, XYZ.BasisZ))); vec_ang1 = (vec_ang1 == 360) ? 0.0 : vec_ang1; XYZ pt1 = bb.Min; XYZ pt2 = bb.Max; double len = (End_Point - Start_Point).GetLength() * 0.5; ViewFamilyType view = Filter.ElementFiltering(doc, typeof(ViewFamilyType), "Section", "Building Section", null) as ViewFamilyType; XYZ min = new XYZ(-len - bottomorleftoffset, pt1.Z - 1, -MaxBeamWidth); XYZ max = new XYZ(len + ToporRightoffset, pt2.Z + 1, MaxBeamWidth); XYZ midpt = Start_Point + (End_Point - Start_Point) / 2; XYZ BeamDir = null; if (((vec_ang1 >= 0) && (vec_ang1 <= 135)) || ((vec_ang1 >= 315) && (vec_ang1 <= 360))) { BeamDir = (Start_Point - End_Point).Normalize(); } else { BeamDir = (End_Point - Start_Point).Normalize(); } XYZ up = XYZ.BasisZ; XYZ viewdir = BeamDir.CrossProduct(up); Transform t = Transform.Identity; t.Origin = midpt; t.BasisX = BeamDir; t.BasisY = up; t.BasisZ = viewdir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = t; sectionBox.Min = min; sectionBox.Max = max; ViewSection vsec = ViewSection.CreateSection(doc, view.Id, sectionBox); return(vsec); }
private ViewFamilyType GetViewFamilyType(Document doc, ViewFamily viewFamily) { ViewFamilyType vFamilyType = null; FilteredElementCollector collector = new FilteredElementCollector(doc); List <ViewFamilyType> viewFamilyTypes = collector.OfClass(typeof(ViewFamilyType)).ToElements().Cast <ViewFamilyType>().ToList(); var vTypes = from vType in viewFamilyTypes where vType.ViewFamily == viewFamily select vType; if (vTypes.Count() > 0) { vFamilyType = vTypes.First(); } return(vFamilyType); }
public FindCADsWindow(UIDocument uid) { InitializeComponent(); CADListView.ItemsSource = CADList; uidoc = uid; doc = uidoc.Document; // Get all imports in the model FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(ImportInstance)) .WhereElementIsNotElementType() .Cast <ImportInstance>(); foreach (ImportInstance IInstance in collector) { // This section gets view specific imports if (IInstance.OwnerViewId != null && IInstance.OwnerViewId.IntegerValue != -1) { View ownerView = doc.GetElement(IInstance.OwnerViewId) as View; ViewFamilyType ViewTy = doc.GetElement(ownerView.GetTypeId()) as ViewFamilyType; string ViewN = ViewTy.Name + " - " + ownerView.Name; CADItem addition = new CADItem { ViewName = ViewN, CADImportInstance = IInstance, OwnerView = ownerView, IsHide = IInstance.IsHidden(ownerView).ToString() }; CADList.Add(addition); } // This section gets model-wide imports. These CADs can be viewed in every view else { CADItem addition = new CADItem { ViewName = null, CADImportInstance = IInstance, OwnerView = null, IsHide = null }; CADList.Add(addition); } } }
public static View3D GetMatching3DView(this View view, Document doc) { ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc). OfClass(typeof(ViewFamilyType)). Cast <ViewFamilyType>() where v.ViewFamily == ViewFamily.ThreeDimensional select v).First(); View3D view3d = View3D.CreateIsometric(doc, viewFamilyType.Id); view3d.Name = view.Name + " 3D temp view"; ViewBox myviewbox = GetViewBox(view); if (myviewbox.bbox == null) { BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ(); boundingBoxXYZ.Min = myviewbox.P1; boundingBoxXYZ.Max = myviewbox.P2; view3d.SetSectionBox(boundingBoxXYZ); } else { view3d.SetSectionBox(myviewbox.bbox); } view3d.SetOrientation(new ViewOrientation3D(myviewbox.EyePosition, myviewbox.DirectionUp, myviewbox.DirectionView)); foreach (Category cat in doc.Settings.Categories) { try { if (cat.CategoryType == CategoryType.Model && cat.get_AllowsVisibilityControl(view3d)) { view3d.SetVisibility(cat, view.GetVisibility(cat)); } } catch (System.Exception e) { } } doc.Regenerate(); return(view3d); }
/// <summary> /// 根据视图类型选择一个视图类型:楼层平面、天花板平面、面积平面等 /// </summary> /// <param name="viewFamily"></param> /// <returns></returns> public ViewFamilyType SelectViewFamilyType(ViewFamily viewFamily) { ViewFamilyType viewType = null; FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(ViewFamilyType)); foreach (ViewFamilyType item in collector) { if (item.ViewFamily == viewFamily) { viewType = item; } } return(viewType); }
private void GetViewFamilyType() { try { FilteredElementCollector collector = new FilteredElementCollector(m_app.ActiveUIDocument.Document); List <ViewFamilyType> elements = collector.OfClass(typeof(ViewFamilyType)).ToElements().Cast <ViewFamilyType>().ToList(); var types = from type in elements where type.ViewFamily == ViewFamily.ThreeDimensional select type; view3dFamilyType = types.First(); types = from type in elements where type.ViewFamily == ViewFamily.FloorPlan select type; viewPlanFamilyType = types.First(); } catch (Exception ex) { MessageBox.Show("Failed to get view family type.\n" + ex.Message, "Get 3D View Family Type", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; Document currentDoc = uiApp.ActiveUIDocument.Document; UIDocument uiDoc = uiApp.ActiveUIDocument; View av = currentDoc.ActiveView; ViewFamilyType vft = GenerateViews.ViewTypeSetup(currentDoc); if (av.ViewType == ViewType.FloorPlan) { Selection sel = uiDoc.Selection; ICollection <ElementId> set = sel.GetElementIds(); if (set.Count == 1) { foreach (ElementId id in set) { Element e = currentDoc.GetElement(id); Room r = e as Room; if (null != r) { BoundaryData b = new BoundaryData(r); GenerateViews.GenViews(vft, av, r); } else { TaskDialog.Show("Error", "Please select a room."); } } } else { TaskDialog.Show("Error", "Please select a room."); } } else { TaskDialog.Show("Error", "Active a plan view!"); } return(Result.Succeeded); }
public BoundedViewCreator(Level level, Element scopeBox, BoundingBoxXYZ bounds) { Level = level; ScopeBox = scopeBox; Bounds = bounds; Document _doc = Level?.Document; if (_doc != null) { List <ViewFamilyType> _viewFamilyTypes = new FilteredElementCollector(_doc) .OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().ToList(); _3DViewFamilyType = _viewFamilyTypes.FirstOrDefault(vft => vft.ViewFamily == ViewFamily.ThreeDimensional); _floorPlanViewFamilyType = _viewFamilyTypes.FirstOrDefault(vft => vft.ViewFamily == ViewFamily.FloorPlan); _sectionViewFamilyType = _viewFamilyTypes.FirstOrDefault(vft => vft.ViewFamily == ViewFamily.Section); } }
public static Dictionary <string, List <List <Revit.Elements.Element> > > CompareViewFamilyTypes(List <Revit.Elements.Element> ViewFamilyType, List <Revit.Elements.Element> Views) { List <List <Revit.Elements.Element> > found = new List <List <Revit.Elements.Element> >(); List <List <Revit.Elements.Element> > not = new List <List <Revit.Elements.Element> >(); var doc = DocumentManager.Instance.CurrentDBDocument; foreach (Revit.Elements.Element k in Views) { if (k != null) { List <Revit.Elements.Element> nest = new List <Revit.Elements.Element>(); nest.Clear(); ElementId searcher = Spring.Elements.UnwrapElement(k); View finalView = doc.GetElement(searcher) as View; ElementId viewID = finalView.GetTypeId(); if (viewID != null && searcher != null) { foreach (Revit.Elements.Element l in ViewFamilyType) { ElementId finder = Spring.Elements.UnwrapElement(l); ViewFamilyType elements = doc.GetElement(finder) as ViewFamilyType; Revit.Elements.Element oView = finalView.ToDSType(false); Revit.Elements.Element eMent = elements.ToDSType(false); nest.Add(oView); nest.Add(eMent); if (viewID == finder) { found.Add(nest); } else { not.Add(nest); }; } } } } return(new Dictionary <string, List <List <Revit.Elements.Element> > >() { { "View Family Type Found", found }, { "View Family Type Not Found", not } }); }
public void Test() { try { UIDocument uidoc = this.ActiveUIDocument; Document doc = uidoc.Document; Transaction transaction = new Transaction(doc, "Duplicate FamilyTemplate"); transaction.Start("Duplicate FamilyTemplate"); FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)); ViewFamilyType old_v = a.FirstOrDefault <Element>(e => e.Name.Equals("test")) as ViewFamilyType; ViewFamilyType new_v = old_v.Duplicate("asdasd") as ViewFamilyType; ICollection <ElementId> delIds = doc.Delete(old_v.Id); transaction.Commit(); } catch (Exception e) { TaskDialog.Show("Error", e.Message); } }
public Autodesk.Revit.UI.Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { try { Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document; Transaction transaction = new Transaction(doc, "CreateDraftingView"); transaction.Start(); ViewFamilyType viewFamilyType = null; FilteredElementCollector collector = new FilteredElementCollector(doc); var viewFamilyTypes = collector.OfClass(typeof(ViewFamilyType)).ToElements(); foreach (Element e in viewFamilyTypes) { ViewFamilyType v = e as ViewFamilyType; if (v.ViewFamily == ViewFamily.Drafting) { viewFamilyType = v; break; } } ViewDrafting drafting = ViewDrafting.Create(doc, viewFamilyType.Id); if (null == drafting) { message = "Can't create the ViewDrafting."; return(Autodesk.Revit.UI.Result.Failed); } transaction.Commit(); TaskDialog.Show("Revit", "Create view drafting succeeded."); return(Autodesk.Revit.UI.Result.Succeeded); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } }
/// <summary> /// Get the default family type for creating ViewPlans. /// </summary> /// <param name="doc"></param> /// <returns></returns> public static ElementId GetViewPlanTypeId(Document doc) { if (m_ViewPlanTypeIdInitialized == false) { ViewFamily viewFamilyToUse = (doc.Application.Product == ProductType.Structure) ? ViewFamily.StructuralPlan : ViewFamily.FloorPlan; m_ViewPlanTypeIdInitialized = true; FilteredElementCollector collector = new FilteredElementCollector(doc); ICollection <Element> viewFamilyTypes = collector.OfClass(typeof(ViewFamilyType)).ToElements(); foreach (Element element in viewFamilyTypes) { ViewFamilyType viewFamilyType = element as ViewFamilyType; if (viewFamilyType.ViewFamily == viewFamilyToUse) { m_ViewPlanTypeId = viewFamilyType.Id; break; } } } return(m_ViewPlanTypeId); }
private ElementId GetViewFamilyType(string viewTypeName) { IEnumerable <ViewFamilyType> coll = new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .Where(v => v.Name.Equals(viewTypeName)); //check if we found the view family type if (coll != null) { ViewFamilyType vt = coll.FirstOrDefault(); if (vt != null) { return(vt.Id);//found the view family type } } //did not find specified view family type return(null); }
/// <summary> /// add more levels so that level number can meet floor number /// </summary> public void UpdateLevels() { double baseElevation = m_levels.Values[m_levels.Count - 1].Elevation; Autodesk.Revit.Creation.Document createDoc = m_commandData.Application.ActiveUIDocument.Document.Create; Autodesk.Revit.DB.Document m_Doc = m_commandData.Application.ActiveUIDocument.Document; FilteredElementCollector collector = new FilteredElementCollector(m_Doc); IList <Element> viewFamilyTypes = collector.OfClass(typeof(ViewFamilyType)).ToElements(); ElementId floorPlanId = new ElementId(-1); foreach (Element e in viewFamilyTypes) { ViewFamilyType v = e as ViewFamilyType; if (v != null && v.ViewFamily == ViewFamily.FloorPlan) { floorPlanId = e.Id; break; } } int newLevelSize = (m_floorNumber + 1) - m_levels.Count; if (newLevelSize == 0) { return; } for (int ii = 0; ii < newLevelSize; ii++) { double elevation = baseElevation + m_levelHeight * (ii + 1); Level newLevel = Level.Create(m_commandData.Application.ActiveUIDocument.Document, elevation); //createDoc.NewViewPlan(newLevel.Name, newLevel, Autodesk.Revit.DB.ViewPlanType.FloorPlan); ViewPlan viewPlan = ViewPlan.Create(m_Doc, floorPlanId, newLevel.Id); viewPlan.Name = newLevel.Name; m_levels.Add(elevation, newLevel); } m_originalLevelSize = m_levels.Count; }