首页 > 其他 > 详细

【Revit】使用PickObect拾取CAD的线的层信息

时间:2020-05-08 11:07:31      阅读:77      评论:0      收藏:0      [点我收藏+]

1、第一步使用PickObject以及筛选器CADPickObjectFilter 获取拾取的线的Reference

 Reference r = selection.PickObject(ObjectType.PointOnElement, new CADPickObjectFilter(_doc));

筛选器代码:

class CADPickObjectFilter : ISelectionFilter
    {
        private Document _doc;
        public CADPickObjectFilter(Document doc)
        {
            _doc = doc;
        }
        public bool AllowElement(Element elem)
        {
            if (elem is ImportInstance)
                return true;
            else
                return false;
        }

        public bool AllowReference(Reference reference, XYZ position)
        {
            var elem = _doc.GetElement(reference);
            if (elem is ImportInstance)
            {
                var geo = elem.GetGeometryObjectFromReference(reference);
                if (geo != null && geo is GeometryObject && geo.GraphicsStyleId.IntegerValue != -1)
                {
                    return true;
                }
                else
                { return false; }
            }
            else
                return false;
        }
    }

第二步,通过Reference获取信息

            protected GeometryElement _geoelem = null;
            protected GeometryObject _geoobj = null;
            protected Transform _transform;
            protected ImportInstance _import;
            protected string _filename;

            var elem = _doc.GetElement(r);
            var import = elem as ImportInstance;
            if (import != null)
            {
                var cadlinkType = _doc.GetElement(elem.GetTypeId());
                if (!cadlinkType.IsExternalFileReference())
                {
                    MessageBox.Show("请将导入CAD改为链接CAD方式。");
                    return;
                }
                _filename = ModelPathUtils.ConvertModelPathToUserVisiblePath(cadlinkType.GetExternalFileReference().GetAbsolutePath());
                _import = import;
                _transform = _import.GetTransform();
            }
            _geoelem = elem.get_Geometry(new Options());
            _geoobj = elem.GetGeometryObjectFromReference(r);
             if (_geoobj.GraphicsStyleId != ElementId.InvalidElementId)
            {
                var graphicsStyleId = _geoobj.GraphicsStyleId;
                GraphicsStyle gs = _doc.GetElement(graphicsStyleId) as GraphicsStyle;
                if (gs != null)
                {
                    var category = gs.GraphicsStyleCategory;//CAD的层
                }
            }

 

【Revit】使用PickObect拾取CAD的线的层信息

原文:https://www.cnblogs.com/mqxs/p/12849003.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!