Beginner's Guide to get and set instance parameter

The video is an introduction on how an instance parameter within Revit API.  An element is selected through the pick tool and the instance parameter is selected (set), viewed and updated (set).


Sample code:

           UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uidoc.Document;

            Element e = SelectElement(uidoc, doc);
            Parameter parameter = e.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET);

            using (Transaction t = new Transaction(doc, "param"))
            {
                t.Start("param");
                try
                {
                    parameter.Set(-5);// 5 feet
                }
                catch { }
                t.Commit();
                TaskDialog.Show("New Value", GetParameterValue(parameter));

            }


//*****************************GetParameterValue()*****************************
        public string GetParameterValue(Parameter parameter)
        {
            switch (parameter.StorageType)
            {
                case StorageType.Double:
                    //get value with unit, AsDouble() can get value without unit
                    return parameter.AsValueString();
                case StorageType.ElementId:
                    return parameter.AsElementId().IntegerValue.ToString();
                case StorageType.Integer:
                    //get value with unit, AsInteger() can get value without unit
                    return parameter.AsValueString();
                case StorageType.None:
                    return parameter.AsValueString();
                case StorageType.String:
                    return parameter.AsString();
                default:
                    return "";
            }

        }


Tips:
  • Methods: Containers, which reusable code can be added to create an object.  Methods are helpful to break out your code in small portions.  This will help you debug your code.  
Example: 
Public string methodName ( string parameter1, string paramter2)
{
    //DO SOMETHING
}

Comments

  1. Is "SelectElement(uidoc, doc)" also a method created by yourself? Or we need to using something at the beginning. I could not find this method.

    ReplyDelete

Post a Comment

Popular Posts