internal RemoteParameter(ElementType type, Parameter parameter, Units units) { Name = parameter.Definition.Name; Type = parameter.Definition.ParameterType.ToString(); Value = string.Empty; if (parameter.StorageType == StorageType.Double) { UnitType utype = parameter.Definition.UnitType; DisplayUnitType dunit = units.GetFormatOptions(utype).DisplayUnits; Value = UnitUtils.ConvertFromInternalUnits(parameter.AsDouble(), dunit).ToString(); } else if (parameter.StorageType == StorageType.Integer) { if (parameter.Definition.ParameterType.ToString() == "YesNo") { int b = parameter.AsInteger(); if (b == 0) { Value = "No"; } else { Value = "Yes"; } } else { Value = parameter.AsInteger().ToString(); } } else if (parameter.StorageType == StorageType.String) { Value = parameter.AsString(); } else if (parameter.StorageType == StorageType.ElementId && parameter.Definition.ParameterType == ParameterType.Material) { ElementId id = parameter.AsElementId(); string elementname = ""; if (id.ToString() != "-1") { elementname = type.Document.GetElement(id).Name; } Value = elementname; } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument UIdoc = commandData.Application.ActiveUIDocument; Document doc = UIdoc.Document; using (Transaction t = new Transaction(doc)) { try { IList <Element> pickedRef = null; List <ElementId> selectedElements = UIdoc.Selection.GetElementIds().ToList(); if (selectedElements.Count == 0) { pickedRef = UIdoc.Selection.PickObjects(ObjectType.Element, new HatchSelectionFilter(), "Выберите штриховки") .Select(q => doc.GetElement(q.ElementId)) .ToList(); } else { pickedRef = selectedElements.Select(q => doc.GetElement(q)).ToList(); } if (pickedRef.Count == 0) { return(Result.Failed); } // Measure their total length List <double> areaList = new List <double>(); foreach (Element element in pickedRef) { Parameter param = element.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED); if (param != null && StorageType.Double == param.StorageType) { areaList.Add(param.AsDouble() * 0.092903); } else { areaList.Add(0.0); } } string areaM2 = Tools.RealString(Math.Round(areaList.Sum(), 2)) + " м2"; StringBuilder sb = new StringBuilder(); sb.AppendLine("Общая площадь:"); sb.AppendLine(areaM2); // Return a message window that displays total length to user TaskDialog.Show("Площадь штриховок", sb.ToString()); return(Result.Succeeded); } catch (OperationCanceledException exceptionCancelled) { message = exceptionCancelled.Message; if (t.HasStarted()) { t.RollBack(); } return(Result.Cancelled); } catch (ErrorMessageException errorException) { message = errorException.Message; if (t.HasStarted()) { t.RollBack(); } return(Result.Failed); } catch (Exception ex) { message = "Неожиданная ошибка: " + ex.Message; if (t.HasStarted()) { t.RollBack(); } return(Result.Failed); } } }