C# - Get family parameter and perform if statement with said paramete

C# - Get family parameter and perform if statement with said paramete

mmorocco
Participant Participant
819 Views
3 Replies
Message 1 of 4

C# - Get family parameter and perform if statement with said paramete

mmorocco
Participant
Participant

Hello!

 

I am new to C# and would like a jumping off point if someone would help me.

 

What i have in my project:

family: Receptacle

Type: duplex receptacle, quadraplex, (this list can grow)

parameter: Error (yes no)

 

what i want:

A message to appear when error message is true.

I would need the error message to display which family type is containing the error. if more than one type, I would like it to then be a list of error reported types. This would make finding the family type that needs to be fixed easier.

 

I am not asking for the huge lines of code (that would be awesome if you did lol) but a jumping off point of what code to use to get family, types, parameters and then initiating a if statement with dialog box in revit. 

 

If anyone can help point me in the right direction, that would be great! thank you!

0 Likes
820 Views
3 Replies
Replies (3)
Message 2 of 4

mmorocco
Participant
Participant

 

Right now, we use a schedule to see which types are reporting the error. Problem is, if someone new is working and doesnt know to check the schedule for the error they will not know the family is broken. It would be nice to have a dialog box appear once the shared parameter "Error" becomes yes. 

 

 

 

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

hello,

 

I think you're looking for something like this: http://thebuildingcoder.typepad.com/blog/2009/05/selecting-model-elements.html

 

Then, inside the last If block

if( null != e.get_Geometry( opt ) )
        {
          elems.Insert( e );
        }

you could put something like this:

ElementId id = e.GetTypeId();
            ElementType elementType = document.GetElement(id) as ElementType; 
            foreach (Parameter para in elementType.Parameters)
            {
                if (para.Definition.Name == "YourSharedParameter")
                {
                    //do your thing
                }

            }

Good luck!

Ruben

 

0 Likes
Message 4 of 4

mmorocco
Participant
Participant

Thank you for the response Ruben!

 

But it seems that code doesn't work with versions after 2009. I tried doing what you said to no avail. Tried the code by itself and received a lot of errors. I bet the code i needs is somewhere in there and needs to be altered.

 

I will keep trying to piece things together. If i find an answer I will let you know. Thank you.

0 Likes