Change parameter of elements into family


#1

Hello everyone!

I try changes parameter Text Font from elements into families, but i have a trouble, please help me find solution! Script find elements but can’t changes the values because method Set is not available.
This is my code and screenshot:

import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

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

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

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


NameOfType = IN[0]


errorReport = None
output = None
try:
	def setWhatYouNeed(d, s):
		TransactionManager.Instance.ForceCloseTransaction()
		familyDoc = doc.EditFamily(s)
		TextNotesType = FilteredElementCollector(familyDoc).OfClass(TextNoteType).ToElements()
		DimensionsType = FilteredElementCollector(familyDoc).OfClass(DimensionType).ToElements()
		TransactionManager.Instance.EnsureInTransaction(familyDoc)
		for list in [DimensionsType,TextNotesType]:
			for element in list:
				element.LookupParameter("Text Font").Set(IN[0])
		TransactionManager.Instance.TransactionTaskDone()
	
	for symbol in IN[1]:
		setWhatYouNeed(UnwrapElement(symbol).Symbol.Family.Document, UnwrapElement(symbol).Symbol.Family)

except:
	import traceback
	errorReport = traceback.format_exc()

if errorReport == None:
	OUT = output
else:
	OUT = errorReport	

`


#2

Up topic. Some ideas guys?


#3

Hi @DENIS.REMESNIK,

It’s not saying set is not available, it is saying that you are passing in nulls and that’s is why set is not available. Have you debugged by outputting just the lists of dimension/text note types? You could add a small change to test if the object is null before trying to get and set it’s parameters.

Cheers,
Dan


#4

I append the elements in the list and this list consist different elements which i should changes. But when i try changes this elements I get this error.


#5

UP2. Maybe someone can advise another way to achieve the goals of this topic?


#6

Please browse the forum and try to be more specific by refering to what has already been done:


#7

Thank you for the your reply, but it’s not the same problem.
I found it topic before - but in this case Konord changes the parameter of family. I want changes the parameter of elements which located in the family.


#8

Do you mean this?


#9

I guess yes! In my code above I found this elements inside families but I can’t changes they values.


#10

It look like you are trying to change the font of the text?


#11

You are right - I try change Text Font in text and dimensions!


#12

Perhaps this may help a little on how to achieve this. I have made two nodes, one to get the Text Node Types in the current doc, the other to set the font. Modify as needed…

TextNoteTypes.Get (Py)

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc =  DocumentManager.Instance.CurrentDBDocument

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

tnTypes = FilteredElementCollector(doc).OfClass(TextNoteType).ToElements()
p = BuiltInParameter.ALL_MODEL_TYPE_NAME
names = [tnt.get_Parameter(p).AsString() for tnt in tnTypes]

OUT = tnTypes, names

TextNoteType.SetFont (Py)

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc =  DocumentManager.Instance.CurrentDBDocument

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

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]

# TextNoteTypes to update...
tnTypes = tolist(UnwrapElement(IN[0]))
# Only accepting one text fornt for now
fontName = tolist(IN[1])[0]

outList = []

p = BuiltInParameter.TEXT_FONT

TransactionManager.Instance.EnsureInTransaction(doc)
for t in tnTypes:
	try:
		textFont = t.get_Parameter(p)
		textFont.Set(fontName)
		outList.append("Success")
	except Exception, e:
		outList.append("Failed to update:- \n" + e.message)
TransactionManager.Instance.TransactionTaskDone()	

OUT = outList

Cheers,
Dan


#13

ps. you will need to integrate this into your own code and i haven’t tested with dims. It is to show how it can be done generally speaking.


#14

Daniel_Woodcock1, Thank you for your reply, but it’s not a solve the problem. I have solution for changes value of parameters (Text Font) in the project. This is my code for this goals:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
doc = DocumentManager.Instance.CurrentDBDocument

ElementTypes = FilteredElementCollector(doc).OfClass(ElementType).ToElements()
result = []
TransactionManager.Instance.EnsureInTransaction(doc)
for i in ElementTypes:
	for j in i.Parameters:
		if j.Definition.Name == "Text Font":
			i.LookupParameter("Text Font").Set(IN[0])
			result.append(i)
TransactionManager.Instance.TransactionTaskDone()
OUT = result

#15

But when I try make the same into different families in the project I can’t do it.
And now i have the next problem: I changed values into families but I can’t reload families with this changes in the project.
If someone can show when I make a mistake - please let me know!
Now my code looks like this:
import clr
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)

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

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *


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

class FamilyOption(IFamilyLoadOptions):
	def OnFamilyFound(self,familyInUse,overwriteParameterValues):
		overwriteParameterValues = True
		return True
		
	def OnSharedFamilyFound(self, sharedFamily, familyInUse, FamilySource, overwriteParameterValues):
		overwriteParameterValues = True
		return True


NameOfType = IN[0]
result = []
def setWhatYouNeed(d, s):
	TransactionManager.Instance.ForceCloseTransaction()
	familyDoc = doc.EditFamily(s)
#	owner = familyDoc.OwnerFamily
	ElementTypes = FilteredElementCollector(d).OfClass(ElementType).ToElements()
	TransactionManager.Instance.EnsureInTransaction(d)
	for i in ElementTypes:
		for j in i.Parameters:
			if j.Definition.Name == "Text Font":
				i.LookupParameter("Text Font").Set(IN[0])
				result.append(i.LookupParameter("Text Font").AsString())
	TransactionManager.Instance.TransactionTaskDone()
	TransactionManager.Instance.ForceCloseTransaction()
	familyDoc.LoadFamily(doc, FamilyOption())
	familyDoc.Close(False)

for symbol in IN[1]:
	setWhatYouNeed(UnwrapElement(symbol).Symbol.Family.Document, UnwrapElement(symbol).Symbol.Family)
	
OUT = result

And my script looks like this:


#16

Hi @DENIS.REMESNIK,

Is this what you are trying to achieve…?

I have only filtered tags in this graph for text font update, but you can filter what you need I think.
ChangeTextFontInAllFamilies.dyn (26.4 KB)

One thing I noticed is that I also wasn’t seeing any text updated. But I was specifically looking at tags and you need to get the TypeId for the annotation element family. I have also changed your code a bit (not much) with some exception handling, list handling and now it takes families directly rather than elements.

Cheers,
Dan


Get family from SpaceTag
#17

Here is a slightly cleaner version of the above sticking to mostly what is in the box.

Slight cleanup on the code also and using the get_Parameter(BuiltInParameter.TEXT_FONT) like my earlier post rather than a string search as @til.shviger flagged up in a separate post will cause errors in different languages should you want to distribute it.

Output data is a little more descriptive too, so you can see what ElementTypes were updated in the family for each family. Run input added if you want to keep it and a doc.refresh to tie it all off.


ChangeTextFontInAllFamilies.dyn (21.2 KB)

Cheers,
Dan


#18

Daniel_Woodcock1,
I can’t check it right now, but it’s looks good. Thanks a lot for your support!
Best regards.


#19

To be fair, I didn’t do all that much. it was pretty much most the way there, I just added a few extras. :slight_smile: