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;
}