Message 1 of 3
Set Parameter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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; }