Set Grids design

Hello everyone , I am trying to set grid leader from linked models grids. I am facing some error with it in live project.
Annotation 2022-10-14 185126
is there any way , that i can do it with dynamo nodes because i am not good at python.

@kapilp7W8RU ,

You have to share your code … … to see how “bad” you are ! :wink:

#paste your bad code here!

let`s see your inputs too, maybe the mistake is in the input!

KR

Andreas

@Draxl_Andreas
Ha ha ha . I am very bad in python :smiley: Actually the script is working properly in normal projects but gets error in live project
here is the code :
Grid design.txt (3.5 KB)

thanks in advance .

kapil

@kapilp7W8RU

#paste it via </>
import clr
import time

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

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
from Revit import GeometryConversion
clr.ImportExtensions(Revit.GeometryReferences)


doc = DocumentManager.Instance.CurrentDBDocument
uiapp=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

view = doc.ActiveView

linkGrid = UnwrapElement(IN[0])
currGrid = UnwrapElement(IN[1])
linkView = UnwrapElement(IN[2])

resGrids = []

gName = []
gExtents = []
gExtents1 = []


TransactionManager.Instance.ForceCloseTransaction()

with Transaction(doc,"Add Leader to grids") as t:
#t = Transaction(doc,"Add Leader to grids")
	t.Start()
	lb=[]
	lb1 = []
	for i in range(len(linkGrid)):
		leaderBase = linkGrid[i].GetLeader(DatumEnds.End1,linkView)
		lb.append(leaderBase)
		if leaderBase != None:
			gExtents.append(leaderBase)
			
			currGrid[i].AddLeader(DatumEnds.End1,view)
				
			resGrids.append(currGrid[i])
		else:
			resGrids.append(currGrid[i])
	
	
	for i in range(len(linkGrid)):
		leaderBase = linkGrid[i].GetLeader(DatumEnds.End0,linkView)
		lb1.append(leaderBase)
		if leaderBase != None:
			gExtents.append(leaderBase)
			
			currGrid[i].AddLeader(DatumEnds.End0,view)
				
			resGrids.append(currGrid[i])
		else:
			resGrids.append(currGrid[i])
	#t.Commit()
	t.Commit()
		
	time.sleep(2)
	#TransactionManager.Instance.ForceCloseTransaction()	
	#TransactionManager.Instance.EnsureInTransaction(doc)
with Transaction(doc,"Set Leader to grids") as t1:	
	t1.Start()
	for i in range(len(linkGrid)):
		leaderBase = linkGrid[i].GetLeader(DatumEnds.End1,linkView)
		if leaderBase != None:
			
			leader = currGrid[i].GetLeader(DatumEnds.End1,view)
			
			anchor = leader.Anchor
			end = leader.End
			elbow = leader.Elbow
			
			distY = (leaderBase.Elbow.Y - leaderBase.End.Y)
			distElbowX = (leaderBase.Elbow.X - leaderBase.End.X)
			distEndX = (leaderBase.End.X - leader.End.X)
			newEnd = (Geometry.Point.ByCoordinates(leaderBase.End.X + distEndX,leader.End.Y,leader.End.Z)).ToXyz()
			newElbow = (Geometry.Point.ByCoordinates(leader.End.X + distEndX + distElbowX, leader.End.Y + distY, leader.Elbow.Z)).ToXyz()
				
			leader.Elbow = newElbow
			leader.End = newEnd
				
			currGrid[i].SetLeader(DatumEnds.End1,view,leader)
		else:
			continue	
	


	for i in range(len(linkGrid)):
		leaderBase = linkGrid[i].GetLeader(DatumEnds.End0,linkView)
		if leaderBase != None:
			
			leader = currGrid[i].GetLeader(DatumEnds.End0,view)
			
			anchor = leader.Anchor
			end = leader.End
			elbow = leader.Elbow
			
			distY = (leaderBase.Elbow.Y - leaderBase.End.Y)
			distElbowX = (leaderBase.Elbow.X - leaderBase.End.X)
			distEndX = (leaderBase.End.X - leader.End.X)
			newEnd = (Geometry.Point.ByCoordinates(leaderBase.End.X + distEndX,leader.End.Y,leader.End.Z)).ToXyz()
			newElbow = (Geometry.Point.ByCoordinates(leader.End.X + distEndX + distElbowX, leader.End.Y + distY, leader.Elbow.Z)).ToXyz()
				
			leader.Elbow = newElbow
			leader.End = newEnd
				
			currGrid[i].SetLeader(DatumEnds.End0,view,leader)
		else:
			continue		
	
				
	t1.Commit()
#TransactionManager.Instance.TransactionTaskDone()
OUT="success"

Hey @Draxl_Andreas
I am new here, i did not know that.
is this code is working now ?