今天有朋友问我怎么通过Revit读取cad里的单独的一条线,我刚开始在网上找了一下,发现并没有相关介绍,网上都是读取cad里所有的线的信息或者图层相关。于是我自己尝试了一下,只要通过这个关键的PickObject(ObjectType.PointOnElement)方法,就可以获取到点选的单独的一条线,然后通过GetGeometryObjectFromReference转化成geometryObject即可。然后想怎么利用就怎么利用你选的信息(我这里是读取出线的第二个点的坐标)。
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 re = sel.PickObject(ObjectType.Element);
Reference re = sel.PickObject(ObjectType.PointOnElement);
ImportInstance dwg = revitDoc.GetElement(re) as ImportInstance;
var geoObj = (dwg as Element).GetGeometryObjectFromReference(re);
TaskDialog.Show("revit", geoObj.GetType().ToString());
//Transform transf = null;
XYZ p1 = null;
XYZ p2 = null;
if (geoObj is Line)
{
Line l = geoObj as Line;
p1 = l.GetEndPoint(0);
p2 = l.GetEndPoint(1);
TaskDialog.Show("revit", p2.X.ToString());
}
return Result.Succeeded;
}
}
}
微信公众号:xuebim
关注建筑行业BIM发展、研究建筑新技术,汇集建筑前沿信息!
← 微信扫一扫,关注我们+
评论前必须登录!
注册