Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with get_Parameter

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
2034 Views, 5 Replies

Problem with get_Parameter

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; }

 

5 REPLIES 5
Message 2 of 6
rosalesduquej
in reply to: Anonymous

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)

Screen Shot 2015-08-19 at 5.13.44 PM.png

- 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



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
Message 3 of 6
Mendo123
in reply to: rosalesduquej

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 

Message 4 of 6
sfadeev
in reply to: Mendo123

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.

Message 5 of 6
Yien_Chao
in reply to: Anonymous

Indeed get_parameter is for builtinparameter.

You want to use .LookupParameter("yourparameter") .String() instead, because is a user parameter.

 

 

 

Message 6 of 6
Yien_Chao
in reply to: Yien_Chao

Oups i meant .AsString()

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community