FILTER WITH SHARED PARAMETER. GUID ID.

FILTER WITH SHARED PARAMETER. GUID ID.

juancalvoferrandiz
Enthusiast Enthusiast
2,512 Views
6 Replies
Message 1 of 7

FILTER WITH SHARED PARAMETER. GUID ID.

juancalvoferrandiz
Enthusiast
Enthusiast

Hello everyone!

As matthew.taylor has suggested I'm creating a post with a query which I'm strugguling since a few days ago:

 

OBJECTIVE: Filter the elements in my model of a category I choose with a shared parameter yes/no.

 

ACTUAL SITUATION: At this moment, I know how get my objective but using the GUID number directly, looking at it in the .txt or the fantastic "Lookup" addin.

 

int ruleValInt = 1;
Element firstdoorElement = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).FirstElement(); Parameter SharedParamGUIDID = firstdoorElement.get_Parameter(new Guid("6b79a46d-8d2a-4071-8069-86dc9c0f2c68")); ParameterValueProvider pvp = new ParameterValueProvider(SharedParamGUIDID.Id); FilterNumericEquals fnrv = new FilterNumericEquals(); FilterIntegerRule paramFr = new FilterIntegerRule(pvp, fnrv, ruleValInt); ElementParameterFilter epf = new ElementParameterFilter( paramFr ); FilteredElementCollector doors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WherePasses(epf); doors.OfClass(typeof(FamilyInstance));

 

 

MAIN QUERY: I want to know how to get and use the GUID from the .txt or the category(or element). I have this code that dosen't give any error in Visual, but dosent work when I do the debugging:

 

Element firstdoorElement = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).FirstElement();
var sharedParamGuid = firstdoorElement.LookupParameter(LabConstants.SharedParamsGroupAPI).GUID;
Parameter SharedParamGUIDID = firstdoorElement.get_Parameter(sharedParamGuid);


ParameterValueProvider pvp = new ParameterValueProvider(SharedParamGUIDID.Id);
FilterNumericEquals fnrv = new FilterNumericEquals();
FilterIntegerRule paramFr = new FilterIntegerRule(pvp, fnrv, ruleValInt);
ElementParameterFilter epf = new ElementParameterFilter( paramFr );

FilteredElementCollector doors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors).WherePasses(epf); ;
doors.OfClass(typeof(FamilyInstance));

 

SECOND QUERY: It's possible to write the GUID I want to use? Example: "7b7b77b-7b7b-7777-7777-77bb7b77bb77" I want to do this in case I use families created before with the same shared parameter name and group, but different GUID. My intention is to create always this parameter with the same GUID so I can filter independently from when it was created.

 

REFERENCES :

 

https://forums.autodesk.com/t5/revit-api-forum/get-all-elements-in-a-project-that-have-a-parameter-w...

http://thebuildingcoder.typepad.com/blog/2015/12/shared-project-parameter-guid-reporter.html

http://spiderinnet.typepad.com/blog/2011/07/elementparameterfilter-using-sharedparameterapplicableru...

https://forums.autodesk.com/t5/revit-api-forum/get-parameter-guid-directly-from-shared-parameter-fil...

 

 

 

 

Any comment is wellcome. Thanks for your time. Have a nice day.

 

0 Likes
2,513 Views
6 Replies
Replies (6)
Message 2 of 7

matthew_taylor
Advisor
Advisor

Hello @juancalvoferrandiz,

Thanks for making the new post.

Without looking at your code too much, have you seen the ParameterFilterRuleFactory class? http://www.revitapidocs.com/2017.1/e6646480-b0ce-b299-3996-e965c913f9c4.htm

When testing filters, add a layer at a time and check that your results are as expected along the way. Not all filters act as I expect them to, perhaps the same applies to you?

As for your GUID question. If the GUID varies, then just using the shared parameter name could be the best tactic. Or search for a selection of GUIDs.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes
Message 3 of 7

juancalvoferrandiz
Enthusiast
Enthusiast

Thanks Matthew for your quick answer.

 

PRINCIPAL QUERY: I didn,t know about ParameterFilterRuleFactory class. I will take a look at it as soon as possible.

 

I have detect that my problem is with this line. When debugging the message I get is this one:

 

Screenshot (29).png


RIght now, I dont know what it refers to.

 


SECOND QUERY: The problem I think I have if I use the name parameter, is that I can end with more than 1 parameter if they have different GUID. Thats why I think a good option to be sure, that the shared parameter I have has the same GUID and name, all the ocassions I create it or/and use it.

 

Thanks.

 

Have a nice day.

 

 

0 Likes
Message 4 of 7

matthew_taylor
Advisor
Advisor

Hi @juancalvoferrandiz,

No problem.

You are calling for the GUID in the same line as the LookupParameter.

If you put the lookupParameter on the first line, then get the guid on the second line, you'll (probably) find that the same exception happens on the second line - the parameter hasn't been found. So provide a test for Parameter=nothing, and an alert so you know that this has happened.

 

You don't note what your constant is. If it's not the parameter name, then that's the issue. If it is, then it (the parameter) doesn't exist.

 

You could filter for door elements that definitely have the relevant parameter, so that you know that the parameter exists.


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 5 of 7

FAIR59
Advisor
Advisor

For shared parameters you don't need to have an element with that parameter. The SharedParameterElement exists independent in the document.

 

if you know the GUID :

SharedParameterElement shParamElement = SharedParameterElement.Lookup(doc, new Guid("088dc720-c070-40bb-b838-b1e34b47b46f"));

ParameterValueProvider pvp = new ParameterValueProvider(shParamElement.Id);

 

or you can search for a parameter by name in this List;

 

List<SharedParameterElement> shParamElements = new FilteredElementCollector(doc)

.OfClass(typeof(SharedParameterElement))

.Cast<SharedParameterElement>()

.ToList();

 

Message 6 of 7

juancalvoferrandiz
Enthusiast
Enthusiast

PRINCIPAL QUERY (SOLVED): Thanks Matthew. I'm relative new to coding. Your tips where very useful to stablish a methodology to how detect errors. My problem was that I was detecting all elements in the file, not just in the model. With "ofClass(typeof(FamilyInstance))" everything solved.

 

I will try your code soon Fair59. Thanks aswell.

 

SECOND QUERY: I just need now to see if I can define by the API the GUID of the shared parameter when I create it.

 

Have a nice week.

 

Cheers.

0 Likes
Message 7 of 7

matthew_taylor
Advisor
Advisor

Hi @juancalvoferrandiz,

One way is to load the shared parameter definition from file. There is an example here.

 


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?