I am using the Filtered elements collector passing in the document as in the image below, the intention is to get all shared parameter loaded to the document. However, it returns extra shared parameters. which I recognise but not actually loaded in the file.
when I tried using a linked document it gives the same results.( which is correct it uses a different SP file)
I even tried unloading the linked file and is still the same.
It doesn’t seems to work even if I close/open Revit session.
I also tried it on a new document from the actual document and vice versa and it gives the same number of SPs. It seems to like the Filtered element collector tries to access the UIapplication of the host model and access the SP in there. Since the linked models are also in the same session and in the same UI application it seems to return the same.
Are you trying to return all the SharedParameterElements that exist in the model or all the shared parameters available in the currently loaded shared parameter file? This seems to be returning all the shared parameters existing in the model, which makes sense from a collector standpoint.
It may also be that the shared parameters loaded into a given doc also include any shared parameters available through a currently linked model. That would explain why active and linked docs return the same list.
The FilteredElementCollector is getting the actual SharedParameterElements that exist in the model. That is all the shared parameters that have been loaded into a family or project. It has nothing to do with the current SPF.
Compare it to if you collected all the ParameterElements in the current document. This would be the actual elements representing a parameter that exist within a family or doc. There’s no “source” here to choose from because it’s the actual elements.
If you want the parameters from the SPF then you have to get them from the SPF. The currently active SPF doesn’t actually interact with the current document. It’s just a source for pulling parameter definitions at the time of import.
This post may be helpful.
In order to get the corresponding SharedParameterElements that exist within the active SPF, I think you’d have to compare both sources (GUID from SPF with GUID from elements). This of course would only work for parameters that have been loaded into the project via families or project parameters though.
Sorry for all the confusion I just realised that these parameter are coming from the Project Template that I have been using and most of them are still available of the SPF which created this confusion in the first place. I actually get a null value when I open a file with out any revit template applied.