Hi,
I'm trying to make a python script to auto-tag all doors and place them without clashing with other tags or doors . I'm using a custom smart tag which is much bigger than typical door tag. I hope to use this concept with other types of tagging.
Issue i'm having is that I cannot get the tag location to verify against list of points to avoid. and also to add the new tag location to the list so that the next tag does not clash with the previous.
I think the problem is the list of location to avoid is not properly updating and it's not correctly checking against it.
Any help would be appreciated.
Thanks
doorFiltered = list of doors
TagSymbols = custom smart tag
import clr
clr.AddReference('System')
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")
clr.AddReference("RevitAPI")
clr.AddReference('RevitAPIUI')
clr.AddReference("System.Collections")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit import DB
from pyrevit import forms, revit, DB, script
from itertools import compress
from operator import itemgetter, attrgetter
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
scaleFactor = 5
def move_right(x,y,z):
n = scaleFactor
return x+n, y, z
def move_down(x,y,z):
n = scaleFactor
return x,y-n,z
def move_left(x,y,z):
n = scaleFactor
return x-n,y,z
def move_up(x,y,z):
n = scaleFactor
return x,y+n,z
moves = [move_right, move_down, move_left, move_up]
def shift(end, point):
from itertools import cycle
_moves = cycle(moves)
n = 1
pos = point
times_to_move = 1
yield pos
while True:
for _ in range(2):
move = next(_moves)
for _ in range(times_to_move):
if n >= end:
return
pos = move(*pos)
n+=1
yield pos
times_to_move+=1
avoidLoc = []
for l in doorFiltered:
avoidLoc.append(l.Location.Point)
for d in doorFiltered:
LP = d.Location
levelPoint = LP.Point
startpoint = (levelPoint.X, levelPoint.Y, levelPoint.Z)
shiftPoint = DB.XYZ(levelPoint.X, levelPoint.Y, levelPoint.Z)
R = Reference(d)
#create door tags
t = Transaction(doc)
t.Start('tag doors')
IT = IndependentTag.Create(doc, v.Id, R, False, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, shiftPoint)
IT.ChangeTypeId(TagSymbols)
#get location of tag
tagBB = IT.get_BoundingBox(doc.GetElement(IT.OwnerViewId))
globalMax = tagBB.Max
globalMin = tagBB.Min
BBloc = XYZ((globalMax.X + globalMin.X)/2, (globalMax.Y + globalMin.Y)/2, globalMax.Z)
tagSize = globalMax.DistanceTo(globalMin)
originalPoint = (BBloc.X, BBloc.Y, BBloc.Z)
#find overlap
requireDist = tagSize*2
overlap = True
counter = 1
while overlap:
spiralPoints = list(shift(counter, startpoint))
newPoint = spiralPoints[-1]
counter += 1
testPoint = DB.XYZ(newPoint[0], newPoint[1], newPoint[2])
for i in avoidLoc:
OriginalPoint = DB.XYZ(newPoint[0], newPoint[1], newPoint[2])
tagDist = OriginalPoint.DistanceTo(i)
movePoint = DB.XYZ((BBloc.X-newPoint[0]), (BBloc.Y-newPoint[1]), (BBloc.Z-newPoint[2]))
#print(tagDist)
if tagDist < requireDist:
overlap = True
#print("overlap")
else:
overlap = False
IT.Location.Move(movePoint)
NtagBB = IT.get_BoundingBox(doc.GetElement(IT.OwnerViewId))
if NtagBB == None:
break
NglobalMax = NtagBB.Max
NglobalMin = NtagBB.Min
NBBloc = XYZ((NglobalMax.X + NglobalMin.X) / 2, (NglobalMax.Y + NglobalMin.Y) / 2, NglobalMax.Z)
avoidLoc.append(NBBloc)
#print(NBBloc)
break
IT.HasLeader = True
#IT.LeaderElbow = DB.XYZ(shiftPoint.X + 10, shiftPoint.Y, shiftPoint.Z)
t.Commit()
Solved! Go to Solution.
Link copied