Shared Parameter is showing in the wrong Parameter Group when added to a family

Shared Parameter is showing in the wrong Parameter Group when added to a family

Anonymous
Not applicable
2,808 Views
4 Replies
Message 1 of 5

Shared Parameter is showing in the wrong Parameter Group when added to a family

Anonymous
Not applicable

Hi,

 

I am adding Shared Parameters to a Family in a project document and reloading this family back to the same document. It works fine but the Shared Parameters show in the wrong Parameter Group, is like the API is ignoring the parameterGroup argument. In this example I use TEXT Parameter Group, but after adding them they show in the Mechanical Group.

 

Any idea of what I am doing wrong?? If I try to add the parameters manually works fine.

 

 

        
Document famDoc = _doc.EditFamily(family);

FamilyManager fm = famDoc.FamilyManager;

using (Transaction trans = new Transaction(famDoc, "Adding SP to Family")) { trans.Start(); foreach (string param in paramsToLoad) { if (fm.get_Parameter(param) == null) { ExternalDefinition extDef = GetExternalDefinition(param); if (extDef != null) { FamilyParameter fParam =
fm.AddParameter(extDef, BuiltInParameterGroup.PG_TEXT, param.Instance);
} } } trans.Commit(); Family fam = famDoc.LoadFamily(_doc, new FamilyOption()); famDoc.Close(false); } private ExternalDefinition GetExternalDefinition(string param) { DefinitionGroups myGroups = _app.OpenSharedParameterFile().Groups; foreach (DefinitionGroup group in myGroups) { Definitions myDefinitions = group.Definitions; ExternalDefinition myExtDef = myDefinitions.get_Item(param) as ExternalDefinition; if (myExtDef != null) return myExtDef; } return null; } class FamilyOption : IFamilyLoadOptions { #region IFamilyLoadOptions Members public bool OnFamilyFound(bool familyInUse, out bool overwriteParameterValues) { overwriteParameterValues = true; return true; } public bool OnSharedFamilyFound(Autodesk.Revit.DB.Family sharedFamily, bool familyInUse, out FamilySource source, out bool overwriteParameterValues) { source = FamilySource.Project; overwriteParameterValues = true; return true; } #endregion }

 

I would appreciate any help.

 

Thanks,

 

Marc

0 Likes
2,809 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

If a parameter has been previously bound to a document, the binding is kept
and will override the grouping.

To fix it you can add the parameter to a schedule and then edit the field.
It will then allow you to reassign the group.

As far as I know there is no way to do this with the API.

 

EDIT:

 

Sorry, I missed the part where you said that adding manually works fine. That sounds like it could be something different as the same issue should happen manually also. Are you manually adding the parameters in the same way (edit family, add parameter, load back into project?

0 Likes
Message 3 of 5

Anonymous
Not applicable

Hi Scott,

 

First of all, thanks for your help.

 

You were totally right, I tried again manually and it behaves exactly in the same way that the API does, once the shared parameter has been previously bound to a document it keeps overriding the grouping.

 

I am creating an application that reads a specific schedule and all its fields that are shared parameters. After selecting a chosen family it loads all those shared parameters into that family to guarantee that all fields in the schedule are "talking" with the family. Everything works fine except modifying the Parameter Group when being loaded to the family.

 

If I have already a Schedule with a Shared Parameter loaded (field) how do you think I could change the Parameter Group?

 

Can I even know what is the current Parameter Group for a specific shared parameter? I know there is the Document.ParameterBindings property but I couldn't figure how to access to the Parameter Group info. I will keep researching...

 

Thanks for your help, I really appreciate it!

 

Marc

0 Likes
Message 4 of 5

Anonymous
Not applicable

I don't think there is a way to access and modify the stored bindings of non-project shared parameters from the API. I've had a good dig around and couldn't get at them, they look to be completely hidden from the API.

 

I have asked about this before (here) but didn't get any response.

0 Likes
Message 5 of 5

antonjubani
Enthusiast
Enthusiast

I found these 2 work-arounds (I prefer the second option)

 

 1- In the project, go to Manage > Project Parameters. Add a new shared parameter and point to the parameter file that contains the shared parameters that are in your families. When you find them, go ahead and load them up. I found that it does not matter which category or categories you apply the parameter to. Make sure you point the "Group Parameter Under" to the same category that you intended the family parameters to be under in the first place. Once you have done that, click OK. Now click on one of the affected families in your project. The parameters should have changed. If so, cool. Now you can go back to the Project Parameters and delete all of the parameters that you just loaded into the model. This will NOT remove your loaded family parameters.

Not sure why Revit does this but this method seems to be a good workaround.

 

2- You can do this through scheduling. Schedule the item and go to" fields". Find the parameter you want to change in either "available" or "scheduled" fields and click "edit". Change the Group parameter in the "parameter data" box and put a check in "add to all elements in the selected categories" and then put a check in the "category" area next to the items the shared parameter affects, hit ok to close the edit box and ok to the schedule properties.
Check your family, it should now show the parameter in the grouping you moved it to. You can delete the schedule you just created after without affecting the grouping.