Autodesk.Revit.DB.GeometryObject

本文探讨了Autodesk Revit DB中GeometryObject类的继承层级,包括Curve、Edge、Face等几何元素,以及如何通过GeometryOptions获取GeometryElement,遍历GeometryInstance的SymbolGeometry,和读取GraphicsStyle属性的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 Autodesk.Revit.DB.GeometryObject

Inheritance Hierarchy

  •       Autodesk.Revit.DB.Curve
  •       Autodesk.Revit.DB.Edge
  •       Autodesk.Revit.DB.Face
  •       Autodesk.Revit.DB.GeometryElement
  •       Autodesk.Revit.DB.GeometryInstance
  •       Autodesk.Revit.DB.Mesh
  •       Autodesk.Revit.DB.Point
  •       Autodesk.Revit.DB.PolyLine
  •       Autodesk.Revit.DB.Profile
  •       Autodesk.Revit.DB.Solid
 GraphicsStyleId

The ElementId of the GeometryObject's GraphicsStyle

 IsElementGeometry

Indicates whether this geometry is obtained directly from an Element.

 IsReadOnly

Identifies if the object is read-only or modifiable.

(Inherited from APIObject.)
 Visibility

The visibility.

// find the name of the GraphicsSytleCategory for every geometric primitive in a family instance
        Options options = app.Create.NewGeometryOptions();
        GeometryElement geomElem = element.get_Geometry(options);
        foreach (GeometryObject geomObj in geomElem)
        {
            GeometryInstance geomInst = geomObj as GeometryInstance;
            if (geomInst != null)
            {
                foreach (Object obj in geomInst.SymbolGeometry)
                {
                    GeometryObject geomObject = obj as GeometryObject;
//The ElementId of the GeometryObject's GraphicsStyle
                    GraphicsStyle gStyle = doc.GetElement(geomObject.GraphicsStyleId) as GraphicsStyle;
                    if (gStyle != null)
                    {
                        string gstyleName = gStyle.GraphicsStyleCategory.Name;
                    }
                }
            }
        }

 

using Autodesk.Revit.Attributes; using Autodesk.Revit.UI; using Autodesk.Revit.DB; using System.Collections; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.DB.Structure; using Autodesk.Revit.DB.Plumbing; using Autodesk.Revit.DB.Architecture; using Autodesk.Revit.ApplicationServices; using System; using System.Runtime.Remoting.Contexts; namespace Shiquwenzi { [Transaction(TransactionMode.Manual)] public class Class1 : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; View activeView = doc.ActiveView; // 关键:获取当前视图 try { // 修改1:使用带图层的筛选器 var filter = new CADLayerFilter("TEXT"); Reference reference = uiDoc.Selection.PickObject(ObjectType.Element, filter, "选择CAD文字"); ImportInstance importInstance = doc.GetElement(reference) as ImportInstance; if (importInstance == null) return Result.Failed; // 修改2:使用GetGraphics替代GetGeometry GeometryElement geomElem = importInstance.GetGraphics(activeView); // 修改3:遍历所有几何实例 foreach (GeometryObject geoObj in geomElem) { if (geoObj is GeometryInstance geometryInstance) { foreach (GeometryObject cadObj in geometryInstance.GetSymbolGeometry()) { // 修改4:识别CAD文字类型 if (cadObj is DBText dbText) TaskDialog.Show("文字内容", dbText.Text); if (cadObj is CADText cadText) TaskDialog.Show("文字内容", cadText.Text); } } } return Result.Succeeded; } catch { return Result.Failed; } } // 增强版筛选器(支持图层过滤) public class CADLayerFilter : ISelectionFilter { private readonly string _targetLayer; public CADLayerFilter(string layerName) => _targetLayer = layerName; public bool AllowElement(Element elem) { // 允许所有ImportInstance return elem is ImportInstance; } public bool AllowReference(Reference reference, XYZ position) { // 关键:检查CAD图层名称 var layer = reference.GlobalObject .GetType() .GetProperty("Layer")? .GetValue(reference.GlobalObject) as string; return layer == _targetLayer; } } 请根据revit API对上述代码进行改正
最新发布
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值