It seems that you are transcribing a Dynamo 2.x script to Dynamo 1.3 for Revit 2016. The script includes a code snippet that uses the IndependentTag.Create() method from the Revit 2019 API. You have adapted the code to use the Autodesk.Revit.Creation.Document.NewTag() method from the Revit 2016 API.
However, when you run the adapted code in Dynamo:
import clr
from math import floor
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
app = DocumentManager.Instance.CurrentUIApplication.Application
uiapp = DocumentManager.Instance.CurrentUIApplication
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.DB import *
from Autodesk.Revit.Creation import *
import Autodesk.Revit.DB as DB
import Autodesk.Revit.Creation as Create
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('ProtoGeometry')
import Autodesk.DesignScript.Geometry as DS
clr.AddReference("System")
import System
from System.Collections.Generic import List
PF_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86)
Lib_path = '\IronPython 2.7\Lib'
import sys
sys.path.append("%s%s" % (PF_path, Lib_path))
import ctypes
def getFirstSolid(geo):
for g in geo:
if isinstance(g, DB.GeometryInstance):
return getFirstSolid(g.GetInstanceGeometry())
else:
v = getattr(g, "Volume", 0)
if v != 0:
return g
def getSolidBoundPts(s):
x, y, z = [], [], []
for e in s.Edges:
p = e.Evaluate(0)
x.append(p.X)
y.append(p.Y)
z.append(p.Z)
return DB.XYZ(min(x), min(y), min(z)), DB.XYZ(max(x), max(y), max(z))
SetForegroundWindow = ctypes.windll.user32.SetForegroundWindow
SendKeys = ctypes.windll.user32.keybd_event
def UP1():
SendKeys(0x26, 0, 0, 0)
SendKeys(0x26, 0, 0x0002, 0)
def DN1():
SendKeys(0x28, 0, 0, 0)
SendKeys(0x28, 0, 0x0002, 0)
# INPUT
Cat1, cutoff_depth, TAG_PLACEMENT_MODE, _, IfcTag, IfcTagLeft = UnwrapElement(IN)
IfcTagId, IfcTagLeftId = IfcTag.Id, IfcTagLeft.Id
# get active view's data
view = doc.ActiveView
def pullOntoViewPlane(pt, n=view.ViewDirection, o=view.Origin):
d = n.DotProduct(o) - n.DotProduct(pt)
return pt + n * d
# temporarily modify the view's clip depth to get the visible elements
TransactionManager.Instance.EnsureInTransaction(doc)
cropMan = view.GetCropRegionShapeManager()
if cropMan.Split:
with DB.SubTransaction(doc) as subT:
subT.Start()
min0, max0 = cropMan.GetSplitRegionMinimum(0), cropMan.GetSplitRegionMaximum(0)
min1, max1 = cropMan.GetSplitRegionMinimum(1), cropMan.GetSplitRegionMaximum(1)
cropMan.RemoveSplit()
crop1 = cropMan.GetCropShape()
subT.RollBack()
else:
crop1 = cropMan.GetCropShape()
fec1 = DB.FilteredElementCollector(doc, view.Id).OfCategoryId(Cat1.Id)
VisibleEl = [e for e in fec1]
# get the crop region and shrink appropriately to the tagscale
cropSolid = DB.GeometryCreationUtilities.CreateExtrusionGeometry(crop1, view.ViewDirection, cutoff_depth)
cropCenter = crop1[0].GetPlane().Origin
viewRight = view.RightDirection
cropHalfWidth = abs(view.CropBox.Max.X - view.CropBox.Min.X) / 2 + 0.4 # a bit of a buffer
cropCenter_dot = viewRight.DotProduct(cropCenter)
# collect all existing tags in the view and find their host elements
ViewTags = DB.FilteredElementCollector(doc, view.Id).OfClass(DB.IndependentTag)
TaggedElId = set(t.TaggedLocalElementId.IntegerValue for t in ViewTags)
geoOpt = DB.Options()
intOptions = DB.SolidCurveIntersectionOptions()
intOptions.ResultType = DB.SolidCurveIntersectionMode.CurveSegmentsInside
# find a point inside each element. Elements that are already
# tagged or that are beyond the crop's depth will be ignored
toTag = []
avrgPt, avrgCount = DB.XYZ.Zero, 0
for e in VisibleEl:
if e.Id.IntegerValue in TaggedElId:
continue
elSolid = getFirstSolid(e.Geometry[geoOpt])
intersectedSolid = DB.BooleanOperationsUtils.ExecuteBooleanOperation(
cropSolid, elSolid, DB.BooleanOperationsType.Intersect)
if intersectedSolid.Volume == 0:
continue
a, b = getSolidBoundPts(intersectedSolid)
a, b = pullOntoViewPlane(a), pullOntoViewPlane(b)
l = DB.Line.CreateBound(a, b)
xResult = intersectedSolid.IntersectWithCurve(l, intOptions)
l.Dispose()
curves = [c for c in xResult]
curves.sort(key=lambda c: c.Length)
tagPt = curves[-1].Evaluate(0.5, 1)
toTag.append((e, tagPt))
avrgPt += tagPt
avrgCount += 1
# place the actual tags and compute the final tag position
tm1 = DB.TagMode.TM_ADDBY_MATERIAL
to1 = DB.TagOrientation.Horizontal
tags, areRight = [], []
if avrgCount:
avrgPt /= avrgCount
avrgPt_dot = viewRight.DotProduct(avrgPt)
for elem, tagPt in toTag:
tagPt_dot = viewRight.DotProduct(tagPt)
distToCenter = cropCenter_dot - tagPt_dot
distToAvrg = avrgPt_dot - tagPt_dot
rightOfCenter = distToCenter < 0
if TAG_PLACEMENT_MODE == 0:
shiftRight = distToAvrg < 0
elif TAG_PLACEMENT_MODE == 1:
shiftRight = False
else:
shiftRight = True
mul = distToCenter + cropHalfWidth if shiftRight else distToCenter - cropHalfWidth
headPt = tagPt + mul * viewRight
tag = Create.Document.NewTag(view, elem, True, tm1, to1, tagPt)
#tag = DB.IndependentTag.Create(doc, view.Id, DB.Reference(e), 1, tm1, to1, tagPt)
typeId = IfcTagId if shiftRight else IfcTagLeftId
tag.ChangeTypeId(typeId)
tag.LeaderEnd = tagPt
tag.TagHeadPosition = headPt
tags.append(tag)
areRight.append(shiftRight)
TransactionManager.Instance.TransactionTaskDone()
geoOpt.Dispose()
intOptions.Dispose()
tagsId = List[DB.ElementId](t.Id for t in tags)
uidoc.Selection.SetElementIds(tagsId)
if "2019" in app.VersionNumber:
rvt_winH = uiapp.MainWindowHandle
else:
rvt_proc = System.Diagnostics.Process.GetProcessesByName("Revit")
rvt_winH = rvt_proc[0].MainWindowHandle
active_win = SetForegroundWindow(rvt_winH)
UP1()
DN1()
OUT = [t.Id.IntegerValue for t in tags], areRight, [c.ToProtoType(1) for c in crop1[0]]
you receive the following error message:
Warning: IronPythonEvaluator. Failed to evaluate IronPython script.
Traceback (most recent call last):
File “”, line 160, in
TypeError: NewTag() takes exactly 7 arguments (6 given)
According to the documentation at ApiDocs.co, the NewTag() method should only take 6 arguments.