Resolving duplicate tags Step 3 – get & set parameter values

Now that we can find the doors, the next step is to find the Mark parameter of each one. This is done with get_Parameter(“Mark”) and the AsString() method. The code below will show a dialog box with the mark value for each door in the project.

foreach (Element e in collector.OfCategory(BuiltInCategory.OST_Doors).OfClass(typeof(FamilyInstance)).ToList())
{
    Parameter p = e.get_Parameter("Mark");
    TaskDialog.Show("Revit",p.AsString());
}

Now that we can get the mark of every door, there are multiple ways we could proceed:

  1. Renumber every door, regardless of whether or not it is a duplicate. If we start with doors 1, 2, 3, 1, 2, 3 we could renumber them to 100, 101, 102, 103, 104, 105, 106.
  2. Sequentially renumber the doors that are duplicates. If we start with doors 1, 2, 3, 1, 2, 3 we could leave the first 1, 2, 3 doors as-is and renumber the last 3 doors, resulting in 1, 2, 3, 4, 5, 6. This isn’t too hard in the 1, 2, 3, 1, 2, 3 case, but if we are starting with 1, 5, 8, 9, 1, 2, 5 then it will be a bit trickier to figure out that the 2nd door with number 1 should become #3.
  3. Change the duplicate doors so we have something like 1, 2, 3, 1*, 2*, 3*
  4. Prompt the user for new numbers
  5. etc.

Options 1 & 3 are fairly straightforward, and I will show #3 here. Please leave a comment if you are interested in some of the other solutions.

To implement #3, build a list containing each mark # as it is encountered. Then, if a door’s mark value is already in the list it needs to be changed. If the value is not in the list then it needs to be added to the list.

An empty list is created with

IList<string> markValues = new List<string>();

and the logic to add to the list or set a new value is

if (markValues.Contains(p.AsString()))
  p.Set(p.AsString() + "*");
else
  markValues.Add(p.AsString());

The “+” is the string concatenation operator, so p.AsString() + “*” appends an asterisk at the end of the mark’s existing value.

Advertisements

2 thoughts on “Resolving duplicate tags Step 3 – get & set parameter values

  1. I’m interested in two additional options. Prompting the user for new numbers (I’m assuming it would only prompt for the duplicates? The other option I’m curious about is if Revit has the ability to understand direction. Am I able to create a rule that doors are to be numbered from east to west (from north to south let’s say)? There’s obviously a certain ammount of coordination that would have to take place in a true project situation. But in terms of concept, I’ve always wondered if we’re able to use directionality…

    Thanks again! You’re instruction is excellent. Great pace, easy to follow!!! I’ve been starving for something like this!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s