public static Reference GetSpecialFamilyReference(
            FamilyInstance inst,
            SpecialReferenceType refType)
        {
            Reference indexRef = null;

            int idx = (int)refType;

            if (inst != null)
            {
                Document dbDoc = inst.Document;

                Options geomOptions = dbDoc.Application.Create
                                      .NewGeometryOptions();

                if (geomOptions != null)
                {
                    geomOptions.ComputeReferences        = true;
                    geomOptions.DetailLevel              = ViewDetailLevel.Undefined;
                    geomOptions.IncludeNonVisibleObjects = true;
                }

                GeometryElement gElement = inst.get_Geometry(
                    geomOptions);

                GeometryInstance gInst = gElement.First()
                                         as GeometryInstance;

                String sampleStableRef = null;

                if (gInst != null)
                {
                    GeometryElement gSymbol = gInst
                                              .GetSymbolGeometry();

                    if (gSymbol != null)
                    {
                        foreach (GeometryObject geomObj in gSymbol)
                        {
                            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(
                                        dbDoc);

                                    break;
                                }
                            }
                            else if (geomObj is Curve)
                            {
                                Curve curve = geomObj as Curve;

                                sampleStableRef = curve.Reference
                                                  .ConvertToStableRepresentation(dbDoc);

                                break;
                            }
                            else if (geomObj is Point)
                            {
                                Point point = geomObj as Point;

                                sampleStableRef = point.Reference
                                                  .ConvertToStableRepresentation(dbDoc);

                                break;
                            }
                        }
                    }

                    if (sampleStableRef != null)
                    {
                        String[] refTokens = sampleStableRef.Split(
                            new char[] { ':' });

                        String customStableRef = refTokens[0] + ":"
                                                 + refTokens[1] + ":" + refTokens[2] + ":"
                                                 + refTokens[3] + ":" + idx.ToString();

                        indexRef = Reference
                                   .ParseFromStableRepresentation(
                            dbDoc, customStableRef);

                        GeometryObject geoObj = inst
                                                .GetGeometryObjectFromReference(
                            indexRef);

                        if (geoObj != null)
                        {
                            String finalToken = "";

                            if (geoObj is Edge)
                            {
                                finalToken = ":LINEAR";
                            }

                            if (geoObj is Face)
                            {
                                finalToken = ":SURFACE";
                            }

                            customStableRef += finalToken;

                            indexRef = Reference
                                       .ParseFromStableRepresentation(
                                dbDoc, customStableRef);
                        }
                        else
                        {
                            indexRef = null;
                        }
                    }
                }
                else
                {
                    throw new Exception("No Symbol Geometry found...");
                }
            }
            return(indexRef);
        }
        public static Reference GetSpecialFamilyReference( 
            FamilyInstance inst,
            SpecialReferenceType refType)
        {
            Reference indexRef = null;

            int idx = (int) refType;

            if( inst != null )
            {
              Document dbDoc = inst.Document;

              Options geomOptions = dbDoc.Application.Create
            .NewGeometryOptions();

              if( geomOptions != null )
              {
            geomOptions.ComputeReferences = true;
            geomOptions.DetailLevel = ViewDetailLevel.Undefined;
            geomOptions.IncludeNonVisibleObjects = true;
              }

              GeometryElement gElement = inst.get_Geometry(
            geomOptions );

              GeometryInstance gInst = gElement.First()
            as GeometryInstance;

              String sampleStableRef = null;

              if( gInst != null )
              {
            GeometryElement gSymbol = gInst
              .GetSymbolGeometry();

            if( gSymbol != null )
            {
              foreach( GeometryObject geomObj in gSymbol )
              {
            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(
                    dbDoc );

                break;
              }
            }
            else if( geomObj is Curve )
            {
              Curve curve = geomObj as Curve;

              sampleStableRef = curve.Reference
                .ConvertToStableRepresentation( dbDoc );

              break;
            }
            else if( geomObj is Point )
            {
              Point point = geomObj as Point;

              sampleStableRef = point.Reference
                .ConvertToStableRepresentation( dbDoc );

              break;
            }
              }
            }

            if( sampleStableRef != null )
            {
              String[] refTokens = sampleStableRef.Split(
            new char[] { ':' } );

              String customStableRef = refTokens[0] + ":"
            + refTokens[1] + ":" + refTokens[2] + ":"
            + refTokens[3] + ":" + idx.ToString();

              indexRef = Reference
            .ParseFromStableRepresentation(
              dbDoc, customStableRef );

              GeometryObject geoObj = inst
            .GetGeometryObjectFromReference(
              indexRef );

              if( geoObj != null )
              {
            String finalToken = "";

            if( geoObj is Edge )
            {
              finalToken = ":LINEAR";
            }

            if( geoObj is Face )
            {
              finalToken = ":SURFACE";
            }

            customStableRef += finalToken;

            indexRef = Reference
              .ParseFromStableRepresentation(
                dbDoc, customStableRef );
              }
              else
              {
            indexRef = null;
              }
            }
              }
              else
              {
            throw new Exception( "No Symbol Geometry found..." );
              }
            }
            return indexRef;
        }