Revit二次开发——怎么读取cad里的单独的一条线


今天有朋友问我怎么通过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;
 }
 }
}
0

评论0

请先

没有账号? 注册  忘记密码?

社交账号快速登录

微信扫一扫关注
扫码关注后会自动登录网站
普人特福的博客cnzz&51la for wordpress,cnzz for wordpress,51la for wordpress