Get Parameter Values from Room

Get Parameter Values from Room

Kevin.Bell
Advisor Advisor
2,412 Views
3 Replies
Message 1 of 4

Get Parameter Values from Room

Kevin.Bell
Advisor
Advisor

Hi,

 

I'm moving from Python to C# and am trying to convert my plugin which obtains data from Room objects.

 

In Python I can obtain a rooms Number with the following method:

 

Create a FilteredElementCollector of all rooms and then convert to Eleemnts, then loop through the elements list with the variable f:

 

paramsnum = f.GetParameters('Number')

 

This returns the Number parameter value in the variable paramsnum.

 

This works fine, but I'm struggling to do this in c#:

 

            //Get all rooms
            FilteredElementCollector allrooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms);

            //Convert room list to elements
            ICollection<Element> allroomelements = allrooms.ToElements();

            // Create list of room numbers (from Number parameter)
            List<string> numslist = new List<string>();

            foreach (Element f in allroomelements)
            {
                Debug.Print(f.Name);
                IList<Parameter> paramsnum = f.GetParameters("Number");
            }

This executes, but paramsnum is not a string I can use, I cannot obtain the value from an IList.

 

Where am I going wrong?

 

Thanks.

0 Likes
2,413 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk

Dear Archie.

 

I would strongly recommend you start off working through the .NET C# Revit API getting started material before doing anything else at all, especially the DevTV and My First Revit Plugin tutorials:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

That will immediately answer your question and many more, saving both you and the rest of the world lots of time and effort.

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 4

joshua.lumley
Advocate
Advocate

 

How do you check of a parameter exists?

The below code does not work on : OST_Views, OST_Room & OST_DetailComponents


if (null != doc2.GetElement(doc2.GetElement(id).GetTypeId()).GetParameters("Family Name"))

 

It keeps coming up with an error message, and I have tried. 

 

 if (0 !=  doc2.GetElement(doc2.GetElement(id).GetTypeId()).GetParameters("Family Name").Count)

 

0 Likes
Message 4 of 4

Anonymous
Not applicable

You should be able to do it like this: 

 

            ICollection<Element> allRooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).ToElements();
            List<string> roomNumbers = allRooms.Select(x => ((Room)x).Number).ToList();

Few key things to keep in mind here are the differences between Python and C#. C# is strong typed and doesn't fare well with unknown types. Python doesn't have that "issue" since it just tries all possible overloads. C# was meant to be a little more efficient and wants you to define a type that you are working with. What I am getting at here, is that where's you can just do FilteredElementCollector query in Python and then ask returned elements for a Number, you can't do that with C# before you cast Element to Room. 

 

Give it a try.