FamilyManager.Parameter(string) expects guid

Trying to remove parameters from families, and it says that unlike the add which needs definitions it just needs the familyparameter. I thought I figured out a way to do this with FamilyManager.Parameter(string). I’m getting the names from Parameters.Name. Below is a section of code. I’m trying to modify some code that I duplicated from a Gavin Crump tutorial. Also note that the script has some unused stuff I need to clean up when I’m doing figuring out what I’m doing.

if famDoc.IsFamilyDocument:
        # Get family manager
        famMan = famDoc.FamilyManager
        # The line below is a coding method called "Chaining". from left to right we are implying an order of operations
        parDefs = [p.Definition for p in famMan.Parameters]
        parNames = [p.Name for p in parDefs]
        paramet = []
        for n in parNames:
            paramet.append(famMan.Parameter[n])
        params = []
        print(paramet)

I’m getting a type error: expected Guid, got str. I know that there is a Guid version of this but I also see one that needs strings, but it looks like the same command. Is there something I’m missing here?
image

I thought I could just get the familyparameter from FamilyManager.GetParameters, but I don’t see how I would compare that to a list of parameter names I want to delete. I explored the FamilyParameter class and can’t find anything property relating the the parameter’s name.

Hopefully, it’s clear that I’m very new to APIs and python in general.

The GUID is only going to work for shared parameters so you would have to filter for that - something like this
parGUIDs = [p.GUID for p in famMan.Parameters if p.IsShared]
or you could try with the Definition
[famMan.Parameter[def] for def in parDefs]
I’m wondering what the purpose of the script is as can get a list of the parameters with list(famMan.GetParameters())

I’m not trying to use the GUID. I want to use the .Parameter property but have it use the string as the input. It’s acting like it the first version but I want it to act like the second.

image

I happen to be removing shared parameters but I want to make it so it can remove any family parameter.
My idea was to get the parameter name which I got with FamilyManager.Parameters.Name and use the names to get the familyparameter in such a way that I can get the index of the familyparameter when comparing it to the parameter names in my excel file.

I currently have the RemoveParameter commented out because i thought it needed the parameter definition but instead it needs the family parameter.

def famDoc_DeleteParams(famDoc, famNames):
    # Make sure it is a family document
    if famDoc.IsFamilyDocument:
        # Get family manager
        famMan = famDoc.FamilyManager
        # The line below is a coding method called "Chaining". from left to right we are implying an order of operations
        parDefs = [p.Definition for p in famMan.Parameters]
        parNames = [p.Name for p in parDefs]
        paramet = []
        for n in parNames:
            paramet.append(famMan.Parameter[n])
        params = []
        print(paramet)
        # Make a transaction (I added the "pR - " to the transaction name because I want to quickly see what is a pyRevit operation in Revit) Note to self why ' instead of " ?
        t = Transaction(famDoc, 'pR - Delete parameters')
        t.Start()
        # Delete parameters to document
        for d in famNames:
            print(d)
            if d in parNames:
                ind = parNames.index(d)
                print(parDefs[ind])
                #p = famMan.RemoveParameter(paramet[ind])
                #params.append(p)
            else:
                pass

Try this paramet.append(famMan.get_Parameter(n))

2 Likes

Thank you, that managed to get the family parameter. I do have one question, and this is more of a general python/API question.

How did you know you could do that? I can’t find anything in the API with get_Parameter. When I look at the API I see stuff like this and it has “get” but I thought that was just because all the examples are written in C#.

public FamilyParameter this[
	string parameterName
] { get; }

Is this just a standard python thing I’m unaware of? I’m lost as to how I’m supposed to find this information on my own, which I would like to do!

You get to know these poorly documented methods mainly through trawling through this forum and the Autodesk Revit forum. Info is at the bottom of the LookupParameter method on ApiDocs page here.

Another way you can find what is available for an element / object is to run the python dir() function which outputs a list of the methods and attributes available. This is where you can learn about .NET methods like get_Item() which can retrieve from a dictionary when the API method doesn’t cooperate in python

1 Like