如何在我的 C# 插件中使用 offset 命令?我有要包含在偏移和偏移值中的线/弧的列表。我找不到要使用的命令。
我认为该ElementTransformUnit
课程包含可以做的事情,但似乎没有...
谢谢
There's no Offset command that I'm aware of, but you could make one pretty easily I think using the ElementTransformUtils.CopyElement
method instead. Try something like this:
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;
}
might be better if you made a Direction enum or something like that but that should work for your purposes, I think.