g = UnwrapElement(IN[0])
TransactionManager.Instance.EnsureInTransaction(doc)
g_curve = [c for c in g.GetCurvesInView(DatumExtentType.ViewSpecific, doc.ActiveView)][0]
direct = g_curve.Direction
start = g_curve.GetEndPoint(0)
end = g_curve.GetEndPoint(1)
mock_shift = 3 # an imperial value for testing, you can trim with the other grid for sure
g.SetCurveInView(DatumExtentType.ViewSpecific, doc.ActiveView, Line.CreateBound(start, end.Subtract(direct.Multiply(mock_shift))))
TransactionManager.Instance.TransactionTaskDone()
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
def toList(input):
"""Ensures input is a list of valid Revit elements"""
if isinstance(input, list):
return [UnwrapElement(i) for i in input if UnwrapElement(i) is not None]
else:
return [UnwrapElement(input)] if UnwrapElement(input) is not None else []
# Ensure g is always a list
g = toList(IN[0])
if not g or not all(isinstance(grid, Grid) for grid in g):
OUT = "Invalid input: Expected a list of Grid elements."
else:
TransactionManager.Instance.EnsureInTransaction(doc)
for grid in g:
# Get the grid curve in the active view
g_curve = next((c for c in grid.GetCurvesInView(DatumExtentType.ViewSpecific, doc.ActiveView)), None)
if g_curve:
start = g_curve.GetEndPoint(0)
end = g_curve.GetEndPoint(1)
# Modify only the Y-coordinates
new_start = XYZ(start.X, start.Y + 50, start.Z)
new_end = XYZ(end.X, end.Y + 50, end.Z)
# Create the new shifted line
new_curve = Line.CreateBound(new_start, new_end)
grid.SetCurveInView(DatumExtentType.ViewSpecific, doc.ActiveView, new_curve)
TransactionManager.Instance.TransactionTaskDone()
OUT = g # Output modified grids
So it works for a nice horizontal or vertical grid…
you should factor in the direction of the grid curve as I demonstrated. Move start and end points only along the direction (or its negation) of the curve.