BuildingCoder.CmdRemoveDwfLinks.RemoveDwfLinkUsingExternalFileUtils C# (CSharp) Метод

RemoveDwfLinkUsingExternalFileUtils() приватный Метод

Remove DWF links from model and return the total number of deleted elements.
private RemoveDwfLinkUsingExternalFileUtils ( Document doc ) : int
doc Document
Результат int
        int RemoveDwfLinkUsingExternalFileUtils(
            Document doc)
        {
            List<ElementId> idsToDelete
            = new List<ElementId>();

              ICollection<ElementId> ids = ExternalFileUtils
            .GetAllExternalFileReferences( doc );

              foreach( ElementId id in ids )
              {
            Element e = doc.GetElement( id );

            Debug.Print( Util.ElementDescription( e ) );

            ExternalFileReference xr = ExternalFileUtils
              .GetExternalFileReference( doc, id );

            ExternalFileReferenceType xrType
              = xr.ExternalFileReferenceType;

            if( xrType == ExternalFileReferenceType.DWFMarkup )
            {
              ModelPath xrPath = xr.GetPath();

              string path = ModelPathUtils
            .ConvertModelPathToUserVisiblePath( xrPath );

              if( path.EndsWith( ".dwf" )
            || path.EndsWith( ".dwfx" ) )
              {
            idsToDelete.Add( id );
              }
            }
              }

              int n = idsToDelete.Count;

              ICollection<ElementId> idsDeleted = null;

              if( 0 < n )
              {
            using( Transaction t = new Transaction( doc ) )
            {
              t.Start( "Delete DWFx Links" );

              idsDeleted = doc.Delete( idsToDelete );

              t.Commit();
            }
              }

              int m = ( null == idsDeleted )
            ? 0
            : idsDeleted.Count;

              Debug.Print( string.Format(
            "Selected {0} DWF external file reference{1}, "
            + "{2} element{3} successfully deleted.",
            n, Util.PluralSuffix( n ), m, Util.PluralSuffix( m ) ) );

              return m;
        }