C# Revit API中的偏移命令
如何在我的C#插件中使用offset命令?我有要包含在偏移和偏移值中的直线/圆弧列表。我找不到要使用的命令 我原以为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
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;
}
如果你做一个方向枚举或类似的东西可能会更好,但我认为这应该适合你的目的