更新
This commit is contained in:
@@ -11,19 +11,17 @@ public class InstancesCreator : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
var doc = Document;
|
||||
var uidoc = UiDocument;
|
||||
//var uidoc = uiApplication.ActiveUIDocument;
|
||||
//var doc = uidoc.Document;
|
||||
var ids = uidoc.Selection.GetElementIds();
|
||||
//var Document = uidoc.Document;
|
||||
var ids = UiDocument.Selection.GetElementIds();
|
||||
|
||||
using (Transaction ts = new(doc, "旋转"))
|
||||
using (Transaction ts = new(Document, "旋转"))
|
||||
{
|
||||
ts.Start();
|
||||
var collector = new FilteredElementCollector(doc, doc.ActiveView.Id).OfClass(typeof(TextNote));
|
||||
var collector = new FilteredElementCollector(Document, Document.ActiveView.Id).OfClass(typeof(TextNote));
|
||||
foreach (var id in ids)
|
||||
{
|
||||
var elem = doc.GetElement(id);
|
||||
var elem = Document.GetElement(id);
|
||||
var loc = elem.Location as LocationPoint;
|
||||
var point = loc.Point;
|
||||
XYZ flattenXY = new(loc.Point.X, loc.Point.Y, 0);
|
||||
@@ -51,15 +49,15 @@ public class InstancesCreator : ExternalCommand
|
||||
var crossProduct = XYZ.BasisX.CrossProduct(textNoteNearest.BaseDirection).Normalize();
|
||||
if (Math.Abs(radian - Math.PI) < 10E-6)
|
||||
{
|
||||
ElementTransformUtils.RotateElement(doc, id, Line.CreateUnbound(point, XYZ.BasisZ), Math.PI);
|
||||
ElementTransformUtils.RotateElement(Document, id, Line.CreateUnbound(point, XYZ.BasisZ), Math.PI);
|
||||
}
|
||||
if (crossProduct.IsAlmostEqualTo(XYZ.BasisZ))
|
||||
{
|
||||
ElementTransformUtils.RotateElement(doc, id, Line.CreateUnbound(point, XYZ.BasisZ), radian);
|
||||
ElementTransformUtils.RotateElement(Document, id, Line.CreateUnbound(point, XYZ.BasisZ), radian);
|
||||
}
|
||||
if (crossProduct.IsAlmostEqualTo(-XYZ.BasisZ))
|
||||
{
|
||||
ElementTransformUtils.RotateElement(doc, id, Line.CreateUnbound(point, XYZ.BasisZ), 2 * Math.PI - radian);
|
||||
ElementTransformUtils.RotateElement(Document, id, Line.CreateUnbound(point, XYZ.BasisZ), 2 * Math.PI - radian);
|
||||
}
|
||||
}
|
||||
ts.Commit();
|
||||
|
||||
Reference in New Issue
Block a user