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


    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的层
                    }
                }
  • 相关阅读:
    Ubuntu之修改用户名和主机名
    HM中CU,TU的划分
    BZOJ 3237([Ahoi2013]连通图-cdq图重构-连通性缩点)
    Introducing Regular Expressions 学习笔记
    kubuntu添加windows字体
    WISE安装程序增加注册控制
    Linux内核中常见内存分配函数(一)
    Linux内核中常见内存分配函数(二)
    Swift现实
    Android 5.0(L) ToolBar(替代ActionBar) 现实(四)
  • 原文地址:https://www.cnblogs.com/mqxs/p/12849003.html
Copyright © 2020-2023  润新知