Unable to permanently change a parameter group


#1

I was trying to obtain the same thing as this post, i.e. changing parameter groups and noticed the same error: once I save the family or the project then the parameters do not remember that they were moved and go back to their original state.

This is a similar post with a different code posted by @Konrad_K_Sobon but with the same concpet: OLDparameterDefinition.ParameterGroup=NEWgroup

I tried both in the project and the family environment and could not permanently save the changed group, i.e. if I closed and reopened the file the parameters did not change. However if I did it by hand it worked. It seems like we are missing some sort of “update” button, or maybe we have to trick revit in thinking that the edit was done by a human and not by python.

Cattura

In the project environment:

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

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

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
import System
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

pgINstr=IN[0]
pgOUTstr=IN[1]

#From the input strings find the corresponding BuiltInParameterGroup
bpgs=System.Enum.GetValues(BuiltInParameterGroup)
for bpg in bpgs:
	if str(bpg)==pgINstr:
		pgIN=bpg
	if str(bpg)==pgOUTstr:
		pgOUT=bpg

#Create a list with all the project parameters
params = []
iterator = doc.ParameterBindings.ForwardIterator()
while iterator.MoveNext():
	params.append(iterator.Key)

#Change the parameter group of all parameters in the desired paramgroup
pchanged=[]

for pdef in params:
	TransactionManager.Instance.EnsureInTransaction(doc)
	if pdef.ParameterGroup==pgIN:
		pdef.ParameterGroup=pgOUT
		test=pdef.ParameterGroup
		pchanged.append(pdef.Name)
	TransactionManager.Instance.TransactionTaskDone()
	#TransactionManager.Instance.ForceCloseTransaction()

OUT = pchanged

In the family environment:

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

# 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 System

pgGroupStr=IN[0]
pgGroupStr2=IN[1]

bpgs=System.Enum.GetValues(BuiltInParameterGroup)
for bpg in bpgs:
	if str(bpg)==pgGroupStr2:
		pgGroup2=bpg
	if str(bpg)==pgGroupStr:
		pgGroup=bpg

rtn=[]
TransactionManager.Instance.EnsureInTransaction(doc)
params=doc.FamilyManager.Parameters	
for p in params:
	if p.Definition.ParameterGroup==pgGroup:
		rtn.append(p)
		p.Definition.ParameterGroup=pgGroup2

TransactionManager.Instance.ForceCloseTransaction()

OUT=rtn

I tried playing around with ForceCloseTransaction() instead of TransactionTaskDone(), and inserting the transaction in the for loop but nothing changed.

I am not talking about changing a parameter group in a family, uploading it (again) in a project and noticing that the group does not change: this is a well known issue regardless of what Autodesk says: link

A really horrible “workaroud” I found is the following:

  • For the project environemt: run the script, create a new file(rvt or rte template, as in my case), and transfer the standards (the parameters in my case) to the new file.Now use the new file…
  • For the family environment: run the script, create a new file(rvt or rte), load and close the family in the project, export the family from the project.

This is the second time I found such a behaviour (recently I could not permanently change some MEP settings) and would love to understand what line of code I am missing
Thanks