Reading instance parameters by API

Reading instance parameters by API

oza77
Participant Participant
7,467 Views
3 Replies
Message 1 of 4

Reading instance parameters by API

oza77
Participant
Participant

We are developing the Addin for Revit 2016 (in C#) and we have got an issue with reading element parameters.

We have some instance of Element in the drawing (for example Door):

Element e

Also we have the name of the parameter:

string parameterToFind = "MyParameterName";

We read the parameter as follows:

Parameter p = e.LookupParameter(parameterToFind);

This code works properly for these parameter variants:

  • Shared parameter – Type
  • Project parameter – Type

We are not able to read these parameter variants:

  • Shared parameter – Instance
  • Project parameter – Instance

The collection e.Paramters does not contains any Instance parameter and we could not read its value. The method LookupParameter returns null.

Please, could you advise how to read instance parameter from particular element?

Particularly we need this method:

public string GetParameterValue(Element e, string parameterName)

{

 

}

 

Or

 

public Parameter GetParameter(Element e, string parameterName)

{

 

}

0 Likes
Accepted solutions (3)
7,468 Views
3 Replies
Replies (3)
Message 2 of 4

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

I'm a bit confused.

When e is an Element, the e.LookupParameter method returns instance parameters, not type parameters.

To get type parameters, you would get e's type via

Element et = e.Document.GetElement(e.GetTypeId());

 

An Element's type parameters are in fact its ElementType's instance parameters.

 

Are you sure your ParameterBindings are defined correctly ?

You can either bind a parameter to instances OR to types.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 4

oza77
Participant
Participant
Accepted solution

Thank you, 

 

your sentence  "An Element's type parameters are in fact its ElementType's instance parameters"

 

was the key to the problem. We thought that we hold a handle to the element, but had types only.

 

So we already know where to make the changes.

 

best regards, Stepan

 

0 Likes
Message 4 of 4

Revitalizer
Advisor
Advisor
Accepted solution

Hi Stepan,

 

if that is the solution, please mark this thread as solved.

 

 

Regards,

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes