Auto Material Tag

Hi,
What is this “ToRvtPoint”? I chose the points I wanted to tag in the selections, but what am I doing wrong?
I am adding the relevant .JPEG and code to the attachment.
Thanks.


MaterialTag.dyn (94.3 KB)

Can you open the node and copy the python code within into the topic? Looks like a system conversion problem. Also, what package/ package version is the node from? (As you look to be using Dynamo 2.0 at least)

Hi @Durmus_Cesur,

Add a List.Flatten node after the Geometry.Translate node.
The Create Annotation Tag doesn’t seem to work with material tags.

You can use instead the Create Annotation Tag (Multi-Category) node in Genius Loci package.
It’s a variation on the node of archilab so many thanks to Konrad Sobon.
If you are using Revit 2019 choose the Create Independent Tag node.


My Dynamo Vers. 2.02.02

#Copyright(c) 2015, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

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

# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

locationPts = UnwrapElement(IN[0])
tagType = UnwrapElement(IN[1])
elements = UnwrapElement(IN[2])

if IN[4] != None:
	link = UnwrapElement(IN[4])
else:
	link = None
	
RunIt = IN[5]

if isinstance(IN[3], list):
	views = [UnwrapElement(i) for i in IN[3]]
else:
	views = UnwrapElement(IN[3])

def toRvtPoint(point):
	return point.ToXyz()

def toRvtId(_id):
	if isinstance(_id, int) or isinstance(_id, str):
		id = ElementId(int(_id))
		return id
	elif isinstance(_id, ElementId):
		return _id

def GetUVPoint(pt):
	if type(pt) == Autodesk.DesignScript.Geometry.Point:
		return Autodesk.Revit.DB.UV(pt.X, pt.Y)
	elif type(pt) == Autodesk.DesignScript.Geometry.UV:
		return Autodesk.Revit.DB.UV(pt.U, pt.V)

def CreateSpaceTag(space, uv, view):
	doc = DocumentManager.Instance.CurrentDBDocument
	return doc.Create.NewSpaceTag(space, uv, view)

tagTypeId = toRvtId(tagType.Id)

try:
	errorReport = None
	if RunIt:
		if tagType.Category.Name == "Room Tags":
			TransactionManager.Instance.EnsureInTransaction(doc)
			roomTags = []
			if isinstance(views, list):
				for i, j, k in zip(elements, views, locationPts):
					roomId = LinkElementId(i.Id)
					location = Autodesk.Revit.DB.UV(toRvtPoint(k).X, toRvtPoint(k).Y)
					roomTag = doc.Create.NewRoomTag(roomId, location, j.Id)
					roomTag.RoomTagType = tagType
					roomTags.append(roomTag)
			else:
				for i, j in zip(elements, locationPts):
					if link != None:
						roomId = LinkElementId(link.Id, i.Id)
					else:
						roomId = LinkElementId(i.Id)
					location = Autodesk.Revit.DB.UV(toRvtPoint(j).X, toRvtPoint(j).Y)
					roomTag = doc.Create.NewRoomTag(roomId, location, views.Id)
					roomTag.RoomTagType = tagType
					roomTags.append(roomTag)
			TransactionManager.Instance.TransactionTaskDone()
			result = roomTags
		elif tagType.Category.Name == "Space Tags":
			TransactionManager.Instance.EnsureInTransaction(doc)
			roomTags = []
			if isinstance(views, list):
				for i, j, k in zip(elements, views, locationPts):
					uv = GetUVPoint(k)
					spaceTag = CreateSpaceTag(i, uv, j)
					spaceTag.SpaceTagType = tagType
					roomTags.append(spaceTag)
			else:
				for i, j in zip(elements, locationPts):
					uv = GetUVPoint(j)
					spaceTag = CreateSpaceTag(i, uv, views)
					spaceTag.SpaceTagType = tagType
					roomTags.append(spaceTag)
			TransactionManager.Instance.TransactionTaskDone()
			result = roomTags
		else:
			TransactionManager.Instance.EnsureInTransaction(doc)
			tags = [\*]
			if isinstance(views, list):
				for i,j,k in zip(elements, views, locationPts):
					location = toRvtPoint(k)
					tag = doc.Create.NewTag(j, i, False, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, location)
					tag.ChangeTypeId(tagTypeId)
					tags.append(tag)
			else:
				for i, j in zip(elements, locationPts):
					location = toRvtPoint(j)
					tag = doc.Create.NewTag(views, i, False, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, location)
					tag.ChangeTypeId(tagTypeId)
					tags.append(tag)
			TransactionManager.Instance.TransactionTaskDone()
			result = tags
	else:
		result = "RunIt is set to False."
except:
	# if error accurs anywhere in the process catch it
	import traceback
	errorReport = traceback.format_exc()

#Assign your output to the OUT variable
if errorReport == None:
	OUT = result
else:
	OUT = errorReport

Yes, that code works really well. Thank you for the package and @Konrad_K_Sobon. Yet still “Element Locations Point” over the “Tag” is creating. In this case, the points I set are not important. I need to know what caused this situation.I examined the work on this situation and in the video, @Dimitar_Venkov has again spread its magic on us. I don’t want to explore America again.
Thanks.
*https://www.youtube.com/watch?v=RCn-eFZb2FU


-1.The points I want to tag.
-2-Element Location Point
MaterialTag.dyn (100.0 KB)

Hi Durmus,

The node created material tags with the leaders and the locations were therefore incorrect.
It is now corrected in the last version of the package.

If your goal is to tag all materials, you can use the Wall CompoundStructureLayersLocation and Tag Set Location nodes.


3 Likes

Thank you very much for your help, really. The secret to this is “ListOfRepeatedItem”. Bonne Journée

:grinning:

1 Like