Wrap Autodesk.Revit.DB.Parameter for Dynamo

So I can get everything I want for a built in parameter, but it is returned as Autodesk.Revit.DB.Parameter (System.Object) and it needs to be Revit.Elements.Parameter… ToDSType() doesn’t work.

If you call the parameter by name with “Family and Type”, you will get one of three different parameters. Only the VIEW_TYPE will work in this instance.

Manage to hack something that gets the right parameter. But it really should be simpler. Any other ideas?

Find the Right BuiltInParameter.dyn (52.9 KB)

Not sure if it would work but you could try using doc.GetElement(result.Id) for one of your outputs.

erm, you can use element selector from dynamo api using the parameter ID as integer value to get Revit.Elements.Element as output. Example of your case would be:

def GetDSElem(id):
    return ElementSelector.ByElementId(Id.IntegerValue,False)

result = None
for myView in collector:
        result = myView.get_Parameter(BuiltInParameter.VIEW_TYPE)
        DSelem = GetDSElem(result.Id)
        myOut = [DSelem, DSelem.Id,DSelem.Name]
        if result: break
    except: pass
OUT = myOut

EDIT: The codes above are not tested yet. It is produced based on your first picture, and your second picture is unclear. Please zoom in till to see a single node and press the camera button on the top right hand corner

Unfortunately, doesn’t work - IronPython wants a reference or string and if I feed the Id in as string, it just comes back null. I don’t think IronPython will return anything that has a negative (-1012106) Id.

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 50, in
TypeError: expected Reference, got int

Good thought, but IronPython returns an error on all negative Id’s (-1012106) just like GetElement. I’m guessing this is just a limit of the API.

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 51, in
Exception: Could not obtain element from the current document! The id may not be valid.

Using vft_id = myView.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsElementId() will return the Id of the view family type. doc.GetElement(vft_id) gets you the element.

But I’m not sure if you wanted the element, or the parameter object itself.

Yes, that is the problem. In most instances, what you’ve shown works just fine. With this and other code of a similar sort, I’m trying to pull the BuiltInParameter as parameter - not the parameter from the element. In some instances, there may not yet be a DB element created. But the BuiltInParameter exist.

Note that you can’t use Snoop for BuiltInParameters by ID. So I’m guessing this is just a underlying API issue.

Did you try the RevitAPI forum?

Seems like I misunderstood the issue in the first place.
And referring to the RevitAPI forum was just a suggestion, where you might find a post with a aim similar to yours. I can see that it could be read as a “push away”.

could you at least show a snapshot of that error? i could not guess where is line50. and i can assure that this works because thats what dynamo did itself in their code for their node. and if you achieve it using their node, then you can achieve it in python script as well

Anyways, i think this workaround should work since i think what you wanna achieve the to get the the viewtype element of a view. So heres the code:

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

def GetDSElem(id):
	result = None
		result = Revit.Elements.ElementSelector.ByElementId(id.IntegerValue,False)
		result = doc.GetElement(id)
	if result:
		try: return result.ToDSType(False)
		except:return result	
	return None
#Preparing input from dynamo to revit
elements = UnwrapElement(IN[0])

finaloutput1,finaloutput2 = list(),list()
#Do some action in a Transaction
for ele in elements:
	if ele:
		typeid1 = ele.GetTypeId()
		typeid12 = ele.get_Parameter(BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM).AsElementId()
		dsele1,dsele2 = None,None
		#Translate to Element
		if typeid1:
			dsele1 = GetDSElem(typeid1)
		if typeid12:
			dsele2 = GetDSElem(typeid12)
		#append to list
		#append to list

#Final output
OUT = finaloutput1,finaloutput2

Actually, I’m working on some parameter management tools, and wanted to get the BuiltInParameters, Labels (all simple enough) and Id’s (not so easy) before views are created.

I also found that there are a number of BuiltInParameters that can’t be parsed and have missing Labels using Python. I posted that under a separate thread.