Problem with a Parameter when used as a Reporting Parameter

Problem with a Parameter when used as a Reporting Parameter

62BJW
Advocate Advocate
659 Views
5 Replies
Message 1 of 6

Problem with a Parameter when used as a Reporting Parameter

62BJW
Advocate
Advocate

I have the same parameter ("Door Width") in two different families. The only difference between the families is that the "Door Width" parameter is used as a reporting parameter in one of them.

 

My codes accesses the parameter as so...

                    ElementType type = doc.GetElement(e.GetTypeId()) as ElementType;
                    Parameter dWidth = type.LookupParameter("Door Width");

When used on the family with the reporting parameter dWidth reports null. When used on the family as a "regular" parameter I get all the desired information. See attachments. Thanks for your time I appreciate it.

 

 

0 Likes
Accepted solutions (1)
660 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk

Dear Bernie,

 

Thank you for your query.

 

I am not aware of any differences accessing parameters depending on whether they are reporting or not.

 

I would however definitely recommend you avoid using LookupParameter at all in a production environment.

 

LookupParameter returns the first parameter corresponding to the given display name that it happens to find.

 

If there are more than one, you have no idea which one you are getting.

 

I recommend:

 

  • Avoid using display names at all when accessing parameters.
  • If you do use display names, use GetParameters to retrieve all of them and see how many you are getting.

 

Here is an example of the latter point:

 

https://thebuildingcoder.typepad.com/blog/2015/06/cnc-direct-export-wall-parts-to-dxf-and-sat.html#2...

 

Here is a comment on the former point:

 

https://thebuildingcoder.typepad.com/blog/2018/11/efficient-elegant-code-and-automatic-dashboard.htm...

 

LookupParameter will only retrieve the first parameter of the given name. In order to use it, you must be absolutely certain that only one parameter with the given name exists. I would suggest adding a test somewhere in your add-in start-up code to ensure that this really is the case.

 

It is always safer to use other means to retrieve parameters, e.g., the built-in parameter enumeration value, if it exists, or simply the Parameter definition, which you can look up and cache beforehand, e.g., in the afore-mentioned code ensuring that the parameter name on that element type really is unique.

 

I hope this helps.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 6

62BJW
Advocate
Advocate

Thanks for the information.

 

I'm not trying to change the parameter just get it's value and store it in a variable (double). I can't seem to get it to work if the parameter is a reporting parameter. The "Door Width" parameter is in my "normal" door families and also in my curtain panel doors as a reporting parameter.

 

I can paste the entire code if that helps? Thanks.

0 Likes
Message 4 of 6

FAIR59
Advisor
Advisor

a reporting parameter is an instance parameter, and doesn't belong to an elementtype.

You need a placed FamilyInstance from the model, to query for a reporting parameter.

0 Likes
Message 5 of 6

62BJW
Advocate
Advocate
I misread your reply. I’ll see if I can get the instance somehow.
0 Likes
Message 6 of 6

FAIR59
Advisor
Advisor
Accepted solution

you probably can cast Element e into a FamilyInstance.

0 Likes