BuildingCoder.CmdRemoveDwfLinks.RemoveDwfLinkUsingDelete C# (CSharp) 메소드

RemoveDwfLinkUsingDelete() 개인적인 메소드

Useless non-functional attempt to remove all DWF links from the model and return the total number of deleted elements. This does not work! Instead, use RemoveDwfLinkUsingExternalFileUtils.
private RemoveDwfLinkUsingDelete ( Document doc ) : int
doc Document
리턴 int
        int RemoveDwfLinkUsingDelete( Document doc )
        {
            int nDeleted = 0;

              FilteredElementCollector col
            = new FilteredElementCollector( doc )
              .WhereElementIsNotElementType();

              List<ElementId> ids = new List<ElementId>();

              int pinned = 0;

              foreach( Element e in col )
              {
            if( ElementCategoryContainsDwf( e ) )
            {
              Debug.Print( Util.ElementDescription( e ) );
              pinned += ( e.Pinned ? 1 : 0 );
              ids.Add( e.Id );
            }
              }

              ICollection<ElementId> idsDeleted = null;
              Transaction t;

              int n = ids.Count;
              int unpinned = 0;

              if( 0 < n )
              {
            if( 0 < pinned )
            {
              using( t = new Transaction( doc ) )
              {
            t.Start(
              "Unpin non-ElementType '.dwf' elements" );

            unpinned = Unpin( ids, doc );

            t.Commit();
              }
            }

            using( t = new Transaction( doc ) )
            {
              t.Start(
            "Delete non-ElementType '.dwf' elements" );

              idsDeleted = doc.Delete( ids );

              t.Commit();
            }
              }

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

              Debug.Print( string.Format(
            "Selected {0} non-ElementType element{1}, "
            + "{2} pinned, {3} unpinned, "
            + "{4} successfully deleted.",
            n, Util.PluralSuffix( n ), pinned, unpinned, m ) );

              nDeleted += m;

              col = new FilteredElementCollector( doc )
            .WhereElementIsElementType();

              ids.Clear();
              pinned = 0;

              foreach( Element e in col )
              {
            if( ElementCategoryContainsDwf( e ) )
            {
              Debug.Print( Util.ElementDescription( e ) );
              pinned += ( e.Pinned ? 1 : 0 );
              ids.Add( e.Id );
            }
              }

              n = ids.Count;

              if( 0 < n )
              {
            if( 0 < pinned )
            {
              using( t = new Transaction( doc ) )
              {
            t.Start(
              "Unpin element type '.dwf' elements" );

            unpinned = Unpin( ids, doc );

            t.Commit();
              }
            }

            using( t = new Transaction( doc ) )
            {
              t.Start( "Delete element type '.dwf' elements" );

              idsDeleted = doc.Delete( ids );

              t.Commit();
            }
              }

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

              Debug.Print( string.Format(
            "Selected {0} element type{1}, "
            + "{2} pinned, {3} unpinned, "
            + "{4} successfully deleted.",
            n, Util.PluralSuffix( n ), pinned, unpinned, m ) );

              nDeleted += m;

              return nDeleted;
        }