SharedParameterElement Shows as in document, but not bound to anything

SharedParameterElement Shows as in document, but not bound to anything

Anonymous
Not applicable
665 Views
1 Reply
Message 1 of 2

SharedParameterElement Shows as in document, but not bound to anything

Anonymous
Not applicable

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)?

0 Likes
666 Views
1 Reply
Reply (1)
Message 2 of 2

FAIR59
Advisor
Advisor

There is another way to "load" a SharedParameterElement into the document, besides the creation of a Binding.

 

  • If you load a family that has shared parameters defined, then the SharedParameterElement is also loaded into the document.

However Revit doesn't delete the SharedparameterElement(s) on deleting a Binding or Family. So if you remove a Binding or a Family (purge) the SharedParameterElement remains in the document. You can try to remove the SharedParameterElement via the API (at your own risk).

 

In your case I would suggest to simply use the SharedParameterElement.GetDefinition() for the creation of the new Bindings.