C#Revit API使用钢筋每个段的长度创建TextNote

问题描述

我正在尝试在钢筋的每个曲线上放置一个TextNote,即通过GetCenterlineCurves方法获得的中心曲线。

我的代码如下:

// Recorre todas las curvas
foreach (Curve curva in listaCurvas)
{
    try
    {
        // Obtiene la longitud de la curva
        nombre = curva.ApproximateLength.ToString();

        // Obtiene la ubicación del principio de la curva
        curvaInicio = curva.GetEndPoint(0);

        // Obtiene la ubicación del final de la curva
        curvaFin = curva.GetEndPoint(1);

        // Obtiene la ubicación media de la curva
        ubicacion = (curvaInicio + curvaFin) / 2;

        // Crea el texto
        TextNote texto = TextNote.Create(doc,vista.Id,ubicacion,nombre,tipoTexto.Id);

        // Agrega el texto a la lista
        listaTexto.Add(texto);
    }

    catch (Exception) { }
}

但是该曲线以英尺为单位,我需要按图中所示以项目单位返回它。

enter image description here

如果可能的话,还可以弯曲钢筋的弯曲直径。

解决方法

首先,我们必须使用以下方法从参数A,B,C,D ...中获取UnitType

///<summary> Obtiene el UnitType de un parámetro </summary>
public static UnitType UnidadesObtenerUnitTypeParametro(Parameter param)
{
     // Obtiene el UnitType
     return param.Definition.UnitType;
}

然后,我们使用“ UnitFormatUtils”类的“ Format”方法获取具有用户为这些参数配置的单位的值。

// Recorre todas las curvas
foreach (Curve curva in listaCurvas)
{
    // Obtiene el UnitType del parámetro A...
    UnitType UT = UnidadesObtenerUnitTypeParametro(listaParametros[0]);

    // Obtiene las unidades
    Units unidades = doc.GetUnits();
    
    // Obtiene la longitud de la curva redondeando el número según la precisión elegida
    nombre = UnitFormatUtils.Format(unidades,UT,curva.ApproximateLength,false,false);
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...