Here is code example you can refine and run, FYI:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Application revitApp = commandData.Application.Application;
string [] files = Directory.GetFiles(@"<your folder contains rvt files>", "*.rvt", SearchOption.TopDirectoryOnly);
foreach (var file in files)
{
// open each rvt
Document rvtDoc = revitApp.OpenDocumentFile(file);
//
// find one 3d view
FilteredElementCollector coll = new FilteredElementCollector(rvtDoc);
View3D v3d = coll.OfClass(typeof(View3D)).ToElements().Cast<View3D>().Where(v => !v.IsTemplate).First();
//
// create export options, you may need to specify more options
NavisworksExportOptions opt = new NavisworksExportOptions();
opt.ExportScope = NavisworksExportScope.View;
opt.ViewId = v3d.Id;
//
// export the 3d view model to nwc
rvtDoc.Export(@"<your export folder>", rvtDoc.Title + ".nwc", opt);
rvtDoc.Close(false);
}
return Result.Succeeded;
}