提取模型线边缘并将之变成模型线主要是为了方便建桥梁的护栏,因为选择护栏的路线必须是在平面上,这点暂时不好解决。
但是前一个问题还是可以解决的。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
namespace 取得边缘线
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档
Application revitApp = commandData.Application.Application; //取得应用程序
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Selection sel = uiDoc.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element, “选择一个族实例”);
Element elem = revitDoc.GetElement(ref1);
FamilyInstance familyInstance = elem as FamilyInstance;
Options opt = new Options();
opt.ComputeReferences = true;
opt.DetailLevel = ViewDetailLevel.Fine;
GeometryElement e = familyInstance.get_Geometry(opt);
Transaction tra = new Transaction(revitDoc);
tra.Start(“revit”);
foreach (GeometryObject obj in e)
{
GeometryInstance geoInstance = obj as GeometryInstance;
GeometryElement geoElement = geoInstance.GetInstanceGeometry();
Transform insTransform = geoInstance.Transform;
foreach (GeometryObject obj2 in geoElement)
{
Solid solid2 = obj2 as Solid;
if (solid2.Faces.Size > 0)
{
foreach (Edge edge in solid2.Edges)
{
Curve curve = edge.AsCurve();
//TaskDialog.Show(“revit”,edge.AsCurve().GetType().ToString());
CreatModelLine2(revitDoc, curve, revitApp);
//SketchPlane plane =SketchPlane.Create(revitDoc,new Plane(normal,curve.GetEndPoint(0)));
//ModelCurve modelCurve = revitDoc.Create.NewModelCurve(curve,);
}
//FindBottomFace(solid2);
//FindEdge(solid2);
//FindLine(solid2);
//FindPoint(solid2);
//transformPointAndUaPoint(solid2, insTransform);
//TaskDialog.Show(“呵呵”, “在这里”);
}
}
}
tra.Commit();
return Result.Succeeded;
}
public void CreatModelLine(Document revitDoc, Curve curve, Application revitApp)
{
XYZ p1 = GeomUtil.SubXYZ(curve.GetEndPoint(0), curve.GetEndPoint(1));
XYZ p2 = GeomUtil.SubXYZ(curve.GetEndPoint(0), new XYZ(3, 29, 37));
XYZ normal = GeomUtil.CrossMatrix(p1, p2);
SketchPlane modelSketch = SketchPlane.Create(revitDoc, revitApp.Create.NewPlane(normal, curve.GetEndPoint(0)));
ModelCurve modelcurve = revitDoc.FamilyCreate.NewModelCurve(curve, modelSketch);
}
/// <summary>
/// 在项目中建模型线
/// </summary>
/// <param name=”revitDoc”></param>
/// <param name=”curve”></param>
/// <param name=”revitApp”></param>
public void CreatModelLine2(Document revitDoc, Curve curve, Application revitApp)
{
try
{
XYZ p1 = GeomUtil.SubXYZ(curve.GetEndPoint(0), curve.GetEndPoint(1));
XYZ p2 = GeomUtil.SubXYZ(curve.GetEndPoint(0), new XYZ(3, 29, 37));
XYZ normal = GeomUtil.CrossMatrix(p1, p2);
SketchPlane modelSketch = SketchPlane.Create(revitDoc, revitApp.Create.NewPlane(normal, curve.GetEndPoint(0)));
ModelCurve modelcurve = revitDoc.Create.NewModelCurve(curve, modelSketch);
}
catch
{
XYZ p1 = GeomUtil.SubXYZ(curve.Tessellate()[0], curve.Tessellate()[1]);
XYZ p2 = GeomUtil.SubXYZ(curve.GetEndPoint(0), curve.Tessellate()[2]);
XYZ normal = GeomUtil.CrossMatrix(p1, p2);
SketchPlane modelSketch = SketchPlane.Create(revitDoc, revitApp.Create.NewPlane(normal, curve.GetEndPoint(0)));
ModelCurve modelcurve = revitDoc.Create.NewModelCurve(curve, modelSketch);
}
}
}
评论前必须登录!
注册