예제 #1
0
        public Reference GetReferenceOfFamilyInstance(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;
                    if (geoInstance != null)
                    {
                        GeometryElement geoSymbol       = geoInstance.GetSymbolGeometry();
                        string          sampleStableRef = null;
                        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;
                    }
                }
            }
            return(indexReference);
        }
        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;
        }