Hi everyone:
I've been trying to modifiy a parameter of an element. In my code I call the method "ModificarParametroElemento" with a specific parameter name, but the problem is when i calling the class "get_Parameter()" because the class only accepts (GUID's, BuiltInParameter, Definitions) and I dont know how i get the element parameter with my string text.
Thanks!
//IN THIS PART I'VE BEEN CALLING THE METHOD "ModificarParametrosElemento" TO PROCEED
this.ModificaParametrosElemento(elementId2.IntegerValue, num3.ToString(), this.document, "Union 16");
//METHOD private bool ModificaParametrosElemento(int ID, string ValorParam, Document Documento, string StrParametro) { bool result; try { ElementId elementId = new ElementId(ID); Element element = this.document.GetElement(elementId); if (element != null) { ParameterSet arg_20_0 = element.Parameters; Parameter parameter = element.get_Parameter(StrParametro); if (parameter != null) { switch (parameter.StorageType) { case (StorageType)(1): element.get_Parameter(StrParametro).Set(Convert.ToInt32(ValorParam)); break; case (StorageType)(2): element.get_Parameter(StrParametro).Set(double.Parse(ValorParam)); break; case (StorageType)(3): element.get_Parameter(StrParametro).Set(ValorParam); break; case (StorageType)(4): element.get_Parameter(StrParametro).Set(new ElementId(int.Parse(ValorParam))); break; } } } result = true; } catch (Exception ex) { TaskDialog.Show("ModificaParametrosElemento", ex.Message, (TaskDialogCommonButtons)(1)); result = false; } return result; }
Dear Carlos,
What version of Revit are you using ? 2015 ? or some earlier one. One thing I can think of if you are using 2015 or newer is to use LookupParameter instead of get_Parameter, for a couple of reasons.
- get_Parameter is an obsolete method and has been depracated in Revit 2015 (see attached for explanation)
- LookupParameter will return you the first available parameter with a given name,
I think this is what you are trying to do, If not please explain and It will help me better if you can submit a small ready-to-build command to investigate and also a more in detail explanation of what you are trying to do.
Thanks
I have some code that would allow you get the GUID of a shared parameter if you are completely stuck,
static Guid SharedParamGuid(Application app, string defGroup, string defName, DefinitionFile file) { Guid guid = Guid.Empty; try { file = app.OpenSharedParameterFile(); DefinitionGroup group = file.Groups.get_Item(defGroup); Definition definition = group.Definitions.get_Item(defName); ExternalDefinition externalDefinition = definition as ExternalDefinition; guid = externalDefinition.GUID; } catch (Exception) { } return guid; }
reply was meant for the poster sorry rosalesduquej
Hi there! If get_Parameter is obsolete, what is the correct and efficient way to get the BuiltInParameter? I cannot find the method allowing BuiltInParameter type as the argument... Iterating all parameters is not efficient. But LookupParameter need string name of the parameter and cause localization issues.
Indeed get_parameter is for builtinparameter.
You want to use .LookupParameter("yourparameter") .String() instead, because is a user parameter.