Revit API 开发周边:对 Element 进行 Reflection

前言

RevitLookup 可以找到任意一个构建的 BoundingBox,但是我用 API 直接调用却不能,这是什么原因的?到底有没有这个属性 BoundingBox。

内容

在这里插入图片描述
Element 进行反射,读取它的所有的属性和方法,并且打印出来。这里顺便把字符串 Autodesk.Revit.DB. 去掉,免得内容太繁杂。另外,如果真的有 BoundingBox,就把它读出来:

Type type = typeof(Element);
FileStream fs = File.Create(@"D:\result\elementReflection.txt");
StreamWriter sw = new StreamWriter(fs);
PropertyInfo[] propertyInfos = type.GetProperties();
foreach(PropertyInfo propertyInfo in propertyInfos)
{
    sw.WriteLine("Property: " + propertyInfo.ToString().Replace("Autodesk.Revit.DB.",""));
    if (propertyInfo.Name == "BoundingBox")
    {
        BoundingBoxXYZ bbxyz = propertyInfo.GetValue(element, new object[1] { commandData.Application.ActiveUIDocument.ActiveView }) as BoundingBoxXYZ;
        if(null != bbxyz)
        {
            sw.WriteLine("    Min:" + bbxyz.Min.ToString() + ", Max:" + bbxyz.Max.ToString());
        }
    }
}

MethodInfo[] methodInfos = type.GetMethods();
foreach (MethodInfo methodInfo in methodInfos)
{
    sw.WriteLine("Method: " + methodInfo.ToString().Replace("Autodesk.Revit.DB.", ""));
}

结果列在作后面,这个是 BoundingBox,虽然是一个属性,但是有一个参数 View,实际上和 BoundingBoxXYZ get_BoundingBox(View) 一样:

Property: BoundingBoxXYZ BoundingBox [View]
    Min:(0.008202100, -0.003280840, 0.000000000), Max:(2.764107612, 1.945538058, 0.000000000)

所有的属性和方法:

Property: Boolean IsValidObject
Property: ElementId DemolishedPhaseId
Property: ElementId CreatedPhaseId
Property: ElementId OwnerViewId
Property: Boolean ViewSpecific
Property: ElementId AssemblyInstanceId
Property: ElementId LevelId
Property: System.String UniqueId
Property: Boolean IsTransient
Property: ElementId Id
Property: ElementId GroupId
Property: WorksetId WorksetId
Property: Boolean Pinned
Property: BoundingBoxXYZ BoundingBox [View]
    Min:(0.008202100, -0.003280840, 0.000000000), Max:(2.764107612, 1.945538058, 0.000000000)
