/// <summary> /// Adds a Revision to a Sheet /// </summary> /// <param name="Sheet">Dynamo wrapped Sheet element</param> /// <param name="Revision">Dynamo wrapped Revision element</param> /// <returns name="Sheet">Returns the modified sheet.</returns> public static DynaSheet AddRevision(DynaSheet Sheet, DynaRevision Revision) { RevitSheet revitSheet = (RevitSheet)Sheet.InternalElement; RevitRevision revitRevision = (RevitRevision)Revision.InternalElement; RevitDoc document = revitSheet.Document; List <RevitDB.ElementId> revisions = (List <RevitDB.ElementId>)revitSheet.GetAdditionalRevisionIds(); if (!revisions.Contains(revitRevision.Id)) { revisions.Add(revitRevision.Id); } if (document.IsModifiable) { TransactionManager.Instance.EnsureInTransaction(document); revitSheet.SetAdditionalRevisionIds(revisions); TransactionManager.Instance.TransactionTaskDone(); } else { using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document)) { trans.Start("Set Revision on Sheet"); revitSheet.SetAdditionalRevisionIds(revisions); trans.Commit(); } } return(Sheet); }
private bool updatePositionsInit(Autodesk.Revit.DB.ViewSheet curViewSheet) { Autodesk.Revit.DB.XYZ norXYZ = null; Autodesk.Revit.DB.ElementId deltaViewportId = null; if (curViewSheet != null) { ICollection <ElementId> curViewportsIdsCollection = curViewSheet.GetAllViewports(); foreach (ElementId curViewportId in curViewportsIdsCollection) { if (this.selViewportsIdsAndPositions.ContainsKey(curViewportId)) { Autodesk.Revit.DB.Viewport curViewport = doc.GetElement(curViewportId) as Autodesk.Revit.DB.Viewport; if (curViewport != null) { norXYZ = curViewport.GetBoxCenter(); break; } } } } List <ElementId> viewportIds = new List <ElementId>(this.selViewportsIdsAndPositions.Keys); PageAlignmentToolRequestHandler handler = new PageAlignmentToolRequestHandler(norXYZ, deltaViewportId, viewportIds); ExternalEvent exEvent = ExternalEvent.Create(handler); exEvent.Raise(); return(true); }
public static Dictionary <string, object> GetViewportsAndViews(global::Revit.Elements.Views.Sheet sheet) { Autodesk.Revit.DB.ViewSheet viewSheet = (Autodesk.Revit.DB.ViewSheet)sheet.InternalElement; Autodesk.Revit.DB.Document doc = viewSheet.Document; //obtains the viewports from the given sheet var viewportIds = viewSheet.GetAllViewports(); List <global::Revit.Elements.Element> viewports = new List <global::Revit.Elements.Element>(); //attempt to add views to output try { viewports.AddRange(viewportIds.Select(id => doc.GetElement(id).ToDSType(true))); } catch (Exception) { //suppress } //obtains the views from the given sheet List <object> views = new List <object>(); //attempt to add views to output try { views.AddRange(viewports.Select(v => doc.GetElement(((Autodesk.Revit.DB.Viewport)v.InternalElement).ViewId).ToDSType(true))); } catch (Exception) { //suppress } //obtains the schedules from the sheet var scheduleCollector = new FilteredElementCollector(doc, viewSheet.Id).OfCategory(BuiltInCategory.OST_ScheduleGraphics) .ToElements(); List <object> schedules = new List <object>(); //attempt to add schedules to output try { schedules.AddRange(scheduleCollector.Select(s => s.ToDSType(true))); } catch (Exception) { //suppress } //returns the outputs var outInfo = new Dictionary <string, object> { { "viewports", viewports }, { "views", views }, { "schedules", schedules } }; return(outInfo); }
/// <summary> /// Create a View from a user selected Element. /// </summary> /// <param name="view"></param> /// <param name="isRevitOwned"></param> /// <returns></returns> internal static Sheet FromExisting(Autodesk.Revit.DB.ViewSheet view, bool isRevitOwned) { return(new Sheet(view) { IsRevitOwned = isRevitOwned }); }
private void Load() { DirectoryInfo d = new DirectoryInfo(_data.Setting.GetFolderPath()); var p = d.GetFiles().ToList(); string filename = lb_view.SelectedItem.ToString(); string pathfile = ""; foreach (var item in p) { if (item.Name.Replace(".json", "") == filename) { pathfile = item.FullName; break; } } var json = File.ReadAllText(pathfile); CegParameterSet dictemp = JsonConvert.DeserializeObject <CegParameterSet>(json); a.ViewSheet viewSheet = _doc.ActiveView as a.ViewSheet; using (a.Transaction tran = new a.Transaction(_doc, "Set Parameter Sheet")) { tran.Start(); foreach (var item in dictemp.Parameters) { foreach (var item2 in _data.dic.Parameters) { if (item.Value.Name == item2.Value.Name) { a.Parameter pa = viewSheet.LookupParameter(item2.Value.Name); if (pa != null) { a.InternalDefinition definition = pa.Definition as a.InternalDefinition; if (definition.BuiltInParameter != a.BuiltInParameter.SHEET_NAME && definition.BuiltInParameter != a.BuiltInParameter.SHEET_NUMBER) { switch (item2.Value.Type) { case a.StorageType.Double: pa.Set(item.Value.AsDouble); break; case a.StorageType.String: pa.Set(item.Value.AsString); break; case a.StorageType.Integer: pa.Set(item.Value.AsInteger); break; default: break; } } } } } } tran.Commit(); } Close(); }
/// <summary> /// Renumbers the views on the Active Sheet /// </summary> /// <param name="familyType">Dynamo FamilyType that represents the origin element</param> /// <param name="xGridName">Name of the parameter that represents the X grid spacing</param> /// <param name="yGridName">Name of the parameter that represents the Y grid spacing</param> /// <returns name="Viewports">Revit viewport objects on the sheet.</returns> public static List <revitViewport> RenumberOnActiveSheet(FamilyType familyType, string xGridName, string yGridName) { revitDoc document = Document.Current(); revitSheet rSheet = (revitSheet)document.ActiveView; return(_renumberViewsOnSheet(familyType, xGridName, yGridName, rSheet, document)); }
/// <summary> /// Renumbers the views on the Active Sheet /// </summary> /// <param name="sheet">A dynamo Sheet element</param> /// <param name="familyType">Dynamo FamilyType that represents the origin element</param> /// <param name="xGridName">Name of the parameter that represents the X grid spacing</param> /// <param name="yGridName">Name of the parameter that represents the Y grid spacing</param> /// <returns name="Viewports">Revit viewport objects on the sheet.</returns> public static List <revitViewport> RenumberOnSheet(dynaSheet sheet, FamilyType familyType, string xGridName, string yGridName) { revitSheet rSheet = (revitSheet)sheet.InternalElement; revitDoc document = rSheet.Document; return(_renumberViewsOnSheet(familyType, xGridName, yGridName, rSheet, document)); }
/// <summary> /// Renumbers the views on the sheet based on the view grid. /// </summary> /// <param name="sheet">A dynamo Sheet element</param> /// <param name="gridX">Size of the layout grid in the X direction</param> /// <param name="gridY">Size of the layout grid in the Y direction</param> /// <param name="originX">Location of the layout grid origin on the X axis</param> /// <param name="originY">Location of the layout grid origin on the Y axis</param> /// <returns name="Viewports">Revit viewport objects on the sheet.</returns> public static List <revitViewport> RenumberOnSheetByCoordinates(dynaSheet sheet, double gridX, double gridY, double originX, double originY) { string transactionName = "Renumber views on sheet"; // Initialize variables revitSheet rSheet = (revitSheet)sheet.InternalElement; revitDoc document = rSheet.Document; List <revitElemId> rViewports = (List <revitElemId>)rSheet.GetAllViewports(); List <revitViewport> viewports; // If the document is modifieable, // then a transaction is already open // and function uses the Dynamo Transaction Manager. // Else, open a new transaction. if (document.IsModifiable) { TransactionManager.Instance.EnsureInTransaction(document); viewports = View._tempRenumberViewports(rViewports, document); viewports = View._renumberViewports(viewports, gridX, gridY, originX, originY); TransactionManager.Instance.TransactionTaskDone(); } else { using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document)) { trans.Start(transactionName); viewports = View._tempRenumberViewports(rViewports, document); viewports = View._renumberViewports(viewports, gridX, gridY, originX, originY); trans.Commit(); } } return(viewports); }
/// <summary> /// Creates a Placeholder Sheet /// </summary> /// <param name="SheetNumber">The sheet number</param> /// <param name="SheetTitle">The sheet title</param> /// <param name="document">Document to create the sheet in.</param> /// <returns name="Sheet">Returns the created placeholder sheet as a dynamo wrapped sheet.</returns> public static DynaSheet CreatePlaceHolderSheet(string SheetNumber, string SheetTitle, [DefaultArgument("Synthetic.Revit.Document.Current()")] RevitDoc document) { RevitSheet revitSheet; if (document.IsModifiable) { TransactionManager.Instance.EnsureInTransaction(document); revitSheet = RevitSheet.CreatePlaceholder(document); revitSheet.SheetNumber = SheetNumber; RevitDB.Parameter paramName = revitSheet.get_Parameter(RevitDB.BuiltInParameter.SHEET_NAME); paramName.Set(SheetTitle); TransactionManager.Instance.TransactionTaskDone(); } else { using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document)) { trans.Start("Create Placeholder Sheet"); revitSheet = RevitSheet.CreatePlaceholder(document); revitSheet.SheetNumber = SheetNumber; RevitDB.Parameter paramName = revitSheet.get_Parameter(RevitDB.BuiltInParameter.SHEET_NAME); paramName.Set(SheetTitle); trans.Commit(); } } return((DynaSheet)revitSheet.ToDSType(false)); }
private void uiapp_ViewActivated(object sender, Autodesk.Revit.UI.Events.ViewActivatedEventArgs e) { if (doc.ActiveView.GetType().Name == "ViewSheet") { Autodesk.Revit.DB.ViewSheet curViewSheet = doc.ActiveView as Autodesk.Revit.DB.ViewSheet; if (curViewSheet != null) { //updatePositionsInit(curViewSheet); } } }
private void uiapp_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e) { if (doc.ActiveView.GetType().Name == "ViewSheet") { Autodesk.Revit.DB.ViewSheet curViewSheet = doc.ActiveView as Autodesk.Revit.DB.ViewSheet; if (curViewSheet != null) { if (updatePositions(curViewSheet)) { this.uiapp.ViewActivating -= uiapp_ViewActivating; this.uiapp.ViewActivated -= uiapp_ViewActivated; this.uiapp.Idling -= uiapp_Idling; } } } }
public static Dictionary <string, dynamic> ViewportLocations(Revit.Elements.Views.Sheet sheet) { Document doc = DocumentManager.Instance.CurrentDBDocument; Autodesk.Revit.DB.ViewSheet iSheet = sheet.InternalElement as Autodesk.Revit.DB.ViewSheet; var allViewports = iSheet.GetAllViewports().Select(x => doc.GetElement(x) as Viewport); return(new Dictionary <string, dynamic>() { { "viewportNames", allViewports.Select(x => (doc.GetElement(x.ViewId) as Autodesk.Revit.DB.View).ViewName) }, { "viewportLocations", ( allViewports.Select( x => x.GetBoxCenter()).Select( x => Autodesk.DesignScript.Geometry.Point.ByCoordinates(x.X, x.Y, x.Z))) } }); }
/// <summary> /// Returns all scales present on a sheet in a sorted list of integers. /// </summary> /// <param name="sheet">The input sheet.</param> /// <returns></returns> public static int[] AllScales(Revit.Elements.Views.Sheet sheet) { Document doc = DocumentManager.Instance.CurrentDBDocument; Autodesk.Revit.DB.ViewSheet iSheet = sheet.InternalElement as Autodesk.Revit.DB.ViewSheet; ISet <ElementId> eIds = iSheet.GetAllPlacedViews(); List <int> scales = new List <int>(); scales.AddRange(eIds.Select(x => (doc.GetElement(x) as Autodesk.Revit.DB.View).Scale)); scales = scales.Distinct().ToList(); scales.Sort(); return(scales.ToArray()); }
public static dynamic[] PlacedViews(Revit.Elements.Views.Sheet sheet) { Document doc = DocumentManager.Instance.CurrentDBDocument; Autodesk.Revit.DB.ViewSheet iSheet = sheet.InternalElement as Autodesk.Revit.DB.ViewSheet; ISet <ElementId> eIds = iSheet.GetAllPlacedViews(); List <dynamic> views = new List <dynamic>(); foreach (ElementId eId in eIds) { views.Add(doc.GetElement(eId).ToDSType(true)); } return(views.ToArray()); }
private void CreateDesignOptions(int id) { int curScale = GetScaleFromString(requestData.scaleName); for (int r = 0; r < requestData.optionsInfos.Count; r++) { Tuple <string, string, string, string, string, string> curDesignOptionInfo = requestData.optionsInfos[r]; DesignOption curDesignOption = getDesignOptionIdByNames(curDesignOptionInfo.Item1, curDesignOptionInfo.Item2); if (curDesignOption != null) { Autodesk.Revit.DB.Level curLevel = GetLevelFromString(curDesignOptionInfo.Item4); if (curLevel != null) { try { Autodesk.Revit.DB.ViewPlan curViewPlan = createViewPlan(curLevel, curDesignOptionInfo.Item3); foreach (Parameter curParameter in curViewPlan.Parameters) { if (curParameter.Definition.Name == "Visible In Option") { curParameter.Set(curDesignOption.Id); break; } } if (curViewPlan != null) { Autodesk.Revit.DB.ViewSheet curViewSheet = createViewSheet(curDesignOptionInfo.Item5, curDesignOptionInfo.Item6, requestData.titleBlockName); if (curViewSheet != null) { SetViewForSheet(curViewPlan, curViewSheet, curScale); } } } catch (Exception ex) { TaskDialog.Show("Excepion", ex.Message + " " + curDesignOptionInfo.Item4); } } } } }
private bool updatePositions(Autodesk.Revit.DB.ViewSheet curViewSheet) { Autodesk.Revit.DB.XYZ norXYZ = null; Autodesk.Revit.DB.XYZ deltaXYZ = null; Autodesk.Revit.DB.ElementId deltaViewportId = null; if (curViewSheet != null) { ICollection <ElementId> curViewportsIdsCollection = curViewSheet.GetAllViewports(); foreach (ElementId curViewportId in curViewportsIdsCollection) { if (this.selViewportsIdsAndPositions.ContainsKey(curViewportId)) { Autodesk.Revit.DB.Viewport curViewport = doc.GetElement(curViewportId) as Autodesk.Revit.DB.Viewport; if (curViewport != null) { norXYZ = curViewport.GetBoxCenter(); Autodesk.Revit.DB.XYZ preXYZ = this.selViewportsIdsAndPositions[curViewportId]; Autodesk.Revit.DB.XYZ curXYZ = curViewport.GetBoxCenter(); if ((curXYZ.X != preXYZ.X) || (curXYZ.Y != preXYZ.Y) || (curXYZ.Z != preXYZ.Z)) { deltaViewportId = curViewportId; deltaXYZ = new XYZ((curXYZ.X - preXYZ.X), (curXYZ.Y - preXYZ.Y), (curXYZ.Z - preXYZ.Z)); break; } } } } } if ((deltaXYZ != null) && (deltaViewportId != null)) { List <ElementId> viewportIds = new List <ElementId>(this.selViewportsIdsAndPositions.Keys); PageAlignmentToolRequestHandler handler = new PageAlignmentToolRequestHandler(norXYZ, deltaViewportId, viewportIds); ExternalEvent exEvent = ExternalEvent.Create(handler); exEvent.Raise(); return(true); } return(false); }
private List <Autodesk.Revit.DB.ViewSheet> getSheetsByViewScale(int selScale) { List <Autodesk.Revit.DB.ViewSheet> selSheets = new List <Autodesk.Revit.DB.ViewSheet>(); FilteredElementCollector docFilter = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.ViewSheet)); if (docFilter != null) { FilteredElementIterator docFilterIterator = docFilter.GetElementIterator(); while (docFilterIterator.MoveNext()) { Autodesk.Revit.DB.ViewSheet curViewSheet = docFilterIterator.Current as Autodesk.Revit.DB.ViewSheet; if (curViewSheet != null) { bool sheetHasSelectedScale = false; ISet <ElementId> curViewSheetViews = curViewSheet.GetAllPlacedViews(); foreach (ElementId curElementId in curViewSheetViews) { Autodesk.Revit.DB.View curView = doc.GetElement(curElementId) as Autodesk.Revit.DB.View; if (curView != null) { if (curView.Scale == selScale) { sheetHasSelectedScale = true; break; } } } if (sheetHasSelectedScale) { selSheets.Add(curViewSheet); } } } } return(selSheets); }
private HashSet <string> GetExistingSheetsNumbers() { HashSet <string> sheetsNumbers = new HashSet <string>(); FilteredElementCollector docFilter = new FilteredElementCollector(doc); if (docFilter != null) { FilteredElementIterator sheetsIterator = docFilter.OfClass(typeof(Autodesk.Revit.DB.ViewSheet)).GetElementIterator(); while (sheetsIterator.MoveNext()) { Autodesk.Revit.DB.ViewSheet curViewSheet = sheetsIterator.Current as Autodesk.Revit.DB.ViewSheet; if (curViewSheet != null) { sheetsNumbers.Add(curViewSheet.SheetNumber); } } } return(sheetsNumbers); }
private List <Tuple <string, string, string> > GetExistingViewSheetsInfos() { List <Tuple <string, string, string> > infos = new List <Tuple <string, string, string> >(); FilteredElementCollector docFilter = new FilteredElementCollector(doc); if (docFilter != null) { FilteredElementIterator viewsheetsIterator = docFilter.OfClass(typeof(Autodesk.Revit.DB.ViewSheet)).GetElementIterator(); while (viewsheetsIterator.MoveNext()) { Autodesk.Revit.DB.ViewSheet curViewSheet = viewsheetsIterator.Current as Autodesk.Revit.DB.ViewSheet; if (curViewSheet != null) { string attachedViewName = ""; ISet <ElementId> subViews = curViewSheet.GetAllPlacedViews(); if (subViews.Count() > 0) { ElementId curSubViewId = subViews.ElementAt(0); if (curSubViewId != null) { Autodesk.Revit.DB.View attachedView = doc.GetElement(curSubViewId) as Autodesk.Revit.DB.View; if (attachedView != null) { attachedViewName = attachedView.Name; } } } Tuple <string, string, string> norInfo = new Tuple <string, string, string>(curViewSheet.SheetNumber, curViewSheet.Name, attachedViewName); infos.Add(norInfo); } } } return(infos); }
public static Dictionary <string, object> GetViewportsAndViews(global::Revit.Elements.Views.Sheet sheet, [DefaultArgument("Rhythm.Revit.Elements.Sheet.CurrentDocument()")] Autodesk.Revit.DB.Document doc) { Autodesk.Revit.DB.ViewSheet viewSheet = (Autodesk.Revit.DB.ViewSheet)sheet.InternalElement; //obtains the viewports from the given sheet var viewportIds = viewSheet.GetAllViewports(); List <global::Revit.Elements.Element> viewports = new List <global::Revit.Elements.Element>(viewportIds.Select(id => doc.GetElement(id).ToDSType(true)).ToArray()); //obtains the views from the given sheet List <global::Revit.Elements.Element> views = new List <global::Revit.Elements.Element>(viewports.Select(v => doc.GetElement(((Autodesk.Revit.DB.Viewport)v.InternalElement).ViewId).ToDSType(true)).ToArray()); //obtains the schedules from the sheet FilteredElementCollector scheduleCollector = new FilteredElementCollector(doc, viewSheet.Id).OfCategory(BuiltInCategory.OST_ScheduleGraphics); var schedulesInternal = scheduleCollector.ToElements(); List <global::Revit.Elements.Element> schedules = new List <global::Revit.Elements.Element>(schedulesInternal.Select(s => s.ToDSType(true)).ToArray()); //returns the outputs7 var outInfo = new Dictionary <string, object> { { "viewports", viewports }, { "views", views }, { "schedules", schedules } }; return(outInfo); }
public static Sheet Wrap(Autodesk.Revit.DB.ViewSheet view, bool isRevitOwned) { return(Sheet.FromExisting(view, isRevitOwned)); }
/// <summary> /// Initialize a Sheet element /// </summary> private void InitSheet(Autodesk.Revit.DB.ViewSheet view) { InternalSetViewSheet(view); }
internal static List <revitViewport> _renumberViewsOnSheet(FamilyType familyType, string xGridName, string yGridName, revitSheet rSheet, revitDoc document) { string transactionName = "Renumber views on sheet"; // Initialize variables revitFamilySymbol rFamilySymbol = (revitFamilySymbol)familyType.InternalElement; // Get all viewport ID's on the sheet. List <revitElemId> viewportIds = (List <revitElemId>)rSheet.GetAllViewports(); List <revitViewport> viewports = null; // Get the family Instances in view revitElemId symbolId = familyType.InternalElement.Id; revitCollector collector = new revitCollector(document, rSheet.Id); revitElementFilter filterInstance = new revitDB.FamilyInstanceFilter(document, symbolId); collector.OfClass(typeof(revitDB.FamilyInstance)).WherePasses(filterInstance); revitDB.FamilyInstance originFamily = (revitDB.FamilyInstance)collector.FirstElement(); // If family instance is found in the view // Then renumber views. if (originFamily != null) { revitDB.LocationPoint location = (revitDB.LocationPoint)originFamily.Location; revitXYZ originPoint = location.Point; double gridX = rFamilySymbol.LookupParameter(xGridName).AsDouble(); double gridY = rFamilySymbol.LookupParameter(yGridName).AsDouble(); // If the document is modifieable, // then a transaction is already open // and function uses the Dynamo Transaction Manager. // Else, open a new transaction. if (document.IsModifiable) { TransactionManager.Instance.EnsureInTransaction(document); viewports = View._tempRenumberViewports(viewportIds, document); viewports = View._renumberViewports(viewports, gridX, gridY, originPoint.X, originPoint.Y); TransactionManager.Instance.TransactionTaskDone(); } else { using (Autodesk.Revit.DB.Transaction trans = new Autodesk.Revit.DB.Transaction(document)) { trans.Start(transactionName); viewports = View._tempRenumberViewports(viewportIds, document); viewports = View._renumberViewports(viewports, gridX, gridY, originPoint.X, originPoint.Y); trans.Commit(); } } } return(viewports); }
/// <summary> /// Private constructor /// </summary> private Sheet(Autodesk.Revit.DB.ViewSheet view) { SafeInit(() => InitSheet(view)); }
/// <summary> /// Set the InternalViewSheet property and the associated element id and unique id /// </summary> /// <param name="floor"></param> private void InternalSetViewSheet(Autodesk.Revit.DB.ViewSheet floor) { this.InternalViewSheet = floor; this.InternalElementId = floor.Id; this.InternalUniqueId = floor.UniqueId; }
public override Value Evaluate(FSharpList <Value> args) { var name = ((Value.String)args[0]).Item; var number = ((Value.String)args[1]).Item; var tb = (FamilySymbol)((Value.Container)args[2]).Item; if (!args[3].IsList) { throw new Exception("The views input must be a list of views."); } var views = ((Value.List)args[3]).Item; Autodesk.Revit.DB.ViewSheet sheet = null; if (this.Elements.Any()) { if (dynUtils.TryGetElement(this.Elements[0], out sheet)) { if (sheet.Name != null && sheet.Name != name) { sheet.Name = name; } if (number != null && sheet.SheetNumber != number) { sheet.SheetNumber = number; } } else { //create a new view sheet sheet = Autodesk.Revit.DB.ViewSheet.Create(dynRevitSettings.Doc.Document, tb.Id); sheet.Name = name; sheet.SheetNumber = number; Elements[0] = sheet.Id; } } else { sheet = Autodesk.Revit.DB.ViewSheet.Create(dynRevitSettings.Doc.Document, tb.Id); sheet.Name = name; sheet.SheetNumber = number; Elements.Add(sheet.Id); } //rearrange views on sheets //first clear the collection of views on the sheet //sheet.Views.Clear(); var width = sheet.Outline.Max.U - sheet.Outline.Min.U; var height = sheet.Outline.Max.V - sheet.Outline.Min.V; var packer = new CygonRectanglePacker(width, height); foreach (var val in views) { var view = (View)((Value.Container)val).Item; var viewWidth = view.Outline.Max.U - view.Outline.Min.U; var viewHeight = view.Outline.Max.V - view.Outline.Min.V; UV placement = null; if (packer.TryPack(viewWidth, viewHeight, out placement)) { if (sheet.Views.Contains(view)) { //move the view //find the corresponding viewport var collector = new FilteredElementCollector(dynRevitSettings.Doc.Document); collector.OfClass(typeof(Viewport)); var found = collector.ToElements() .Cast <Viewport>() .Where(x => x.SheetId == sheet.Id && x.ViewId == view.Id); var enumerable = found as Viewport[] ?? found.ToArray(); if (!enumerable.Any()) { continue; } var viewport = enumerable.First(); viewport.SetBoxCenter(new XYZ(placement.U + viewWidth / 2, placement.V + viewHeight / 2, 0)); } else { //place the view on the sheet if (Viewport.CanAddViewToSheet(dynRevitSettings.Doc.Document, sheet.Id, view.Id)) { var viewport = Viewport.Create(dynRevitSettings.Doc.Document, sheet.Id, view.Id, new XYZ(placement.U + viewWidth / 2, placement.V + viewHeight / 2, 0)); } } } else { throw new Exception("View could not be packed on sheet."); } } return(Value.NewContainer(sheet)); }
//****************************************************************************************** /// <summary> /// this function export View from the list /// </summary> public List <ViewPath> Export(List <View> argListView, DWGExportOptions setDwg, IREXProgress argProgress) { IREXProgress Progress = argProgress; Progress.Steps = 2 * argListView.Count; Progress.Position = 0; Progress.Header = Resources.Strings.Texts.FreezeInProgress + " - " + Resources.Strings.Texts.Export; List <ViewPath> nameStr = new List <ViewPath>(); m_path = getTempPath(); //reading files from temp directory setDwg.LayerMapping = GetLayMap(setDwg.LayerMapping); foreach (View v in argListView) { List <ElementId> vSet = new List <ElementId>(); if (v != null) { View3D tmp3D = null; Autodesk.Revit.DB.ViewSheet viewSheet = null; bool proceed = false; if (v is Autodesk.Revit.DB.View3D) { try { FilteredElementCollector filteredElementCollector = new FilteredElementCollector(ThisExtension.Revit.ActiveDocument); filteredElementCollector.OfClass(typeof(FamilySymbol)); filteredElementCollector.OfCategory(BuiltInCategory.OST_TitleBlocks); IList <RevitElement> titleBlocks = filteredElementCollector.ToElements(); List <FamilySymbol> familySymbols = new List <FamilySymbol>(); foreach (Element element in titleBlocks) { FamilySymbol f = element as FamilySymbol; if (f != null) { familySymbols.Add(f); } } if (titleBlocks.Count != 0) { Autodesk.Revit.DB.FamilySymbol fs = null; foreach (Autodesk.Revit.DB.FamilySymbol f in familySymbols) { if (null != f) { fs = f; break; } } viewSheet = Autodesk.Revit.DB.ViewSheet.Create(ThisExtension.Revit.ActiveDocument, fs.Id); if (null != viewSheet) { UV location = new UV((viewSheet.Outline.Max.U - viewSheet.Outline.Min.U) / 2, (viewSheet.Outline.Max.V - viewSheet.Outline.Min.V) / 2); try { Viewport.Create(ThisExtension.Revit.ActiveDocument, viewSheet.Id, v.Id, new XYZ(location.U, location.V, 0.0)); } catch { try { XYZ tmpXYZ = new XYZ(-v.ViewDirection.X, -v.ViewDirection.Y, -v.ViewDirection.Z); BoundingBoxXYZ tmpBoundingBox = v.CropBox; bool tmpCropBoxActive = v.CropBoxActive; IList <Element> viewTypes = REXGeometryRvt.FilterElements(ThisExtension.Revit.ActiveDocument, typeof(ViewFamilyType)); ElementId viewTypeid = null; foreach (Element viewType in viewTypes) { ViewFamilyType famType = viewType as ViewFamilyType; if (famType != null && famType.ViewFamily == ViewFamily.ThreeDimensional) { viewTypeid = famType.Id; break; } } if (viewTypeid != null) { tmp3D = View3D.CreateIsometric(ThisExtension.Revit.ActiveDocument, viewTypeid); tmp3D.ApplyViewTemplateParameters(v); tmp3D.CropBox = tmpBoundingBox; Viewport.Create(ThisExtension.Revit.ActiveDocument, viewSheet.Id, tmp3D.Id, new XYZ(location.U, location.V, 0.0)); } } catch { } } vSet.Add(viewSheet.Id); proceed = true; } } } catch { } } else { vSet.Add(v.Id); proceed = true; } if (proceed) { string fam = v.get_Parameter(BuiltInParameter.VIEW_FAMILY).AsString(); Progress.Step(fam + "-" + v.Name); string vName = ValidateFileName(v.Name); m_CommandData.Application.ActiveUIDocument.Document.Export(m_path, fam + "-" + vName, vSet, setDwg); nameStr.Add(new ViewPath(m_path + "\\" + fam + "-" + vName + ".dwg", v, fam + "-" + v.Name)); Progress.Step(fam + "-" + v.Name); if (viewSheet != null) { ElementId elementId = viewSheet.Id; ThisExtension.Revit.ActiveDocument.Delete(elementId); } if (tmp3D != null) { ElementId elementId = tmp3D.Id; ThisExtension.Revit.ActiveDocument.Delete(elementId); } } } } return(nameStr); }
/// <summary> /// Returns the percentage number of gridlines dimensioned in the drawing. If all gridlines are dimensioned the value should be 100%. /// </summary> /// <param name="sheets">sheets to check</param> /// <returns name="results">count of datums in each sheet</returns> /// <search> /// mace, structural, general, arrangement, drawing, datum, count, number /// </search> public static object PercentageOfDimensionedGridlines(Revit.Elements.Views.Sheet sheets) { Document doc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument; Autodesk.Revit.DB.Element unwrappedSheet = sheets.InternalElement; BuiltInCategory dimCat = BuiltInCategory.OST_Dimensions; BuiltInCategory gridCat = BuiltInCategory.OST_Grids; //Get views on sheet Autodesk.Revit.DB.ViewSheet viewSheet = unwrappedSheet as Autodesk.Revit.DB.ViewSheet; List <ElementId> viewIds = viewSheet.GetAllPlacedViews().ToList(); ElementId viewId = viewIds[0]; FilteredElementCollector dimElements = new FilteredElementCollector(doc, viewId).OfCategory(dimCat).WhereElementIsNotElementType(); FilteredElementCollector gridElements = new FilteredElementCollector(doc, viewId).OfCategory(gridCat).WhereElementIsNotElementType(); List <Autodesk.Revit.DB.Dimension> dimList = new List <Autodesk.Revit.DB.Dimension>(); foreach (Autodesk.Revit.DB.Dimension dim in dimElements) { dimList.Add(dim as Autodesk.Revit.DB.Dimension); } List <int> gridList = new List <int>(); foreach (Autodesk.Revit.DB.Element grid in gridElements) { gridList.Add(grid.Id.IntegerValue); } List <int> dimRefs = new List <int>(); foreach (Autodesk.Revit.DB.Dimension d in dimList) { ReferenceArray refArray = d.References; int size = refArray.Size; RevitServices.Transactions.TransactionManager.Instance.EnsureInTransaction(doc); for (int i = 0; i < size; i++) { Reference _ref = refArray.get_Item(i); ElementId id = _ref.ElementId; //Autodesk.Revit.DB.Element revitElement = doc.GetElement(id); dimRefs.Add(id.IntegerValue); } } List <int> uniqueIds = new HashSet <int>(dimRefs).ToList(); List <bool> bools = new List <bool>(); foreach (int id in gridList) { if (uniqueIds.Contains(id)) { bools.Add(true); } else { bools.Add(false); } } double countTrue = bools.Where(c => c).Count(); double countTotal = bools.Count(); double num = (countTrue / countTotal) * 100; decimal dec = System.Convert.ToDecimal(num); decimal round = System.Math.Round(dec, 1); string output = sheets.SheetNumber.ToString() + " - " + sheets.SheetName.ToString() + " = " + round.ToString() + "%"; return(output); }