• 【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的层
                    }
                }
  • 相关阅读:
    将 SharePoint 2010 网站集升级到 2013 (含沙盒方案)
    几款网络云存储服务的使用对比
    技术发展飞快,一日十年
    项目背景介绍
    初次接触,简单的了解需求
    用色彩区分 SharePoint 2010 Calendar 的日历项
    嘿,我这里有一个 Survey!
    博客页面在 IE 浏览器中样式混乱了(已经更换了样式)
    关于 Graphviz
    搭建使用 RTX51Tiny 的 C51 Keil 项目环境
  • 原文地址:https://www.cnblogs.com/mqxs/p/12849003.html
Copyright © 2020-2023  润新知