# Parameters Script Issue

**URL:** <https://forum.dynamobim.com/t/parameters-script-issue/49759>\
**Category:** Developers\
**Tags:** revit, dynamo\
**Created:** [April 24, 2020, 6:51pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759 "2020-04-24T18:51:31Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![kbruno1989](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kbruno1989/32/88072_2.png) [@kbruno1989](https://forum.dynamobim.com/u/kbruno1989)\
**Post date:** [April 24, 2020, 6:51pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/1 "2020-04-24T18:51:31Z")

</div>

Hello Everyone,

I am running into an error when trying to incorporate multiple parameters in multiple groups into a family in one command. Not sure what the issue is exactly… Any ideas?

 ![Parameters Add](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/3/832a8b5f87c8c95bf507906f595bc1a7c22d003a.png)

 ![Error](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/b/9b209d4b102a579252fa78ab8ab65e42699e62d5.png)

> #code largely inspired by Dimitar Venkov  
> import clr
> 
> clr.AddReference(‘RevitServices’)  
> from RevitServices.Persistence import DocumentManager  
> from RevitServices.Transactions import TransactionManager  
> doc = DocumentManager.Instance.CurrentDBDocument
> 
> clr.AddReference(‘RevitAPI’)  
> from Autodesk.Revit.DB import \*
> 
> parameters = IN[0]  
> paramgroups = IN[1]  
> inst\_or\_typ = IN[2]  
> families = UnwrapElement(IN[3])
> 
> class FamOpt1(IFamilyLoadOptions):  
> def **init** (self): pass  
> def OnFamilyFound(self,familyInUse, overwriteParameterValues): return True  
> def OnSharedFamilyFound(self,familyInUse, source, overwriteParameterValues): return True
> 
> trans1 = TransactionManager.Instance  
> trans1.ForceCloseTransaction()
> 
> result =
> 
> for f1 in families:
> 
> ```
> famdoc = doc.EditFamily(f1)
> 
> trans1.EnsureInTransaction(famdoc)
> for p in parameters:
> famdoc.FamilyManager.AddParameter(p, paramgroups, inst_or_typ)
> trans1.ForceCloseTransaction()
> famdoc.LoadFamily(doc, FamOpt1())
> result.append(True)
> 
> ```
> 
> OUT = ‘Successfully added %d shared parameters to %d families’ %(len(parameters),len(result))

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [April 24, 2020, 7:19pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/2 "2020-04-24T19:19:33Z")

</div>

Your variable “families” consists of a single family. So, attempting to loop over a single family (not a list of families) is not valid. If you are only planning on editing a single family at a time, you can remove your outermost loop:

```
family = UnwrapElement(IN[3])
famdoc = doc.EditFamily(family)
# etc. etc.
```

---

<div class="post-metadata">

**Author:** ![kbruno1989](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kbruno1989/32/88072_2.png) [@kbruno1989](https://forum.dynamobim.com/u/kbruno1989)\
**Post date:** [April 28, 2020, 6:50pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/3 "2020-04-28T18:50:36Z")

</div>

Hey @cgartland,

Thank you so much and that definitely helps so much. However, I was wondering what am I doing wrong?

> import clr
> 
> clr.AddReference(‘RevitServices’)  
> from RevitServices.Persistence import DocumentManager  
> from RevitServices.Transactions import TransactionManager  
> doc = DocumentManager.Instance.CurrentDBDocument
> 
> clr.AddReference(‘RevitAPI’)  
> from Autodesk.Revit.DB import \*
> 
> parameters = IN[0]  
> paramgroups = IN[1]  
> inst\_or\_typ = IN[2]  
> family = UnwrapElement(IN[3])  
> famdoc = doc.EditFamily(family)
> 
> class FamOpt1(IFamilyLoadOptions):  
> def **init** (self): pass  
> def OnFamilyFound(self,familyInUse, overwriteParameterValues): return True  
> def OnSharedFamilyFound(self,familyInUse, source, overwriteParameterValues): return True
> 
> trans1 = TransactionManager.Instance  
> trans1.ForceCloseTransaction()
> 
> OUT = ‘Successfully added %d shared parameters to %d families’ %(len(parameters),len(result))

> Blockquote

 ![Error](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/2/52a172a7bf7eaac0ca732299f51484af61c09169.jpeg)

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [April 28, 2020, 7:46pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/4 "2020-04-28T19:46:54Z")

</div>

See [this post](https://forum.dynamobim.com/t/setting-the-builtin-parameter-accessible-thru-the-family-editor/10554/15) for additional information. Also, be sure to paste your code as preformatted text instead of a blockquote.

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/6/c6681d14a012f00b1582df658f9290fd1457083c.png)

I have also found issues using the TransactionManager with documents other than the current DBDocument. Instead, try creating a transaction manually:

```
famdoc = doc.EditFamily(family)

t = Transaction(famdoc, 'Describe your transaction')
t.Start()
# Do stuff here
t.Commit()

```

---

<div class="post-metadata">

**Author:** ![kbruno1989](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kbruno1989/32/88072_2.png) [@kbruno1989](https://forum.dynamobim.com/u/kbruno1989)\
**Post date:** [April 28, 2020, 8:26pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/5 "2020-04-28T20:26:46Z")

</div>

@cgartland, I completely understand what you mean. Thanks for helping with that formatting. I just want to figure this out as this is the last part of a very complex script.

@Dimitar_Venkov, I know you made this script a while back but am currently trying to add the parameters to just 1 family rather than the original (multiple families). Any ideas?

```
import clr

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

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

parameters = IN[0]
paramgroups = IN[1]
inst_or_typ = IN[2]
family = UnwrapElement(IN[3])

# class for overwriting loaded families in the project
class FamOpt1(IFamilyLoadOptions):
    def __init__ (self): pass
    def OnFamilyFound(self,familyInUse, overwriteParameterValues): return True
    def OnSharedFamilyFound(self,familyInUse, source, overwriteParameterValues): return True

trans1 = TransactionManager.Instance
trans1.ForceCloseTransaction() 
#just to make sure everything is closed down
# Dynamo's transaction handling is pretty poor for
# multiple documents, so we'll need to force close
# every single transaction we open

result = []

famdoc = doc.EditFamily(family)
 	
 	trans1.EnsureInTransaction(famdoc)
    for p in parameters:
        famdoc.FamilyManager.AddParameter(p, paramgroups, inst_or_typ)
    trans1.ForceCloseTransaction()
    famdoc.LoadFamily(doc, FamOpt1())
    result.append(True)

OUT = 'Successfully added %d shared parameters to %d families' %(len(parameters),len(result))
```

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [May 2, 2020, 9:38am UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/6 "2020-05-02T09:38:15Z")

</div>

What’s the error you got? The indentation looks a bit off but that might be because you pasted the code in the forum.

---

<div class="post-metadata">

**Author:** ![kbruno1989](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kbruno1989/32/88072_2.png) [@kbruno1989](https://forum.dynamobim.com/u/kbruno1989)\
**Post date:** [May 4, 2020, 3:33pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/7 "2020-05-04T15:33:11Z")

</div>

Hey Dimitar,

I got the following error:

 ![Error](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/6/b6ecb856b073b4beec1a54d5bfaaf9c2aa86f370.png)

I am basically trying to have multiple Parameter groups with multiple parameters go to a single family and/or multiple families. Any ideas?

Sincerely,  
Kevin

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [May 7, 2020, 10:56am UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/8 "2020-05-07T10:56:04Z")

</div>

Right now you’re feeding in a list of Parameter groups but the code expects a single one. You’ll need to iterate over each of the PGs and run the add command. Something along the lines of:

```
famdoc = doc.EditFamily(family)
trans1.EnsureInTransaction(famdoc)
for pg in parameterGroups:
    for p in parameters:
        famdoc.FamilyManager.AddParameter(p, pg, inst_or_typ)
trans1.ForceCloseTransaction()
famdoc.LoadFamily(doc, FamOpt1())
famdoc.Close(Fasle)
result.append(True)
```

---

<div class="post-metadata">

**Author:** ![kbruno1989](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kbruno1989/32/88072_2.png) [@kbruno1989](https://forum.dynamobim.com/u/kbruno1989)\
**Post date:** [May 11, 2020, 3:25pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/9 "2020-05-11T15:25:11Z")

</div>

Hey Dimitar,

I tried making the modifications and adjustments but seems to have thrown a new error? Not entirely sure what is going on that I am potentially missing?

 ![Issue](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/e/aeaec9e50e51d87a002fd9954c04d3db7d4c9060.png)

Thanks again bud,  
Kevin

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [May 20, 2020, 12:19pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/10 "2020-05-20T12:19:32Z")

</div>

what did the inputs look like?

---

<div class="post-metadata">

**Author:** ![kbruno1989](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kbruno1989/32/88072_2.png) [@kbruno1989](https://forum.dynamobim.com/u/kbruno1989)\
**Post date:** [May 21, 2020, 3:26pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/11 "2020-05-21T15:26:51Z")

</div>

Hey Dimitar!

Please see both the code and inputs. I hope the screenshot shows all the inputs needed. I just do not know what is causing the issue?

 ![Error](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/e/aef9bab8fb209e3a3a2c2bf95d626d6041d6b170.jpeg)

```
"
import clr

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

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

parameters = IN[0]
paramgroup = IN[1]
inst_or_typ = IN[2]
families = UnwrapElement(IN[3])

# class for overwriting loaded families in the project
class FamOpt1(IFamilyLoadOptions):
def __init__ (self): pass
def OnFamilyFound(self,familyInUse, overwriteParameterValues): return True
def OnSharedFamilyFound(self,familyInUse, source, overwriteParameterValues): return True

trans1 = TransactionManager.Instance
trans1.ForceCloseTransaction() #just to make sure everything is closed down
# Dynamo's transaction handling is pretty poor for
# multiple documents, so we'll need to force close
# every single transaction we open
result = []

for f1 in families:
famdoc = doc.EditFamily(f1)

trans1.EnsureInTransaction(famdoc)
for pg in paramgroup:
	for p in parameters:
    	famdoc.FamilyManager.AddParameter(p, pg, inst_or_typ)
trans1.ForceCloseTransaction()
famdoc.LoadFamily(doc, FamOpt1())
famdoc.Close(false)
result.append(true)

OUT = 'Successfully added %d shared parameters to %d families' %(len(parameters),len(result))
";

```

Any ideas and Thank you again!  
Kevin

P.S. Starting this Friday, I am going to start taking C# classes and train myself in the ways of API’s to get more into Revit API 🙂

---

<div class="post-metadata">

**Author:** ![kbruno1989](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kbruno1989/32/88072_2.png) [@kbruno1989](https://forum.dynamobim.com/u/kbruno1989)\
**Post date:** [June 5, 2020, 4:28pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/12 "2020-06-05T16:28:57Z")

</div>

Hey @Dimitar_Venkov, just wanted to follow up on what I am doing wrong? LOL

Thank you for your help bud!

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [June 6, 2020, 7:03am UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/13 "2020-06-06T07:03:19Z")

</div>

Everything looks right. Look at the error, it’s different. It’s telling you there’s already a parameter called “Structural Usage”. To add some robustness, you could add a try/catch block:

```auto
for pg in paramgroup:
	for p in parameters:
        try:
    	    famdoc.FamilyManager.AddParameter(p, pg, inst_or_typ)
        except:
            pass

```

---

<div class="post-metadata">

**Author:** ![kbruno1989](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kbruno1989/32/88072_2.png) [@kbruno1989](https://forum.dynamobim.com/u/kbruno1989)\
**Post date:** [June 8, 2020, 4:38pm UTC](https://forum.dynamobim.com/t/parameters-script-issue/49759/14 "2020-06-08T16:38:09Z")

</div>

Hey Dimitar,

Thank you so much bud! This did it. The reason why I wanted to make this script is when we have custom Shared Parameters and get a clients file… I do not have to manually (or my team) need to add in each Shared parameter 1 by 1… Such a pain! LOL. Thank you so much and hope you had a great weekend!
