Пример #1
0
 private void SetParameters(Grid grid, IEnumerable<RevitParameter> parameters, Document doc)
 {
     foreach (RevitParameter rp in parameters)
     {
         try
         {
             Parameter p = grid.LookupParameter(rp.ParameterName);
             switch (rp.StorageType)
             {
                 case "Double":
                     if (p.Definition.ParameterType == ParameterType.Area)
                         p.Set(UnitUtils.ConvertToInternalUnits(Convert.ToDouble(rp.Value), areaDUT));
                     else if (p.Definition.ParameterType == ParameterType.Volume)
                         p.Set(UnitUtils.ConvertToInternalUnits(Convert.ToDouble(rp.Value), volumeDUT));
                     else if (p.Definition.ParameterType == ParameterType.Length)
                         p.Set(UnitUtils.ConvertToInternalUnits(Convert.ToDouble(rp.Value), lengthDUT));
                     else
                         p.Set(Convert.ToDouble(rp.Value));
                     break;
                 case "Integer":
                     p.Set(Convert.ToInt32(rp.Value));
                     break;
                 case "String":
                     p.Set(rp.Value);
                     break;
                 case "ElementId":
                     try
                     {
                         int idInt = Convert.ToInt32(rp.Value);
                         ElementId elemId = new ElementId(idInt);
                         Element elem = doc.GetElement(elemId);
                         if (elem != null)
                         {
                             //TaskDialog.Show("Test:", "Param: " + p.Definition.Name + "\nID: " + elemId.IntegerValue.ToString());
                             p.Set(elemId);
                         }
                     }
                     catch
                     {
                         try
                         {
                             p.Set(p.Definition.ParameterType == ParameterType.Material
                                 ? GetMaterial(rp.Value, doc)
                                 : new ElementId(Convert.ToInt32(rp.Value)));
                         }
                         catch (Exception ex)
                         {
                             //TaskDialog.Show(p.Definition.Name, ex.Message);
                         }
                     }
                     break;
                 default:
                     p.Set(rp.Value);
                     break;
             }
         }
         catch
         {
             try
             {
                 Parameter p = grid.GridType.LookupParameter(rp.ParameterName);
                 switch (rp.StorageType)
                 {
                     case "Double":
                         if (p.Definition.ParameterType == ParameterType.Area)
                             p.Set(UnitUtils.ConvertToInternalUnits(Convert.ToDouble(rp.Value), areaDUT));
                         else if (p.Definition.ParameterType == ParameterType.Volume)
                             p.Set(UnitUtils.ConvertToInternalUnits(Convert.ToDouble(rp.Value), volumeDUT));
                         else if (p.Definition.ParameterType == ParameterType.Length)
                             p.Set(UnitUtils.ConvertToInternalUnits(Convert.ToDouble(rp.Value), lengthDUT));
                         else
                             p.Set(Convert.ToDouble(rp.Value));
                         break;
                     case "Integer":
                         p.Set(Convert.ToInt32(rp.Value));
                         break;
                     case "String":
                         p.Set(rp.Value);
                         break;
                     case "ElementId":
                         try
                         {
                             int idInt = Convert.ToInt32(rp.Value);
                             ElementId elemId = new ElementId(idInt);
                             Element elem = doc.GetElement(elemId);
                             if (elem != null)
                             {
                                 //TaskDialog.Show("Test:", "Param: " + p.Definition.Name + "\nID: " + elemId.IntegerValue.ToString());
                                 p.Set(elemId);
                             }
                         }
                         catch
                         {
                             try
                             {
                                 p.Set(p.Definition.ParameterType == ParameterType.Material
                                     ? GetMaterial(rp.Value, doc)
                                     : new ElementId(Convert.ToInt32(rp.Value)));
                             }
                             catch (Exception ex)
                             {
                                 //TaskDialog.Show(p.Definition.Name, ex.Message);
                             }
                         }
                         break;
                     default:
                         p.Set(rp.Value);
                         break;
                 }
             }
             catch (Exception ex)
             {
                 TaskDialog.Show("Error", ex.Message);
             }
         }
     }
 }