Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Revit API中的偏移命令_C#_.net_Revit Api - Fatal编程技术网

C# Revit API中的偏移命令

C# Revit API中的偏移命令,c#,.net,revit-api,C#,.net,Revit Api,如何在我的C#插件中使用offset命令?我有要包含在偏移和偏移值中的直线/圆弧列表。我找不到要使用的命令 我原以为ElementTransformUnit类包含了一些功能,但它似乎没有 谢谢我知道没有Offset命令,但是我认为您可以使用ElementTransformUtils.CopyElement方法轻松地创建一个。试着这样做: static ElementId Offset(this Element originalelement, double offsetamount, s

如何在我的C#插件中使用offset命令?我有要包含在偏移和偏移值中的直线/圆弧列表。我找不到要使用的命令

我原以为
ElementTransformUnit
类包含了一些功能,但它似乎没有


谢谢

我知道没有Offset命令,但是我认为您可以使用
ElementTransformUtils.CopyElement
方法轻松地创建一个。试着这样做:

    static ElementId Offset(this Element originalelement, double offsetamount, string offsetdirection)
    {
        ElementId newelement = null;
        Document curdoc = originalelement.Document;
        LocationPoint elp = originalelement.Location as LocationPoint;
        XYZ elem_location = null;

        switch(offsetdirection.ToUpper())
        {
            default:
                break;

            case "X":
                elem_location = new XYZ(offsetamount, 0.0, 0.0) + elp.Point;
                break;

            case "Y":
                // code for Y
                break;

            case "Z":
                // code for Z
                break;
        }

        try
        {
            using (Transaction tr_offset = new Transaction(curdoc, "Offsetting element"))
            {
                tr_offset.Start();
                newelement = ElementTransformUtils.CopyElement(curdoc, originalelement.Id, elem_location).FirstOrDefault();
                tr_offset.Commit();
            }
        }

        catch (Exception e)
        {
            Console.WriteLine("Command Failed. See below: \n" + e.StackTrace.ToString());
        }

        return newelement;
    }
如果你做一个方向枚举或类似的东西可能会更好,但我认为这应该适合你的目的