# Change Revit Grid Extents

**URL:** <https://forum.dynamobim.com/t/change-revit-grid-extents/22991>\
**Category:** Revit\
**Tags:** dynamo\
**Created:** [June 21, 2018, 8:26am UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991 "2018-06-21T08:26:55Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![dongthl](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dongthl/32/42176_2.png) [@dongthl](https://forum.dynamobim.com/u/dongthl)\
**Post date:** [June 21, 2018, 8:26am UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/1 "2018-06-21T08:26:55Z")

</div>

Hello everyone,

I found a very helpful script from youtupe.  
But it only work in active view.  
Can we improve the script which can modify the grid in multi-selected views.

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [June 21, 2018, 8:50am UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/2 "2018-06-21T08:50:08Z")

</div>

If you upload both the graph and possible python scripts it would go a long way so everyone doesn’t have to reinvent the wheel. 🙂

EDIT:  
Went to the youtube video and found the graph:  
[SetGridExtents01.dyn](https://forum.dynamobim.com/uploads/short-url/yS9WF2PWKl7NzYK1JgfJiXz4yRn.dyn) (29.2 KB)

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/4/34e68d74007e104847488a6034111e90d8836205.png)

I believe the unloaded node is from an old version of spring nodes.

---

<div class="post-metadata">

**Author:** ![Petar\_Penchev1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/petar_penchev1/32/8592_2.png) [@Petar\_Penchev1](https://forum.dynamobim.com/u/Petar_Penchev1)\
**Post date:** [June 21, 2018, 8:54am UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/3 "2018-06-21T08:54:45Z")

</div>

Or use Scope Box = )

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [June 21, 2018, 9:06am UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/4 "2018-06-21T09:06:04Z")

</div>

My guess is that you should simply input another view that is not the activeview (red node in my previous post).

---

<div class="post-metadata">

**Author:** ![dongthl](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dongthl/32/42176_2.png) [@dongthl](https://forum.dynamobim.com/u/dongthl)\
**Post date:** [June 21, 2018, 9:06am UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/5 "2018-06-21T09:06:26Z")

</div>

Thank you!  
I have to change some old node to get it to work on the active view  
First python script is to get grid length

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

grids = UnwrapElement(IN[0])
view = UnwrapElement(IN[1])

gridCurves = []
curves = []

for g in grids:
	gridCurves.append(g.GetCurvesInView(DatumExtentType.Model, view))

for i in range(0,len(gridCurves)):
	for c in gridCurves[i]:
		start = c.GetEndPoint(0)
		end = c.GetEndPoint(1)
		curves.append(Line.CreateBound(start,end).ToProtoType())

#Assign your outputs to the OUT variable
OUT = curves

```

And the last script is for setting grid lines

> import clr  
> clr.AddReference(‘ProtoGeometry’)  
> from Autodesk.DesignScript.Geometry import \*
> 
> ```
> # Import DocumentManager and TransactionManager
> clr.AddReference("RevitServices")
> import RevitServices
> from RevitServices.Persistence import DocumentManager
> from RevitServices.Transactions import TransactionManager
> 
> # Import RevitAPI
> clr.AddReference("RevitAPI")
> import Autodesk
> from Autodesk.Revit.DB import *
> 
> clr.AddReference("RevitNodes")
> import Revit
> clr.ImportExtensions(Revit.GeometryConversion)
> 
> doc = DocumentManager.Instance.CurrentDBDocument
> uiapp = DocumentManager.Instance.CurrentUIApplication
> app = uiapp.Application
> 
> grids = UnwrapElement(IN[0])
> view = UnwrapElement(IN[1])
> crvs = UnwrapElement(IN[2])
> 
> curves = []
> curvesViews = []
> 
> TransactionManager.Instance.EnsureInTransaction(doc)
> 
> for i in range(0,len(grids)):	
> grids[i].SetCurveInView(DatumExtentType.ViewSpecific,view,crvs[i])
> 
> TransactionManager.Instance.TransactionTaskDone()
> 	
> 
> 	
> #Assign your outputs to the OUT variable
> OUT = grids
> 
> ```

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [June 21, 2018, 9:09am UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/6 "2018-06-21T09:09:21Z")

</div>

If you wish to run on several views either you can pack the graph into a custom node and use that functionality. Otherwise you have to rewrite the python to take multiple views (using for loops).

---

<div class="post-metadata">

**Author:** ![dongthl](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dongthl/32/42176_2.png) [@dongthl](https://forum.dynamobim.com/u/dongthl)\
**Post date:** [June 21, 2018, 10:05am UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/7 "2018-06-21T10:05:33Z")

</div>

Thank you!

Finally work!  
I will mark this post solved.

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/5/b5581b4b800fb27f71b66da5682a9e03e6304e41.png)[SetGridExtents.dyn](https://forum.dynamobim.com/uploads/short-url/lMiLW7sLRE39Zt0qRXrQwzdEpre.dyn) (75.8 KB)

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [June 21, 2018, 10:07am UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/8 "2018-06-21T10:07:09Z")

</div>

You should post the graph as well in your solution as it is not possible to see what is going on in your graph and there is for sure some python in there 😉

For anyone interested the graph by @dongthl is for Dynamo 2.0, so it will not be applicable for people who have not yet updated 🙂

---

<div class="post-metadata">

**Author:** ![mscottM6C4C](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@mscottM6C4C](https://forum.dynamobim.com/u/mscottM6C4C)\
**Post date:** [November 16, 2018, 6:53pm UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/9 "2018-11-16T18:53:22Z")

</div>

When I try to open this definition, I get errors. Even in Dynamo 2.0 i get errors. Can you post a clear picture of this definition?

---

<div class="post-metadata">

**Author:** ![CHANDU](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/chandu/32/169017_2.png) [@CHANDU](https://forum.dynamobim.com/u/CHANDU)\
**Post date:** [September 30, 2020, 4:46pm UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/10 "2020-09-30T16:46:45Z")

</div>

@dongthl…Hi…Can you please post a small video running the script as it may help the community a lot…Thank you

---

<div class="post-metadata">

**Author:** ![ali.tehami](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ali.tehami/32/72384_2.png) [@ali.tehami](https://forum.dynamobim.com/u/ali.tehami)\
**Post date:** [November 25, 2020, 6:14am UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/11 "2020-11-25T06:14:46Z")

</div>

Many thanks to all for the great conversation, I’ve refined and recreated a script that puts everything in the discussion here together (and a few more features like Grids Bubbles manipulation) with a Dynamo player UI (Revit 2020.2 + Dynamo 2.3):

 ![ATnodes_Fit Grids to Viewport Crop Region](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/6/660d35af9dd800526514857402915eed963afe12.jpeg)

You can find the script in the repo below ( [ATnodes\_Fit Grids to Viewport Crop Region.dyn](https://github.com/alitehami/ATnodes-DynamoRevit/blob/main/scripts/ATnodes_Fit%20Grids%20to%20Viewport%20Crop%20Region.dyn))

[https://github.com/alitehami/ATnodes-DynamoRevit/tree/main/scripts](https://github.com/alitehami/ATnodes-DynamoRevit/tree/main/scripts)

Enjoy ~  
Ali T.

---

<div class="post-metadata">

**Author:** ![EC\_EMA](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@EC\_EMA](https://forum.dynamobim.com/u/EC_EMA)\
**Post date:** [December 4, 2020, 10:21am UTC](https://forum.dynamobim.com/t/change-revit-grid-extents/22991/12 "2020-12-04T10:21:05Z")

</div>

Hi @ali.tehami,  
Thank you a lot for your work, it’s awesome!

I tried to adapt it to work with a list of multiple views (the final goal is to make it work on all views in the project), but it does not seem to work as well as expected…

To make it work, I “broke” your custom nodes to take it directly in the main graph. Then I made some modifications in the python script in the “@All Elements of Category in View” to accept a list of views, and to treat it one by one. The modified script filters the list of views to keep only the ones that have grids on them (to avoid an error if there is no grids to work on).

The graph works this way, but acts only on the last view of the list, and I don’t understand why…

Translation of the watch nodes, after the python script :

- Toutes les vues en entrée du script = All views in IN[1] of the script
- Toutes les vues traitées = All views that should be treated

Would it be ok for you to help me make it work?

You will find an image and my graph in attachement.

Thank you,  
Etienne

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/1/5138324b910f0d70f2e5ac0273ef7269cf1492a2.png) [GEN\_Ajuster\_Quadrillage\_a\_cadrage\_TOUTES\_vues\_DYN2-6-1.dyn](https://forum.dynamobim.com/uploads/short-url/1d0w6F9VDbOy1fenlLR2h3QRp8s.dyn) (121.8 KB)
