Makro in Revit

,

Hello,
I have makro code written by a previous employee
image

/*
 * Created by SharpDevelop.
 * User: xxx
 * Date: 2020-01-15
 * Time: 14:29
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;

namespace ElevationParameterENU
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.DB.Macros.AddInId("35453963-A3B1-4F75-9656-3149B8DA9BD0")]
	public partial class ThisDocument
	{
		private void Module_Startup(object sender, EventArgs e)
		{

		}

		private void Module_Shutdown(object sender, EventArgs e)
		{

		}

		#region Revit Macros generated code
		private void InternalStartup()
		{
			this.Startup += new System.EventHandler(Module_Startup);
			this.Shutdown += new System.EventHandler(Module_Shutdown);
		}
		#endregion
		public void OpeningTag()
		{
            
            //UIDocument uidoc = ActiveUIDocument;
            Document doc = this.Application.ActiveUIDocument.Document;
            
            
            // 1. All Generic Instances
            ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel);
            IList<Element> instanceList = new FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType().ToElements();

            // To select and count instances at completion
            IList<ElementId> toSelect = new List<ElementId>();
            long count = 0;

            // 2. Conditioned Instances            
            foreach (Element ins in instanceList)
            {                
                
                double elevation = 0;
                IList<bool> flag = new List<bool>();
                bool heightIsAvailable = false;
                bool BasedLevelIsAvailable = false;
                ParameterSet paramSet = ins.Parameters; 

                foreach (Parameter param in paramSet)
                {
                    
                    if (param.Definition.Name.Equals("Elevation"))
                    {
                        elevation = param.AsDouble();
                    }
                }
                // The separation of the two loops is necessary to avoid confusion in taking parameter value
                foreach (Parameter param in paramSet)
                {
                    if (heightIsAvailable = BasedLevelIsAvailable = true && param.Definition.Name.Equals("Oś otworu")) // "Oś otworu" - custom instance parameter"
                    {
                        using (Transaction t = new Transaction(doc, "Set parameters value"))
                        {
                            t.Start();
                            param.Set(elevation);
                            t.Commit();
                            count += 1;
                            flag.Add(true);
                        }
                    }
                }                
                if (flag.Contains(true))
                {
                    toSelect.Add(ins.Id);
                }
            }
            // 4. Report 
            if (toSelect.Count > 0)
            {
                TaskDialog.Show("Wykonano na " + count + " otworach", "Zakończono: Rzędna - oś otworu - otwór okrągły oraz otwór prostokątny");
            }
            else
            {
                TaskDialog.Show("Revit", "Nie znaleziono obiektów");
            }
            UIDocument uidoc = new UIDocument(doc);
            uidoc.Selection.SetElementIds(toSelect);
            }
	}
}

the code worked in version 2018.3, but in 2022.1 it does not complete the values properly (enters 0.00 in each point):
Should be:

It is:

Have any of you encountered this problem and have a solution? I’m asking here because I don’t work in C# however I need to fix this :laughing:

This is likely a question for the Revit forums or maybe a forum around macros/C# since it’s not Dynamo related.

Are you sure it’s not that just parameter names are changed within the family?

I see it is reading the data from a parameter, called “Elevation”, while in your screenshot you are pointing towards one, called “Elevation from Level” ?

btw I think this could be solved by placing a few formulas withing the family itself, so that you don’t even need a macro :slight_smile:

offtopic: it’s funny how close our languages are, I’ve made a similar family with a parameter, called “Centar Otvor” :smiley: