SharedParameterElement Shows as in document, but not bound to anything
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to determine when exactly a SharedParameterElement is created: I have an addin that relies on several shared parameters. I have been keeping up with the template making sure that they are all added and mapped correctly, but with the change to 2017 I lost track and all of the sudden I had revit users telling me that my add in was failing. So I am now registering a DocumentOpened even handler to make sure the parameters are all set up.
To that end, I check to see if my parameter exists with:
SharedParameterElement p = SharedParameterElement.Lookup(doc, Guid.Parse(sGuid));
if(p == null) {
// create parameter
}
so if p==null I can go through and create it (no problems with that piece). The trouble happens is p is not null. I was assuming that this meant I could count on the parameter existing in the document bindings, but debug sessions that failed to run the code or show an exception I tried this:
else if (!doc.ParameterBindings.Contains(p.GetDefinition())) {
// add a bindinginstance to the ParameterBindings
}
So, I have a SharedParameterElement, that has a valid InternalDefinition, but is not in the bindings (a condition that exists now in my template somehow). How would I do this in the Revit UI if I wanted to?
Also, in order to manage my SharedParameters in the code, I have created a constant class with the name, type and GUID for each of my parameters. That way if they don't exist or if the shared parameters file is not associated I can create the definition myself, and then add and bind the parameter. Is anyone else doing this kind of thing? Is there a better approach (perhaps using resources or something)?