Advertisement

Saturday, May 6, 2017

Forgify – Reduce Project Size Dramatically by Deleting all but the Default "{3D}" View

From the The Building Coder blog:

I am jumping in an urgent case to reduce the RVT model file size before passing it into the Forge translator:

RvtForgify

I implemented a pretty radical and simple approach to prepare a complex RVT model for Forge translation: delete absolutely all views except the default "{3D}" one.

File size went down significantly, from 155 MB to 88 MB, i.e., 57 percent.

I am still waiting for customer feedback on the final results.

Also, more analysis is required on what elements this operation actually removes, and whether there is possibly much more stuff that could also be eliminated.

The code is super simple:

[Transaction( TransactionMode.Manual )]
public class CmdDeleteViews : IExternalCommand
{
  /// <summary>
  /// Delete all views except "{3D}".
  /// </summary>
  void DeleteViews( Document doc )
  {
    IEnumerable<View> views
      = new FilteredElementCollector( doc )
        .OfClass( typeof( View ) )
        .Cast<View>()
        .Where<View>( v => v.CanBePrinted
          && !v.IsTemplate
          && !"{3D}".Equals( v.ViewName ) );

    ICollection<ElementId> ids = views
      .Select<View, ElementId>( v => v.Id )
      .ToList<ElementId>();

    doc.Delete( ids );
  }

  public Result Execute(
    ExternalCommandData commandData,
    ref string message,
    ElementSet elements )
  {
    UIApplication uiapp = commandData.Application;
    UIDocument uidoc = uiapp.ActiveUIDocument;
    Document doc = uidoc.Document;

    using( Transaction tx = new Transaction( doc ) )
    {
      tx.Start( "Delete Views" );
      DeleteViews( doc );
      tx.Commit();
    }
    return Result.Succeeded;
  }
}

The entire Visual Studio solution is provided in the RvtForgify GitHub repository.



There's more information available on the The Building Coder blog.

No comments: