How to Rename a Non-Shared Revit Project Parameter?

CoderBoy
Advocate
Advocate

How to Rename a Non-Shared Revit Project Parameter?

CoderBoy
Advocate
Advocate

Hello everyone!  We have a serious need in Revit 2017 and later to rename non-shared project parameters using the Revit API.  We've written many Revit add-ins and are pretty familiar with the Revit API, but after quite a bit of searching and playing around with some code, I have been unable to find a solution for this need.

 

You can rename one of these non-shared project parameters in the GUI (see the attached screen shot), so it seems to me like it should be possible using the API.  At least, in the past we've been told if you can do it in the GUI the goal is to be able to do it in the API as well.

 

I can get to the InternalDefinition and the ParameterElement reference for the project parameters in question, but the Name field is either read-only, or is NOT read-only but fails at runtime with the error "This element does not support assignment of a user-specified name"

Is there some kind of "ParameterManager" object with a SetName-type method on it (similar to what can be done with Family editing using the API to rename non-shared parameters on the family) that would let us do this?

What am I missing here?  I have searched this forum and the Internet in general and can't seem to find much for applicable results.

Thank you so very much for any assistance you can provide.  

0 Likes
Reply
2,938 Views
8 Replies
Replies (8)

BenoitE&A
Collaborator
Collaborator

Hey,

I think I did it once and it had something to do with ParameterElement. But I can't find how...

Hope it helps !

Benoit


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes

CoderBoy
Advocate
Advocate

Without the details, or at least the general process, about all that can help do is provide some hope, which is still valuable.

 

Thanks.

0 Likes

BenoitE&A
Collaborator
Collaborator

I tried this : 

myParameter.Element

So maybe the ParameterElement (of which you can modify the name) can be found using :

myParameter.Element as ParameterElement

I had no time to check... if it works tell us !


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
0 Likes

CoderBoy
Advocate
Advocate

It doesn't work (at least when I tried it in Revit 2018 yesterday).  The ParameterElement *does* have a Name field, and the API has declared it NOT read-only, but when you try to set it to any new value at runtime (even one you KNOW is unique from all others), it throws an exception with the message "This element does not support assignment of a user-specified name"

It's really odd that the API would allow it to be writable, but apparently never allows you to write to it at runtime.  I tried modifying the same parameter in the UI to the value I was trying to set with code, and it worked just fine.  But from code it throws that exception all the time.

 

It's almost like there's a bug in the API itself.

0 Likes

eason.kangEDLV4
Autodesk Support
Autodesk Support

Hi,

 

As I know, the parameter name is stored in the Definition of the parameter, not the name field, and the Definition name is read-only. Therefore, it could be not possible to rename it via API. I'm checking the possibility with our engineering team, and will get back to you A.S.A.P.

 

https://www.revitapidocs.com/2017.1/a8f22807-7fef-f24e-e1fa-7dbef20c3628.htm

 

Cheers,

 


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

0 Likes

CoderBoy
Advocate
Advocate

I believe you are correct, the Definition.Name property is read-only from what I recall. 

 

However, that doesn't negate the fact that you can rename non-shared project parameters in the UI, so there should ideally be a way to do it in the API.

 

I believe for family documents there's a method on the FamilyManager class to rename non-shared parameters.  Is there something like that for projects, too?  That would be a very good way to do it.

0 Likes

eason.kangEDLV4
Autodesk Support
Autodesk Support

Hi,

 

Sorry for the delay, I just got confirmed from our Revit team that there is no API support for renaming parameter name from the project side currently. Therefore, I would advise you to write down your idea here: https://forums.autodesk.com/t5/revit-ideas/idb-p/302

 

Currently, a possible approach is to create a new parameter with the new name, and copy the old parameter's into the new one. However, there is no API support for project parameters, either. So, the shared parameter might be a reliable way to deal with parameters via the Revit API now with my experience.

 

Cheers,

 

 

 

 


Eason Kang
Developer Advocate
Developer Advocacy & Support Service
Autodesk Platform Service (formerly Forge)

0 Likes

CoderBoy
Advocate
Advocate

Creating a new shared project parameter (because I believe you can't create a non-shared project parameter with the API, like you can in the GUI) with the same category bindings and then hunting down all the elements in the project for those categories and copying the values from the old parameter to the new parameter for each element instance and then deleting the old non-shared project parameter when done is a pretty brute force way to do a workaround for something that gets you close, but really should be as simple as renaming a non-shared project parameter, like you can do in the GUI.  


Can you delete a non-shared project parameter with the API?  I'm not sure, haven't researched that, but I have my doubts given how limiting the API support is for project parameters.  I suppose as part of the workaround, worst case you could unbind it from all categories if you had to.

 

I guess we won't have any choice, though.  I will do what I can to promote getting the API to do what the GUI does elsewhere, I guess.

Thank you very much for confirming with the development team that there is no support for renaming a non-shared project parameter natively in the API.