using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
namespace ChangChunTest
{
[TransactionAttribute(TransactionMode.Manual)]
class Ball_cmd : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
double radius = 1200 / 304.8;
Revolution revolution = null;
using (Transaction trans = new Transaction(doc, "Test"))
{
trans.Start();
// 定義旋轉的輪廓
CurveArrArray curveArrArray = new CurveArrArray();
CurveArray curveArray = new CurveArray();
// 定義點
XYZ p0 = new XYZ(0, 0, 0);
XYZ p1 = new XYZ(1, 0, 0);
XYZ p3 = new XYZ(0, 1, 0);
XYZ p5 = new XYZ(radius, 0, 0);
XYZ p6 = new XYZ(-radius, 0, 0);
Line line1 = Line.CreateBound(p5, p6);
double startAngle = 0;
double endAngle = Math.PI;
Arc arc2 = Arc.Create(p0, radius, startAngle, endAngle, p1, p3);
Plane plane1 = Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), XYZ.Zero);
SketchPlane sketchPlane = SketchPlane.Create(doc, plane1);
curveArray.Append(line1);
curveArray.Append(arc2);
curveArrArray.Append(curveArray);
revolution = doc.FamilyCreate.NewRevolution(false, curveArrArray, sketchPlane, line1, -Math.PI, Math.PI);
trans.Commit();
}
using (Transaction trans2 = new Transaction(doc, "test2"))
{
trans2.Start();
Reference refe = null;
FamilyManager m_familyMgr = doc.FamilyManager;
bool isInstance = false;
// FamilyParameter paramTw = m_familyMgr.AddParameter("半徑測試", BuiltInParameterGroup.PG_GEOMETRY, ParameterType.Length, isInstance);
foreach (CurveArray item in revolution.Sketch.Profile)
{
foreach (var curve in item)
{
if (curve is Arc)
{
Arc arc = curve as Arc;
refe = arc.Reference;
break;
}
}
}
Dimension dimensionRadus = doc.FamilyCreate.NewRadialDimension(doc.ActiveView, refe, new XYZ(1, 0, 0));
// dimensionRadus.FamilyLabel = paramTw;
dimensionRadus.FamilyLabel = m_familyMgr.get_Parameter("半徑測試");
trans2.Commit();
}
return Result.Succeeded;
}
}
}
不信?試一試嘛!瓜娃子些🤭🤭🤭🤭🤭~