Property: GeometryElement Geometry [Options]
Property: DesignOption DesignOption
Property: Document Document
Property: Location Location
Property: ParameterMap ParametersMap
Property: ParameterSet Parameters
Property: Parameter Parameter [BuiltInParameter]
Property: Parameter Parameter [Definition]
Property: Parameter Parameter [System.Guid]
Property: Category Category
Property: System.String Name
Method: System.String get_Name()
Method: Void set_Name(System.String)
Method: Category get_Category()
Method: Parameter get_Parameter(BuiltInParameter)
Method: Parameter get_Parameter(Definition)
Method: Parameter get_Parameter(System.Guid)
Method: ParameterSet get_Parameters()
Method: ParameterMap get_ParametersMap()
Method: Location get_Location()
Method: Document get_Document()
Method: DesignOption get_DesignOption()
Method: GeometryElement get_Geometry(Options)
Method: BoundingBoxXYZ get_BoundingBox(View)
Method: Boolean IsHidden(View)
Method: Boolean CanBeHidden(View)
Method: ChangeType GetChangeTypeParameter(ElementId)
Method: ChangeType GetChangeTypeParameter(Parameter)
Method: System.Collections.Generic.IList`1[Parameter] GetOrderedParameters()
Method: System.Collections.Generic.IList`1[Parameter] GetParameters(System.String)
Method: Parameter LookupParameter(System.String)
Method: Boolean get_Pinned()
Method: Void set_Pinned(Boolean)
Method: WorksetId get_WorksetId()
Method: ElementId get_GroupId()
Method: ElementId get_Id()
Method: Boolean get_IsTransient()
Method: System.String get_UniqueId()
Method: ElementId get_LevelId()
Method: ElementId get_AssemblyInstanceId()
Method: Boolean get_ViewSpecific()
Method: ElementId get_OwnerViewId()
Method: ElementId get_CreatedPhaseId()
Method: Void set_CreatedPhaseId(ElementId)
Method: ElementId get_DemolishedPhaseId()
Method: Void set_DemolishedPhaseId(ElementId)
Method: Boolean get_IsValidObject()
Method: Boolean CanBeLocked()
Method: ElementOnPhaseStatus GetPhaseStatus(ElementId)
Method: ElementId GetTypeId()
Method: System.Collections.Generic.ICollection`1[ElementId] GetGeneratingElementIds(GeometryObject)
Method: Boolean CanHaveTypeAssigned(Document, System.Collections.Generic.ICollection`1[ElementId])
Method: Boolean CanHaveTypeAssigned()
Method: Boolean IsValidType(Document, System.Collections.Generic.ICollection`1[ElementId], ElementId)
Method: Boolean IsValidType(ElementId)
Method: System.Collections.Generic.ICollection`1[ElementId] GetValidTypes(Document, System.Collections.Generic.ICollection`1[ElementId])
Method: System.Collections.Generic.ICollection`1[ElementId] GetValidTypes()
Method: System.Collections.Generic.IDictionary`2[ElementId,ElementId] ChangeTypeId(Document, System.Collections.Generic.ICollection`1[ElementId], ElementId)
Method: ElementId ChangeTypeId(ElementId)
Method: System.Collections.Generic.IList`1[Subelement] GetSubelements()
Method: Boolean DeleteSubelement(Subelement)
Method: Boolean DeleteSubelements(System.Collections.Generic.IList`1[Subelement])
Method: Boolean CanDeleteSubelement(Subelement)
Method: System.Collections.Generic.IList`1[ElementId] GetDependentElements(ElementFilter)
Method: GeometryObject GetGeometryObjectFromReference(Reference)
Method: Boolean IsExternalFileReference()
Method: ExternalFileReference GetExternalFileReference()
Method: Boolean RefersToExternalResourceReferences()
Method: System.Collections.Generic.IDictionary`2[ExternalResourceType,ExternalResourceReference] GetExternalResourceReferences()
Method: Boolean RefersToExternalResourceReference(ExternalResourceType)
Method: ExternalResourceReference GetExternalResourceReference(ExternalResourceType)
Method: System.Collections.Generic.ICollection`1[ElementId] GetMaterialIds(Boolean)
Method: Double GetMaterialArea(ElementId, Boolean)
Method: Double GetMaterialVolume(ElementId)
Method: FormatOptions GetParameterFormatOptions(ElementId)
Method: ChangeType GetChangeTypeElementDeletion()
Method: ChangeType GetChangeTypeElementAddition()
Method: ChangeType GetChangeTypeGeometry()
Method: ChangeType GetChangeTypeAny()
Method: Boolean CanHaveAnalyticalModel()
Method: Structure.AnalyticalModel GetAnalyticalModel()
Method: ElementId GetAnalyticalModelId()
Method: Boolean IsMonitoringLinkElement()
Method: Boolean IsMonitoringLocalElement()
Method: System.Collections.Generic.IList`1[ElementId] GetMonitoredLinkElementIds()
Method: System.Collections.Generic.IList`1[ElementId] GetMonitoredLocalElementIds()
Method: Boolean HasPhases()
Method: Boolean ArePhasesModifiable()
Method: Boolean IsPhaseCreatedValid(ElementId)
Method: Boolean IsPhaseDemolishedValid(ElementId)
Method: System.Collections.Generic.IList`1[System.Guid] GetEntitySchemaGuids()
Method: ExtensibleStorage.Entity GetEntity(ExtensibleStorage.Schema)
Method: Void SetEntity(ExtensibleStorage.Entity)
Method: Boolean DeleteEntity(ExtensibleStorage.Schema)
Method: Void Dispose()
Method: Boolean Equals(System.Object)
Method: Int32 GetHashCode()
Method: System.Type GetType()
Method: System.String ToString()
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

极客BIM工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值