private string CheckParam(Parameter p) { List <string> boolList = new List <string>() { "Вариант конструкции", "Включить аналитическую модель", "Граница помещения", "Использование в конструкции", "Несущие конструкции", "Примыкание сверху", "Примыкание снизу", "Связь с формообразующим элементом", "Перемещать с соседними элементами", "3D", "Метка сверху", "Метка снизу", "Показать стрелку вверх на всех видах", "Стрелка сверху", "Стрелка снизу", "Выноска", "Код основы", "Перемещать с сеткой", "Расчет коэффициента использования", "Сохранять пропорции", "Построение этажа", "Mortat Visibility" }; List <string> valueList = new List <string>() { "Слой построений", "Выравнивание", "Рабочий набор", "Линия привязки", "Правило компоновки", "Выравнивание по оси Y", "Выравнивание по оси Z", "Выравнивание по осям YZ", "Использование в конструкции", "Местоположение условного знака", "Тип привязки в конце", "Тип привязки в начале", "Привязка к грани", "Ориентация", "Тип выноски", "Стиль колонн", "Слой построений" }; if (boolList.Contains(p.Definition.Name)) { if (p.AsInteger() == 0) { return("Нет"); } else if (p.AsInteger() == 1) { return("Да"); } else if (p.AsInteger() == -1) { return("Отстствует"); } } if (valueList.Contains(p.Definition.Name)) { return(p.AsValueString()); } return(""); }
void CopyParameter(Parameter cpFrom, Parameter cpTo) { switch (cpFrom.StorageType) { case StorageType.String: cpTo.Set(cpFrom.AsString()); break; case StorageType.Integer: cpTo.Set(cpFrom.AsInteger()); break; case StorageType.Double: cpTo.Set(cpFrom.AsDouble()); break; case StorageType.ElementId: cpTo.Set(cpFrom.AsInteger()); break; case StorageType.None: throw new Exception(); default: throw new Exception(); } }
/// <summary> /// Helper function: return a string form of a given parameter. /// </summary> public static string ParameterToString(Document doc, Parameter param) { dynamic val = "none"; if (param == null) { return(val); } // To get to the parameter value, we need to pause it depending on its storage type switch (param.StorageType) { case StorageType.Double: // Extract the value and convert it from Revit internal uom to metric val = param.AsValueString(); break; case StorageType.Integer: if (ParameterType.YesNo == param.Definition.ParameterType) { if (param.AsInteger() == 0) { val = "False"; } else { val = "True"; } } else { int iVal = param.AsInteger(); val = iVal.ToString(); } break; case StorageType.String: string sVal = param.AsString(); val = sVal; break; case StorageType.ElementId: ElementId idVal = param.AsElementId(); string stVal = "null"; if (idVal.IntegerValue >= 0) { stVal = doc.GetElement(idVal).Name; } val = stVal; break; case StorageType.None: break; } return(val); }
static String GetParameterInformation(Parameter para, Document document) { string defName = para.Definition.Name + "\t : "; string defValue = string.Empty; // Use different method to get parameter data according to the storage type switch (para.StorageType) { case StorageType.Double: //covert the number into Metric defValue = para.AsValueString(); break; case StorageType.ElementId: //find out the name of the element Autodesk.Revit.DB.ElementId id = para.AsElementId(); if (id.IntegerValue >= 0) { defValue = document.GetElement(id).Name; } else { defValue = id.IntegerValue.ToString(); } break; case StorageType.Integer: if (ParameterType.YesNo == para.Definition.ParameterType) { if (para.AsInteger() == 0) { defValue = "False"; } else { defValue = "True"; } } else { defValue = para.AsInteger().ToString(); } break; case StorageType.String: defValue = para.AsString(); break; default: InternalDefinition def = para.Definition as InternalDefinition; BuiltInParameter bp = def.BuiltInParameter; defValue = "Unexposed parameter."; break; } return(defName + defValue); }
private static string GetParameterInfo(Parameter p) { string result = ""; switch (p.StorageType) { case StorageType.None: { result += p.AsString(); break; } case StorageType.Double: //covert the number into Metric result += " : " + p.AsValueString(); break; case StorageType.ElementId: //find out the name of the element ElementId id = p.AsElementId(); if (id.IntegerValue >= 0) { result += " : " + Doc.GetElement(id).Name; } else { result += " : " + id.IntegerValue.ToString(); } break; case StorageType.Integer: if (ParameterType.YesNo == p.Definition.ParameterType) { if (p.AsInteger() == 0) { result += " : " + "False"; } else { result += " : " + "True"; } } else { result += " : " + p.AsInteger().ToString(); } break; case StorageType.String: result += " : " + p.AsString(); break; default: result = "Unexposed parameter."; break; } return(result); }
private void CollectRevisions() { ElementCategoryFilter catFilter = new ElementCategoryFilter(BuiltInCategory.OST_Revisions); FilteredElementCollector collector = new FilteredElementCollector(m_doc); List <Element> revisionElements = collector.WherePasses(catFilter).ToElements().ToList(); foreach (Element element in revisionElements) { RevisionData rd = new RevisionData(); Parameter param = element.get_Parameter(BuiltInParameter.PROJECT_REVISION_SEQUENCE_NUM); if (null != param) { rd.Sequence = param.AsInteger(); } param = element.get_Parameter(BuiltInParameter.PROJECT_REVISION_REVISION_NUM); if (null != param) { rd.Number = param.AsString(); } param = element.get_Parameter(BuiltInParameter.PROJECT_REVISION_REVISION_DESCRIPTION); if (null != param) { rd.Description = param.AsString(); } param = element.get_Parameter(BuiltInParameter.PROJECT_REVISION_REVISION_DATE); if (null != param) { rd.Date = param.AsString(); } param = element.get_Parameter(BuiltInParameter.PROJECT_REVISION_REVISION_ISSUED); if (null != param) { rd.Issued = Convert.ToBoolean(param.AsInteger()); } param = element.get_Parameter(BuiltInParameter.PROJECT_REVISION_REVISION_ISSUED_TO); if (null != param) { rd.IssuedTo = param.AsString(); } param = element.get_Parameter(BuiltInParameter.PROJECT_REVISION_REVISION_ISSUED_BY); if (null != param) { rd.IssuedBy = param.AsString(); } if (!revisionDictionary.ContainsKey(rd.Sequence)) { revisionDictionary.Add(rd.Sequence, rd); } } }
//***********************************GetParameterInformation*********************************** private Tuple <string, string> GetParameterInformation(Document document, Parameter para) { string defName = para.Definition.Name; string defValue = string.Empty; // Use different method to get parameter data according to the storage type switch (para.StorageType) { case StorageType.Double: //covert the number into Metric double roundDouble = Math.Round(para.AsDouble(), 3); defValue = roundDouble.ToString(); break; case StorageType.ElementId: //find out the name of the element Autodesk.Revit.DB.ElementId id = para.AsElementId(); if (id.IntegerValue >= 0) { defValue = document.GetElement(id).Name; } else { defValue = id.IntegerValue.ToString(); } break; case StorageType.Integer: if (ParameterType.YesNo == para.Definition.ParameterType) { if (para.AsInteger() == 0) { defValue = "False"; } else { defValue = "True"; } } else { defValue = para.AsInteger().ToString(); } break; case StorageType.String: defValue = para.AsString(); break; default: defValue = "Unexposed parameter."; break; } return(Tuple.Create(defName, defValue)); }
public ParameterModel GetParameterInformation(Parameter para, Document document, int idOfModel) { string defName = para.Definition.Name; string defValue = string.Empty; // Use different method to get parameter data according to the storage type switch (para.StorageType) { case StorageType.Double: //covert the number into Metric defValue = para.AsValueString(); break; case StorageType.ElementId: //find out the name of the element Autodesk.Revit.DB.ElementId id = para.AsElementId(); if (id.IntegerValue >= 0) { defValue = document.GetElement(id).Name; } else { defValue = id.IntegerValue.ToString(); } break; case StorageType.Integer: if (ParameterType.YesNo == para.Definition.ParameterType) { if (para.AsInteger() == 0) { defValue = "False"; } else { defValue = "True"; } } else { defValue = para.AsInteger().ToString(); } break; case StorageType.String: defValue = para.AsString(); break; default: defValue = "Unexposed parameter."; break; } return(new ParameterModel(idOfModel, defName, defValue, para.StorageType.ToString(), para)); }
//public static ParameterForm GetParameterForm(this Parameter param, Document doc) //{ // ParameterForm pf = ParameterForm.None; // Debug.WriteLine("This parameter's type is: " + param.Definition.ParameterType.ToString()); // if (!param.Definition.ParameterType.ToString().Equals("Invalid")) // { // try // { // DefinitionBindingMap dbm = doc.ParameterBindings; // Debug.WriteLine("The DefinitionBindingMap has " + dbm.Size.ToString() + "entries"); // Definition d = param.Definition; // Binding b = dbm.get_Item(d); // Debug.Assert(b is InstanceBinding, (d.Name + " is an instance")); // Debug.Assert(b is TypeBinding, (d.Name + " is a type")); // } // catch (Autodesk.Revit.Exceptions.InvalidObjectException invOe) // { // // coode // Debug.WriteLine("The object was invalid?" + "\n" + invOe.Message); // } // catch (Autodesk.Revit.Exceptions.InvalidOperationException auto_ioe) // { // // code // Debug.WriteLine("The operation was invalid?" + "\n" + auto_ioe.Message); // } // } // return pf; //} public static string GetParameterValue(this Parameter param) { try { switch (param.StorageType) { default: // A NULL VALUE MEANS THE PARAMETER IS UNEXPOSED return("PARAMETER HAS NOT BEEN EXPOSED"); case StorageType.Double: return(GetParameterDouble(param)); case StorageType.Integer: if (ParameterType.YesNo != param.Definition.ParameterType) { return("INTEGER: " + param.AsInteger().ToString()); } if (param.AsInteger() == 0) { return("False"); } return("True"); case StorageType.String: return(param.AsString()); case StorageType.ElementId: // this one is tricky // a positive ElementID can point to a specific element // however a negative one can mean a number of different things if (param.AsElementId().IntegerValue <= 0) { return("ELEMENTID: " + param.AsElementId().IntegerValue.ToString()); } using (Document paramdoc = param.Element.Document) { return(paramdoc.GetElement(param.AsElementId()).Name); } } } catch (InvalidObjectException invalidoex) { ExceptionReport.DebugLog(invalidoex); } return(null); }
public String GetParameterValue(Parameter para, Document document) { string value = ""; switch (para.StorageType) { case StorageType.Double: value += para.AsValueString(); break; case StorageType.ElementId: Autodesk.Revit.DB.ElementId id = para.AsElementId(); if (id.IntegerValue >= 0) { value += document.GetElement(id).Name; } else { value += id.IntegerValue.ToString(); } break; case StorageType.Integer: if (ParameterType.YesNo == para.Definition.ParameterType) { if (para.AsInteger() == 0) { value += "False"; } else { value += "True"; } } else { value += para.AsInteger().ToString(); } break; case StorageType.String: value += para.AsString(); break; default: value = "Unexposed parameter."; break; } return(value); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; if (doc.IsFamilyDocument) { message = "This command can only be used in a project, not in a family file."; return(Result.Failed); } // get the singleton project info element Element projInfoElem = LabUtils.GetProjectInfoElem(doc); if (null == projInfoElem) { message = "No project info elem found. Aborting command..."; return(Result.Failed); } // For simplicity, access invisible param by name rather than by GUID: try { Parameter param = projInfoElem.LookupParameter(LabConstants.ParamNameInvisible); // report OLD value int iOldValue = param.AsInteger(); LabUtils.InfoMsg("OLD value = " + iOldValue.ToString()); using (Transaction tx = new Transaction(doc)) { tx.Start("Set Parameter Value"); // set and report NEW value param.Set(iOldValue + 1); LabUtils.InfoMsg("NEW value = " + param.AsInteger().ToString()); tx.Commit(); } } catch (System.Exception e) { message = "Failed: " + e.Message; return(Result.Failed); } return(Result.Succeeded); }
//取得 parameter 內容 private CusParameter getParameterInfo(Parameter parm, Document doc) { string value = "< >"; string defname = parm.Definition.Name; switch (parm.StorageType) { case StorageType.Double: value = parm.AsValueString(); break; case StorageType.Integer: if (ParameterType.YesNo == parm.Definition.ParameterType) { if (parm.AsInteger() == 0) { value = "False"; } else { value = "True"; } } else { value = parm.AsInteger().ToString(); } break; case StorageType.ElementId: ElementId eid = parm.AsElementId(); if (eid.IntegerValue > 0) { value = doc.GetElement(eid).Name; } else { value = eid.IntegerValue.ToString(); } break; case StorageType.String: value = parm.AsString(); break; default: return(null); } return(new CusParameter(defname, value)); }
public string ElementValue(Parameter pa, string defName, Document doc) { switch (pa.StorageType) { case StorageType.Double: defName = pa.AsValueString(); break; case StorageType.ElementId: Autodesk.Revit.DB.ElementId id = pa.AsElementId(); if (id.IntegerValue >= 0) { defName = doc.GetElement(id).Name; } else { defName = id.IntegerValue.ToString(); } break; case StorageType.Integer: if (ParameterType.YesNo == pa.Definition.ParameterType) { if (pa.AsInteger() == 0) { defName = "False"; } else { defName = "True"; } } else { defName = pa.AsInteger().ToString(); } break; case StorageType.String: defName = pa.AsString(); break; default: defName = "Unexposed parameter."; break; } return(defName); }
/// <summary> /// this method is to judge the data type of parameter, /// and make correct conversions of parameter for return the parameter name and value as a string /// </summary> /// <param name="para"></param> /// <param name="doc"></param> /// <param name="seperator"></param> /// <returns></returns> private string getParameterInfomation(Parameter para, Document doc, string seperator) { string defName = para.Definition.Name;//get parameter name, which is the first half of the return value //switch the StorageType, which is a Enum for defining the data type switch (para.StorageType) { case StorageType.Double: //if the parameter is a double, use AsValueString() to return the value return(defName + seperator + para.AsValueString()); case StorageType.ElementId: //if the parameter is a element id, its IntegerValue would be either a positive integer or -1 //-1 means an invalid element id ElementId id = para.AsElementId(); if (id.IntegerValue >= 0) //if IntegerValue is not -1, we can get the parameter by Element.Name { return(defName + seperator + doc.GetElement(id).Name); } else //if IntegerValue is -1, print -1 because it is an invalid ElementId { return(defName + seperator + id.IntegerValue.ToString()); } case StorageType.Integer: //if the parameter is an integer, it would be a boolean or an integer if (ParameterType.YesNo == para.Definition.ParameterType) //if it is a boolean (0 or 1) { //we must use true or false to represent the parameter instead of 0 or 1 if (para.AsInteger() == 0) { return(defName + seperator + "False"); } else //para.AsInteger() == 1 { return(defName + seperator + "True"); } } else //if it is an integer, just use AsInteger().ToString() to get the string value { return(defName + seperator + para.AsInteger().ToString()); } case StorageType.String: //if it is a string, we can return it by AsString() return(defName + seperator + para.AsString()); default: return("unknown parameter"); } }//end fun
}//end fun //這個函式的原型公佈在官網上,我做了一點點修改並且加上註解 //https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2017/ENU/Revit-API/files/GUID-D003803E-9FA0-4B2B-AB62-7DCC3A503644-htm.html private Tuple <string, string, Type> getParameterInfomation(Parameter para, Document doc) { string defName = para.Definition.Name;//這是欄位名稱,而欄位值是比較麻煩的 //StorageType是Revit為了描述欄位變數型態而定義出來的enum switch (para.StorageType) //欄位值比需要區分變數類型來討論,設計得很不親切 { case StorageType.Double: //如果這個欄位的型態是double return(new Tuple <string, string, Type>(defName, para.AsString(), typeof(string))); case StorageType.ElementId: //如果欄位型態是ElementID識別碼,要分正整數及負整數討論 //因為是官網公佈應該這麼做的,因此從善如流 ElementId id = para.AsElementId(); if (id.IntegerValue >= 0) { return(new Tuple <string, string, Type>(defName, doc.GetElement(id).Name, typeof(int))); } else { return(new Tuple <string, string, Type>(defName, id.IntegerValue.ToString(), typeof(int))); } case StorageType.Integer: //如果欄位是整數,它還有可能是布林值的零或一,要再寫一個if-else if (ParameterType.YesNo == para.Definition.ParameterType) //如果欄位是布林值 { if (para.AsInteger() == 0) { return(new Tuple <string, string, Type>(defName, "False", typeof(bool))); } else //para.AsInteger() == 1 { return(new Tuple <string, string, Type>(defName, "True", typeof(bool))); } } else //如果欄位變數型態真的是整數,而非布林值 { return(new Tuple <string, string, Type>(defName, para.AsInteger().ToString(), typeof(int))); } case StorageType.String: //如果是字串則最好處理 return(new Tuple <string, string, Type>(defName, para.AsString(), typeof(string))); default: return(new Tuple <string, string, Type>("未公開的參數", "無法定義的值", typeof(string))); //return "未公開的參數"; } }//end fun
private static string GetParameterValue(Parameter param) { if (param == null) { return(string.Empty); } string str; switch (param.StorageType) { case StorageType.Integer: str = param.AsInteger().ToString(); break; case StorageType.Double: str = param.AsDouble().ToString(CultureInfo.InvariantCulture); break; case StorageType.String: str = param.AsString(); break; case StorageType.ElementId: str = param.AsElementId().ToString(); break; default: str = param.AsString(); break; } return(str ?? string.Empty); }
/// <summary> /// Get the material type via giving material. /// According to my knowledge, the material type can be retrieved by two ways now: /// 1. If the PropertySetElement exists, retrieve it by PHY_MATERIAL_PARAM_CLASS parameter. (via PropertySetElement class) /// 2. If it's indenpendent, retrieve it by PHY_MATERIAL_PARAM_TYPE parameter(via Material class) /// </summary> /// <param name="material"></param> /// <returns></returns> private StructuralAssetClass GetMaterialType(Material material) { if (material.StructuralAssetId != ElementId.InvalidElementId) { PropertySetElement propElem = m_revit.ActiveUIDocument.Document.GetElement(material.StructuralAssetId) as PropertySetElement; Parameter propElemPara = propElem.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_CLASS); if (propElemPara != null) { return((StructuralAssetClass)propElemPara.AsInteger()); } } return(StructuralAssetClass.Undefined); //ElementId propElemId = material.GetMaterialAspectPropertySet(MaterialAspect.Structural); //if (ElementId.InvalidElementId == propElemId) //{ // Parameter independentPara = material.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_TYPE); // if (null == independentPara) // { // return MaterialType.Generic; // } // return (MaterialType)independentPara.AsInteger(); //} //PropertySetElement propElem = m_revit.ActiveUIDocument.Document.GetElement(propElemId) as PropertySetElement; //Parameter propElemPara = propElem.get_Parameter(BuiltInParameter.PHY_MATERIAL_PARAM_CLASS); //if (null == propElemPara) //{ // return MaterialType.Generic; //} //return (MaterialType)propElemPara.AsInteger(); }
object GetParameterValue(Parameter par) { object parValue = null; if (!par.HasValue) { return(parValue); } switch (par.StorageType) { case StorageType.Double: parValue = par.AsDouble(); break; case StorageType.Integer: parValue = par.AsInteger(); break; case StorageType.String: parValue = par.AsString(); break; case StorageType.ElementId: parValue = par.AsElementId(); break; default: break; } return(parValue); }
/// <summary> /// Gets double value from parameter of an element. /// </summary> /// <param name="element">The element.</param> /// <param name="group">Optional property group to limit search to.</param> /// <param name="propertyName">The property name.</param> /// <param name="propertyValue">The output property value.</param> /// <exception cref="System.ArgumentNullException">Thrown when element is null.</exception> /// <exception cref="System.ArgumentException">Thrown when propertyName is null or empty.</exception> /// <returns>The parameter, or null if not found.</returns> public static Parameter GetDoubleValueFromElement(Element element, BuiltInParameterGroup?group, string propertyName, out double propertyValue) { if (element == null) { throw new ArgumentNullException("element"); } if (String.IsNullOrEmpty(propertyName)) { throw new ArgumentException("It is null or empty.", "propertyName"); } propertyValue = 0.0; Parameter parameter = GetParameterFromName(element.Id, group, propertyName); if (parameter != null && parameter.HasValue) { switch (parameter.StorageType) { case StorageType.Double: propertyValue = parameter.AsDouble(); return(parameter); case StorageType.Integer: propertyValue = parameter.AsInteger(); return(parameter); case StorageType.String: return(Double.TryParse(parameter.AsString(), out propertyValue) ? parameter : null); } } return(null); }
public static string GetParameterValueString(this Parameter param) { string empty = string.Empty; string str; switch ((int)param.StorageType) { case 0: str = param.AsValueString().ToString(); break; case 1: str = param.AsInteger().ToString(); break; case 2: str = param.AsDouble().ToString(CultureInfo.InvariantCulture); break; case 3: str = param.AsString(); break; case 4: str = param.AsElementId().ToString(); break; default: str = param.AsValueString(); break; } return(str ?? string.Empty); }
/// <summary> /// get the room property and Department property according the property name /// </summary> /// <param name="room">a instance of room class</param> /// <param name="propertyName">the property name</param> /// <param name="proValue">the value of property</param> public String GetProperty(Room room, BuiltInParameter paramEnum) { String propertyValue = null; //the value of parameter //get the parameter via the parameterId Parameter param = room.get_Parameter(paramEnum); //get the parameter's storage type StorageType storageType = param.StorageType; switch (storageType) { case StorageType.Integer: int iVal = param.AsInteger(); propertyValue = iVal.ToString(); break; case StorageType.String: String stringVal = param.AsString(); propertyValue = stringVal; break; case StorageType.Double: Double dVal = param.AsDouble(); dVal = Math.Round(dVal, 2); propertyValue = dVal.ToString(); break; default: break; } return(propertyValue); }
public static string GetAsString(Parameter param) { switch (param.StorageType) { case StorageType.None: return(""); case StorageType.Integer: return(param.AsInteger().ToString()); case StorageType.Double: double doubleval = param.AsDouble(); if (param.Definition.UnitType == UnitType.UT_Length) { doubleval *= 304.8; } return(doubleval.ToString("F1")); case StorageType.String: return(param.AsString()); case StorageType.ElementId: int intval = param.AsElementId().IntegerValue; return(intval.ToString()); default: return(""); } }
public ScetchTemplate GetTemlateByFamilyName(string familyName, Element rebar) { Debug.WriteLine("Get template by family name: " + familyName + " for element id " + rebar.Id.IntegerValue.ToString()); foreach (ScetchTemplate st in templates) { foreach (string name in st.familyNames) { if (name == familyName) { if (st.IsSubtype) { Parameter subtypeNumberParam = rebar.LookupParameter("Арм.НомерПодтипаФормы"); if (subtypeNumberParam == null) { return(null); } int subtypeNumber = subtypeNumberParam.AsInteger(); if (st.SubtypeNumber == subtypeNumber) { Debug.WriteLine("Scetch template as Subtype " + subtypeNumber.ToString()); return(st); } } else { Debug.WriteLine("Scetch template found, not subtype"); return(st); } } } } return(null); }
public InstanceData(Element instance) { Instance = instance; ParameterMap m = Instance.ParametersMap; Parameter p = m.get_Item("Param1"); Param1 = (p == null) ? string.Empty : p.AsString(); p = m.get_Item("Param2"); Param2 = (p == null) ? false : (0 != p.AsInteger()); p = m.get_Item("Param3"); Param3 = (p == null) ? 0 : p.AsInteger(); }
private void InitDefaultValues() { List <string> finishingTypeNames = (from type in FinishingTypes select type.Name).ToList(); finishingTypeNames.Insert(0, ""); for (int i = 0; i < Rooms.Count; i++) { this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[i].Cells["RoomNumber"].Value = Rooms[i].LookupParameter("Номер").AsString(); this.dataGridView1.Rows[i].Cells["RoomName"].Value = Rooms[i].LookupParameter("Имя").AsString(); this.dataGridView1.Rows[i].Cells["RoomId"].Value = Rooms[i].Id.IntegerValue; /// Типы отделок WF.DataGridViewComboBoxCell cb = this.dataGridView1.Rows[i].Cells["FinishingType"] as WF.DataGridViewComboBoxCell; cb.DataSource = finishingTypeNames; Parameter p = Rooms[i].get_Parameter(FinishingRoomParameter); if (p != null && p.HasValue && cb.Items.Contains(p.AsString())) { cb.Value = p.AsString(); } /// связанный элемент Parameter pFloorId = Rooms[i].LookupParameter(FinishingIdParameterName); int floorId = (pFloorId != null && pFloorId.HasValue) ? pFloorId.AsInteger() : ElementId.InvalidElementId.IntegerValue; Floor linkedFloor = Rooms[i].Document.GetElement(new ElementId(floorId)) as Floor; if (linkedFloor != null) { this.dataGridView1.Rows[i].Cells["FinishingId"].Value = floorId; this.dataGridView1.Rows[i].Cells["FinishingOffset"].Value = linkedFloor.get_Parameter(FinishingOffsetParameter).AsDouble() * 304.8; } else { this.dataGridView1.Rows[i].Cells["FinishingId"].Value = -1; this.dataGridView1.Rows[i].Cells["FinishingOffset"].Value = 0f; } } }
void UpdateReferencingSheet( ViewSection selectedViewport) { BuiltInParameter bip = BuiltInParameter.VIEW_DISCIPLINE; Parameter discipline = selectedViewport.get_Parameter(bip); int disciplineNo = discipline.AsInteger(); Document doc = selectedViewport.Document; Transaction transaction = new Transaction(doc); if (TransactionStatus.Started == transaction.Start("Updating the model")) { //switch( disciplineNo ) //{ // case 1: // discipline.Set( 2 ); // break; // default: // discipline.Set( 1 ); // break; //} //discipline.Set( disciplineNo ); discipline.Set(1 == disciplineNo ? 2 : 1); transaction.Commit(); } }
/// <summary> /// /// </summary> /// <param name="p"></param> /// <returns></returns> public static object GetParameterValue(Parameter p) { switch (p.StorageType) { case StorageType.None: throw new System.ArgumentOutOfRangeException(); case StorageType.Integer: // (Konrad) It appears that by default yes/no parameters // have a greyed out box checked to 1 even though stored // integer value would return 0 return(p.HasValue ? p.AsInteger() : 1); case StorageType.Double: return(p.AsDouble()); case StorageType.String: return(p.AsString()); case StorageType.ElementId: return(p.AsElementId().IntegerValue); default: throw new System.ArgumentOutOfRangeException(); } }
/// <summary> /// Return parameter value formatted as string /// </summary> static string ParameterToString(Parameter p) { string s = "null"; if (p != null) { switch (p.StorageType) { case StorageType.Double: s = p.AsDouble().ToString("0.##"); break; case StorageType.Integer: s = p.AsInteger().ToString(); break; case StorageType.String: s = p.AsString(); break; case StorageType.ElementId: s = p.AsElementId().IntegerValue.ToString(); break; case StorageType.None: s = "none"; break; } } return(s); }
string GetParamValueAsStr(Parameter parameter) { switch (parameter.StorageType) { case StorageType.String: return(parameter.AsString()); case StorageType.Integer: return(parameter.AsInteger().ToString()); case StorageType.Double: return(parameter.AsValueString()); case StorageType.ElementId: ElementId eid = parameter.AsElementId(); if (eid.IntegerValue < 0) { return("(none)"); } else { return(parameter .Element .Document .GetElement(parameter.AsElementId()).Name); } case StorageType.None: return("N/A"); default: return("N/A"); } }
private Dictionary <int, RoomData> GetRoomData(List <Room> rooms) { Dictionary <int, RoomData> dictionary = new Dictionary <int, RoomData>(); try { foreach (Room room in rooms) { Parameter param = room.LookupParameter(LEEDParameters.LEED_NonRegularyOccupied.ToString()); if (null != param) { int paramValue = param.AsInteger(); if (paramValue == 1) { continue; } //non-regulary occupied } if (room.Area > 0) { RoomData roomData = new RoomData(room, m_doc); roomData.BoundarySegments = roomData.CollectSegmentData(exteriorElementIds); if (!dictionary.ContainsKey(roomData.RoomId)) { dictionary.Add(roomData.RoomId, roomData); } } } } catch (Exception ex) { MessageBox.Show("Failed to collect room data.\n" + ex.Message, "Get Room Data", MessageBoxButton.OK, MessageBoxImage.Warning); } return(dictionary); }
private static FScheme.Value _getParam(FamilySymbol fi, Parameter p) { if (p.StorageType == StorageType.Double) { return FScheme.Value.NewNumber(p.AsDouble()); } else if (p.StorageType == StorageType.Integer) { return FScheme.Value.NewNumber(p.AsInteger()); } else if (p.StorageType == StorageType.String) { return FScheme.Value.NewString(p.AsString()); } else { return FScheme.Value.NewContainer(p.AsElementId()); } }
private static Value _getParam(FamilyInstance fi, Parameter p) { if (p.StorageType == StorageType.Double) { switch (p.Definition.ParameterType) { case ParameterType.Length: return Value.NewContainer(Units.Length.FromFeet(p.AsDouble())); break; case ParameterType.Area: return Value.NewContainer(Units.Area.FromSquareFeet(p.AsDouble())); break; case ParameterType.Volume: return Value.NewContainer(Units.Volume.FromCubicFeet(p.AsDouble())); break; default: return Value.NewNumber(p.AsDouble()); break; } } else if (p.StorageType == StorageType.Integer) { return Value.NewNumber(p.AsInteger()); } else if (p.StorageType == StorageType.String) { return Value.NewString(p.AsString()); } else { return Value.NewContainer(p.AsElementId()); } }
private static Expression _getParam(FamilyInstance fi, Parameter p) { if (p.StorageType == StorageType.Double) { return Expression.NewNumber(p.AsDouble()); } else if (p.StorageType == StorageType.Integer) { return Expression.NewNumber(p.AsInteger()); } else if (p.StorageType == StorageType.String) { return Expression.NewString(p.AsString()); } else { return Expression.NewContainer(p.AsElementId()); } }
/// <summary> /// Extract the parameter information. /// By Dan Tartaglia. /// </summary> public string GetParameterInformation( Parameter para, Document doc) { string defName = ""; // Use different method to get parameter // data according to the storage type switch( para.StorageType ) { // Determine the parameter type case StorageType.Double: // Convert the number into Metric defName = para.AsValueString(); break; case StorageType.ElementId: // Find out the name of the element Autodesk.Revit.DB.ElementId id = para.AsElementId(); defName = ( id.IntegerValue >= 0 ) ? doc.GetElement( id ).Name : id.IntegerValue.ToString(); break; case StorageType.Integer: if( ParameterType.YesNo == para.Definition.ParameterType ) { if( para.AsInteger() == 0 ) { defName = "False"; } else { defName = "True"; } } else { defName = para.AsInteger().ToString(); } break; case StorageType.String: defName = para.AsString(); break; default: defName = "Unexposed parameter"; break; } return defName; }
/// <summary> /// Helper function: return a string form of a given parameter. /// </summary> public static string ParameterToString(Parameter param) { string val = "none"; if (param == null) { return val; } // To get to the parameter value, we need to pause it depending on its storage type switch (param.StorageType) { case StorageType.Double: double dVal = param.AsDouble(); val = dVal.ToString(); break; case StorageType.Integer: int iVal = param.AsInteger(); val = iVal.ToString(); break; case StorageType.String: string sVal = param.AsString(); val = sVal; break; case StorageType.ElementId: ElementId idVal = param.AsElementId(); val = idVal.IntegerValue.ToString(); break; case StorageType.None: break; } return val; }
private void writeValueByStorageType(Parameter p, TextWriter writer, Document doc) { if (null != p) { switch (p.StorageType) { case StorageType.Double: { writer.Write(p.AsDouble()); break; } case StorageType.Integer: { writer.Write(p.AsInteger()); break; } case StorageType.String: { writer.Write(p.AsString()); break; } case StorageType.ElementId: { Element elem = doc.get_Element(p.AsElementId()); if (null == elem) writer.Write("NULL ELEMENT FOUND"); else writer.Write(elem.Name); break; } default: writer.Write("N/A"); break; } } }
private void Stream(ArrayList data, Parameter param) { data.Add(new Snoop.Data.ClassSeparator(typeof(Parameter))); data.Add(new Snoop.Data.Object("Definition", param.Definition)); try { // this only works for certain types of Parameters data.Add(new Snoop.Data.String("Display unit type", param.DisplayUnitType.ToString())); } catch (System.Exception) { data.Add(new Snoop.Data.String("Display unit type", "N/A")); } try { // this only works for certain types of Parameters data.Add(new Snoop.Data.Object("Element", param.Element)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("Element", ex)); } try { // this only works for certain types of Parameters data.Add(new Snoop.Data.String("GUID", param.GUID.ToString())); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("GUID", ex)); } try { // this only works for certain types of Parameters data.Add(new Snoop.Data.Bool("HasValue", param.HasValue)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("HasValue", ex)); } try { // this only works for certain types of Parameters data.Add(new Snoop.Data.ElementId("ID", param.Id,m_activeDoc)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("ID", ex)); } try { // this only works for certain types of Parameters data.Add(new Snoop.Data.Bool("IsShared", param.IsShared)); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("IsShared", ex)); } data.Add(new Snoop.Data.String("Storage type", param.StorageType.ToString())); if (param.StorageType == StorageType.Double) data.Add(new Snoop.Data.Double("Value", param.AsDouble())); else if (param.StorageType == StorageType.ElementId) data.Add(new Snoop.Data.ElementId("Value", param.AsElementId(), m_app.ActiveUIDocument.Document)); else if (param.StorageType == StorageType.Integer) data.Add(new Snoop.Data.Int("Value", param.AsInteger())); else if (param.StorageType == StorageType.String) data.Add(new Snoop.Data.String("Value", param.AsString())); data.Add(new Snoop.Data.String("As value string", param.AsValueString())); }
/// <summary> /// Helper to return parameter value as string. /// One can also use param.AsValueString() to /// get the user interface representation. /// </summary> public static string GetParameterValue( Parameter param ) { string s; switch( param.StorageType ) { case StorageType.Double: // // the internal database unit for all lengths is feet. // for instance, if a given room perimeter is returned as // 102.36 as a double and the display unit is millimeters, // then the length will be displayed as // peri = 102.36220472440 // peri * 12 * 25.4 // 31200 mm // //s = param.AsValueString(); // value seen by user, in display units //s = param.AsDouble().ToString(); // if not using not using LabUtils.RealString() s = RealString( param.AsDouble() ); // raw database value in internal units, e.g. feet break; case StorageType.Integer: s = param.AsInteger().ToString(); break; case StorageType.String: s = param.AsString(); break; case StorageType.ElementId: s = param.AsElementId().IntegerValue.ToString(); break; case StorageType.None: s = "?NONE?"; break; default: s = "?ELSE?"; break; } return s; }