revit 二次开发 获取实例参照

1、定义枚举类型

  public enum SpecialReferenceType
    {
        Left = 0,
        CenterLR = 1,
        Right = 2,
        Front = 3,
        CenterFB = 4,
        Back = 5,
        Bottom = 6,
        CenterElevation = 7,
        Top = 8
    }

2、写获取参照的公用方法

    public static Reference GetSpecialFamilyReference(Document doc, FamilyInstance instance, SpecialReferenceType ReferenceType)
        {
            Reference indexReference = null;

            int index = (int)ReferenceType;
            Options geomOptions = new Options();
            geomOptions.ComputeReferences = true;
            geomOptions.DetailLevel = ViewDetailLevel.Medium;
            geomOptions.IncludeNonVisibleObjects = true;

            GeometryElement geoElement = instance.get_Geometry(geomOptions);
            foreach (GeometryObject obj in geoElement)
            {
                if (obj is GeometryInstance)
                {
                    GeometryInstance geoInstance = obj as GeometryInstance;
                    String sampleStableRef = null;
                    if (geoInstance != null)
                    {
                        GeometryElement geoSymbol = geoInstance.GetSymbolGeometry();
                        if (geoSymbol != null)
                        {
                            foreach (GeometryObject geomObj in geoSymbol)
                            {
                                if (geomObj is Solid)
                                {
                                    Solid solid = geomObj as Solid;
                                    if (solid.Faces.Size > 0)
                                    {
                                        Face face = solid.Faces.get_Item(0);
                                        sampleStableRef = face.Reference.ConvertToStableRepresentation(doc);
                                        break;
                                    }
                                }
                            }
                        }
                        if (sampleStableRef != null)
                        {
                            String[] refTokens = sampleStableRef.Split(new char[] { ':' });
                            String customStableRef = refTokens[0] + ":" + refTokens[1] + ":" + refTokens[2] + ":" + refTokens[3] + ":" + index.ToString();
                            indexReference = Reference.ParseFromStableRepresentation(doc, customStableRef);
                        }
                        break;
                    }
                    else
                    {

                    }

                }
            }
            return indexReference;

        }

 

参考网址:https://blog.csdn.net/u010585773/article/details/83179607?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160101233719724839227869%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=160101233719724839227869&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_v2~rank_v25-12-83179607.pc_search_result_cache&utm_term=revit%E8%8E%B7%E5%8F%96%E9%9D%A2%E5%8F%82%E7%85%A7&spm=1018.2118.3001.4187

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值