调整代码
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
|
||||
using Autodesk.Revit.Attributes;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
namespace ShrlAlgoToolkit.RevitAddins.Modeling;
|
||||
[Transaction(TransactionMode.Manual)]
|
||||
[Regeneration(RegenerationOption.Manual)]
|
||||
public class CADCurveToModelCurveCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
|
||||
#region SelectExecute
|
||||
|
||||
using (Transaction trans = new Transaction(Document, "default"))
|
||||
{
|
||||
try
|
||||
{
|
||||
Reference refer = UiDocument.Selection.PickObject(ObjectType.Element, "请选择CAD");
|
||||
Element e = UiDocument.Document.GetElement(refer);
|
||||
if (e is ImportInstance ins)
|
||||
{
|
||||
trans.Start();
|
||||
var cadGeo = e.GetGeometryObjects().FirstOrDefault();
|
||||
List<GeometryObject> curves = [];
|
||||
if (cadGeo is GeometryInstance geometryInstance)
|
||||
{
|
||||
curves = [.. geometryInstance.GetInstanceGeometry()];
|
||||
}
|
||||
foreach (var c in curves)
|
||||
{
|
||||
|
||||
if (c is NurbSpline nurb)
|
||||
{
|
||||
if (nurb.Length > 100 / 304.8)
|
||||
{
|
||||
var points = nurb.Tessellate();
|
||||
ReferencePointArray array = new ReferencePointArray();
|
||||
foreach (var p in points)
|
||||
{
|
||||
var rp = Document.FamilyCreate.NewReferencePoint(p);
|
||||
array.Append(rp);
|
||||
}
|
||||
var curveBypoints = Document.FamilyCreate.NewCurveByPoints(array);
|
||||
}
|
||||
}
|
||||
if (c is PolyLine poly)
|
||||
{
|
||||
ReferencePointArray array = new ReferencePointArray();
|
||||
|
||||
for (int i = 0; i < poly.NumberOfCoordinates - 1; i++)
|
||||
{
|
||||
var p = poly.GetCoordinate(i);
|
||||
//Line.CreateBound(p, poly.GetCoordinate(i + 1));
|
||||
}
|
||||
}
|
||||
if (c is Line l)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
trans.Commit();
|
||||
}
|
||||
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException ex)
|
||||
{
|
||||
if (trans.GetStatus() == TransactionStatus.Started)
|
||||
{
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorMessage = ex.Message;
|
||||
if (trans.GetStatus() == TransactionStatus.Started)
|
||||
{
|
||||
trans.RollBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion SelectExecute
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user