I have been trying to place the GTP point family on grid intersection points, specifically the Control Pt. I have gotten the right intersection locations but my issue is getting a transaction to work, there aren’t any errors and I have added print statements to make sure the code is actually reaching the parameters I want to set. I have gotten them to work in the past and I can’t see a problem with what I have in my code now.
This is my code as a whole, below it I will paste the actual area where I am running into my issue.
'''This tool is used for adding points on gridline intersections and if a gridline moves this tool will take care of the original GTP point and add a new one where the grid intersection moved to.\n\nAuthor: Cameron Adams'''
__title__ = 'Grid Point\nIntersection'
import clr
import os
import csv
# Adding references
clr.AddReference('System.Windows.Forms')
clr.AddReference('IronPython.Wpf')
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
clr.AddReference('RevitServices')
# Importing necessary modules
from getpass import getuser
import re
from pyrevit import script
from pyrevit import revit, DB
from Autodesk.Revit.DB import FilteredElementCollector, FamilySymbol, Family, ViewPlan
from Autodesk.Revit.DB import ElementId, Transaction, XYZ, FamilyInstance, BuiltInCategory, Level
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.Revit.UI import UIApplication
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI.Selection import ObjectType
# Find the path of ui.xaml
xamlfile = script.get_bundle_file('ui.xaml')
# Import WPF creator and base window
import wpf
from System import Windows
from System.Windows.Controls import CheckBox
# Use the __revit__ variable provided by pyRevit to get the current application and document
uiapp = __revit__
uidoc = uiapp.ActiveUIDocument
doc = uidoc.Document
def find_pt_number():
collector = FilteredElementCollector(doc).OfClass(FamilyInstance).OfCategory(BuiltInCategory.OST_GenericModel)
lst = []
int_lst = []
for element in collector:
family = element.Symbol.Family
if family.Name == "GTP":
if element.SuperComponent:
params = element.SuperComponent.Parameters
for param in params:
if param.AsString() != '' and param.AsString() != None:
if 'PointNumber' in param.AsString():
if element.SuperComponent.LookupParameter(param.AsString()).AsString() != '':
lst.append(element.SuperComponent.LookupParameter(param.AsString()).AsString())
else:
if element.LookupParameter('PointNumber').AsString() != '' and element.LookupParameter('PointNumber').AsString() != None:
lst.append(element.LookupParameter('PointNumber').AsString())
if len(lst) == 0:
count = 999
elif len(lst) == 1:
count = int(lst[0][-4:])
else:
for val in lst:
int_lst.append(int(val[-4:]))
count = max(int_lst)
return count + 1
def return_minmax(val1, val2):
if val1 > val2:
maxval = val1
minval = val2
elif val2 > val1:
maxval = val2
minval = val1
else:
print('minval and maxval and equal')
return minval, maxval
def main():
current_view = doc.ActiveView
grid_collector = FilteredElementCollector(doc).OfClass(Grid).OfCategory(BuiltInCategory.OST_Grids)
collector = FilteredElementCollector(doc).OfClass(FamilyInstance).OfCategory(BuiltInCategory.OST_GenericModel)
elevation = current_view.GenLevel.Elevation
y_direction = []
x_direction = []
family_name = 'GTP'
point_description = 'GRID INTERSECTION'
lst = []
for f in FilteredElementCollector(doc).OfClass(Family):
if f.Name == "GTP":
si = f.GetFamilySymbolIds()
for val in si:
lst.append(val.IntegerValue)
family_symbol = doc.GetElement(ElementId(lst[7]))
sloped_line_lst = []
boundary_x = []
boundary_y = []
line_lst = []
for val in grid_collector:
if val.Curve.GetEndPoint(0).X > val.Curve.GetEndPoint(1).X and val.Curve.GetEndPoint(0).Y != val.Curve.GetEndPoint(1).Y:
x1, y1 = val.Curve.GetEndPoint(0).X, val.Curve.GetEndPoint(0).Y
x2, y2 = val.Curve.GetEndPoint(1).X, val.Curve.GetEndPoint(1).Y
elif val.Curve.GetEndPoint(0).X < val.Curve.GetEndPoint(1).X and val.Curve.GetEndPoint(0).Y != val.Curve.GetEndPoint(1).Y:
x1, y1 = val.Curve.GetEndPoint(1).X, val.Curve.GetEndPoint(1).Y
x2, y2 = val.Curve.GetEndPoint(0).X, val.Curve.GetEndPoint(0).Y
elif val.Curve.GetEndPoint(0).X == val.Curve.GetEndPoint(1).X:
if val.Curve.GetEndPoint(0).Y > val.Curve.GetEndPoint(1).Y:
x1, y1 = val.Curve.GetEndPoint(0).X, val.Curve.GetEndPoint(0).Y
x2, y2 = val.Curve.GetEndPoint(1).X, val.Curve.GetEndPoint(1).Y
else:
x1, y1 = val.Curve.GetEndPoint(1).X, val.Curve.GetEndPoint(1).Y
x2, y2 = val.Curve.GetEndPoint(0).X, val.Curve.GetEndPoint(0).Y
elif val.Curve.GetEndPoint(0).Y == val.Curve.GetEndPoint(1).Y:
if val.Curve.GetEndPoint(0).X > val.Curve.GetEndPoint(1).X:
x1, y1 = val.Curve.GetEndPoint(0).X, val.Curve.GetEndPoint(0).Y
x2, y2 = val.Curve.GetEndPoint(1).X, val.Curve.GetEndPoint(1).Y
else:
x1, y1 = val.Curve.GetEndPoint(1).X, val.Curve.GetEndPoint(1).Y
x2, y2 = val.Curve.GetEndPoint(0).X, val.Curve.GetEndPoint(0).Y
line_lst.append((x1,y1,x2,y2,val.Name, val.Curve.GetEndPoint(0), val.Curve.GetEndPoint(1)))
location_lst = []
xy_lst = []
for a in line_lst:
for b in line_lst:
xy = (a,b)
slope_a = (a[3]-a[1])/(a[2]-a[0])
slope_b = (b[3]-b[1])/(b[2]-b[0])
if a != b and slope_a != slope_b:
if xy not in xy_lst and (xy[1],xy[0]) not in xy_lst:
x1,y1,x2,y2,x3,y3,x4,y4 = a[0],a[1],a[2],a[3],b[0],b[1],b[2],b[3]
numer = (x1-x3)*(y3-y4) - (y1-y3)*(x3-x4)
denom = (x1-x2)*(y3-y4) - (y1-y2)*(x3-x4)
t = numer/denom
px = x1 + t*(x2-x1)
py = y1 + t*(y2-y1)
xy_lst.append((a,b))
minx1, maxx2 = return_minmax(x1,x2)
minx3, maxx4 = return_minmax(x3,x4)
miny1, maxy2 = return_minmax(y1,y2)
miny3, maxy4 = return_minmax(y3,y4)
if minx1 <= px <= maxx2 and minx3 <= px <= maxx4 and miny1 <= py <= maxy2 and miny3 <= py <= maxy4:
location_lst.append((px,py,a[4],b[4]))
if not family_symbol.IsActive:
with Transaction(revit.doc, "activate family") as t:
t.Start()
family_symbol.Activate()
t.Commit()
fixed_lst = []
temp_lst = []
for point in location_lst:
for element in collector:
if element.Symbol.Family.Name == 'GTP':
location = element.Location.Point
temp_lst.append((location.X,location.Y))
for point in location_lst:
if (point[0],point[1]) not in temp_lst:
fixed_lst.append(point)
for pos in fixed_lst:
insertion_point = XYZ(pos[0], pos[1], 0)
with Transaction(revit.doc, "place gtp point") as T:
count = find_pt_number()
T.Start()
family_instance = doc.Create.NewFamilyInstance(insertion_point, family_symbol, DB.Structure.StructuralType.NonStructural)
pt_desc = str(pos[2]) + '-' + str(pos[3]) + '_' + point_description
family_instance.LookupParameter("PointDeviationX").Set(pos[0])
family_instance.LookupParameter("PointDeviationY").Set(pos[1])
family_instance.LookupParameter("PointDeviationZ").Set(elevation)
family_instance.LookupParameter("PointDescription").Set(pt_desc)
family_instance.LookupParameter("PointRole").Set("Control Point")
family_instance.LookupParameter("PointNumber").Set('GP' + str(count))
T.Commit()
t = Transaction(doc, "delete error grid GTP points")
delete_lst = []
for element in collector:
family = element.Symbol.Family
if family.Name == 'GTP':
location = element.Location.Point
if (location.X, location.Y) not in location_lst and 'GRID INTERSECTION' in element.LookupParameter("PointDescription").AsString():
delete_lst.append(element.Id)
for val in delete_lst:
t.Start()
doc.Delete(val)
t.Commit()
if __name__ == "__main__":
main()
This is the area where the transaction isn’t having any errors but isn’t actually pasting a GTP point.
for pos in fixed_lst:
insertion_point = XYZ(pos[0], pos[1], 0)
with Transaction(revit.doc, "place gtp point") as T:
count = find_pt_number()
T.Start()
family_instance = doc.Create.NewFamilyInstance(insertion_point, family_symbol, DB.Structure.StructuralType.NonStructural)
pt_desc = str(pos[2]) + '-' + str(pos[3]) + '_' + point_description
family_instance.LookupParameter("PointDeviationX").Set(pos[0])
family_instance.LookupParameter("PointDeviationY").Set(pos[1])
family_instance.LookupParameter("PointDeviationZ").Set(elevation)
family_instance.LookupParameter("PointDescription").Set(pt_desc)
family_instance.LookupParameter("PointRole").Set("Control Point")
family_instance.LookupParameter("PointNumber").Set('GP' + str(count))
T.Commit()