Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#Copyright(c)2020,chuongho
#@chuongmep,https://chuongmep.com/
import clr
clr.AddReference('ProtoGeometry')
clr.AddReference('RevitAPI')
clr.AddReference("RevitServices")
from Autodesk.DesignScript.Geometry import *
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Place your code below this line
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
spfile = app.OpenSharedParameterFile()
def defFile(spfile, group, param):
defGroup = spfile.Groups.get_Item(group)
return defGroup.Definitions.get_Item(param)
def tolist(obj1):
if hasattr(obj1,"__iter__"): return obj1
else : return [obj1]
fams = UnwrapElement(tolist(IN[0]))
params = IN[1]
group = IN[2]
paramGroup = IN[3]
instance = IN[4]
logs = []
if not isinstance(params, list): params = [params]
parameter = []
class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self, familyInUse, overwriteParameterValues):
overwriteParameterValues = True
return True
def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues):
return True
try:
for f in fams:
try:
spfile = app.OpenSharedParameterFile()
except:
log = 'No Shared Parameter file found!'
family = UnwrapElement(f)
TransactionManager.Instance.ForceCloseTransaction()
try :
doc_family = doc.EditFamily(family.Symbol.Family)
except:
doc_family = doc.EditFamily(family)
if doc_family != None:
#Data Process
try:
TransactionManager.Instance.EnsureInTransaction(doc_family)
for item,pg,gr in zip(params,paramGroup,group):
if isinstance(pg, basestring): exec ("pg = BuiltInParameterGroup.%s" % pg)
eDef = defFile(spfile, gr, item)
try:
doc_family.FamilyManager.AddParameter(eDef,pg,instance)
log = 'Shared Parameter Added Successfully'
logs.append(log)
except:
log = "Parameter Has Created"
logs.append(log)
except Exception,ex :
log = ex.message
pass
doc_family.LoadFamily(doc,FamilyOption())
TransactionManager.Instance.TransactionTaskDone()
except Exception,ex:
log = ex.message
# Assign your output to the OUT variable.
OUT = logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment