Set Parameter

Set Parameter

Tripler123
Advocate Advocate
828 Views
2 Replies
Message 1 of 3

Set Parameter

Tripler123
Advocate
Advocate

Hello,

I wanted to run this little code. The goal of the code is set a parameter from other parameters, but I get this error when I run.

Mensaje de error.PNG

this is my code,

 

 

namespace LastPlannerSystem_4D
{
    [Transaction(TransactionMode.Manual)]
    class CrearCodigo : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData,
                              ref string message,
                              ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Application app = uiapp.Application;
            Document doc = uiapp.ActiveUIDocument.Document;

    
            List<Element> lstFloor = GetElementType(doc, typeof(Floor));

string nivel = "";
            string sector = "";
            string elemento = "";
            string codigo = "";
            int i = 1;

            try
            {
                foreach (Element e in lstWall)
                {
                    ParameterSet parameters = e.Parameters;
                    foreach (Parameter param in parameters)
                    {
                        if (param.Definition.Name.Equals("Codigo de Identidad"))
                        {
                            using (Transaction t = new Transaction(doc, "Set Parameter"))
                            {
                                nivel = ParameterToString(e.LookupParameter("Piso / Nivel"));
                                sector = ParameterToString(e.LookupParameter("Sector"));
                                elemento = ParameterToString(e.LookupParameter("Elemento"));
                                codigo = nivel.Substring(0, 3) + nivel.Substring(nivel.Length-2, 2) + "-S" + sector.Substring(7, 1) + "-" + elemento.Substring(0, 3) + i.ToString();
                                i = i + 1;

                                t.Start();
                                param.Set(codigo);
                                t.Commit();
                            }
                        }
                    }
                }
                TaskDialog.Show("Report", "Done!");
            }
            catch (Exception e)
            {
                TaskDialog.Show("Error Information", e.Message);
            }

            TaskDialog.Show("Cantidad de elementos", (i-1).ToString());
            return Result.Succeeded;
        }

public List<Element> GetElementType(Document doc, Type type)
        {
            List<Element> elements = new List<Element>();
            FilteredElementCollector elementCollector = new FilteredElementCollector(doc).OfClass(type);

            foreach (Element e in elementCollector)
            {
                elements.Add(e);
            }

            return elements;

        }

 

 

 

 

 

0 Likes
829 Views
2 Replies
Replies (2)
Message 2 of 3

matthew_taylor
Advisor
Advisor

Hi @Tripler123

lstWall and lstFloor seem to be the issue.

If you change that and still have an issue, check out this post:

http://thebuildingcoder.typepad.com/blog/2016/10/ai-edit-and-continue.html#2

You should do some validation. (Check if parameters exist etc.)

Also, you will want to take the transaction outside the 'foreach' loops.


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 3

Tripler123
Advocate
Advocate

Hello,

 

Thank you very much for the quick response. I have confused myself in sending the code. Has reason lstFloor used in the original code. I have problems with the list I get from floors. I will review the post.

 

Thanks,

0 Likes