public void ExportFile(Document docWrapper, View3D view3d, string rfaFilePath)
        {
            if (docWrapper is null)
            {
                throw new ArgumentNullException(nameof(docWrapper));
            }

            if (docWrapper.IsFamilyDocument)
            {
                throw new InvalidOperationException("Only project-type documents could be exported.");
            }

            var familyName       = Path.GetFileNameWithoutExtension(rfaFilePath);
            var familyExportArgs = new FamilyExportEventArgs {
                FamilyFilePath = rfaFilePath
            };

            this?.OnExportStarted(familyExportArgs);

            Family family;

            using (var collector = new FilteredElementCollector(docWrapper))
                using (var filter = new ElementClassFilter(typeof(Family), false))
                {
                    family = collector
                             .WherePasses(filter)
                             .Cast <Family>()
                             .FirstOrDefault(f => f.Name.Equals(familyName, StringComparison.OrdinalIgnoreCase));
                }

            if (family is null)
            {
                using var t = new Transaction(docWrapper, $"Load the family '{familyName}'");
                t.Start();
                if (!docWrapper.LoadFamily(rfaFilePath, out family))
                {
                    throw new InvalidOperationException();
                }
                t.Commit();
            }

            foreach (var typElementId in family.GetFamilySymbolIds())
            {
                FamilyInstance familyInstance;
                if (!(docWrapper.GetElement(typElementId) is FamilySymbol familySymbol))
                {
                    throw new InvalidOperationException();
                }

                var outputFilePath = familySymbol.Name.Equals(familyName, StringComparison.OrdinalIgnoreCase)
                    ? Path.ChangeExtension(rfaFilePath, ".json")
                    : Path.ChangeExtension(rfaFilePath, $";{familySymbol.Name}.json");

                var familyTypeExportArgs = new FamilySymbolExportEventArgs {
                    FamilyFilePath = rfaFilePath, Symbol = familySymbol?.Name, OutputFilePath = outputFilePath
                };
                this?.OnSymbolExportStarted(familyTypeExportArgs);

                if (string.IsNullOrWhiteSpace(outputFilePath) || File.Exists(outputFilePath))
                {
                    continue;
                }

                using (var t = new Transaction(docWrapper, $"Placing family instance '{familySymbol.Name}'"))
                {
                    t.Start();
                    if (!familySymbol.IsActive)
                    {
                        familySymbol.Activate();
                    }

                    familyInstance = docWrapper.Create.NewFamilyInstance(
                        XYZ.Zero,
                        familySymbol,
                        StructuralType.NonStructural);

                    t.Commit();
                }

                var context = new ObjectSceneExportContext(docWrapper, view3d);
                using (var exporter = new ObjectSceneExporter(docWrapper, context)
                {
                    ShouldStopOnError = false,
                })
                {
                    var objectScene     = exporter.Export(view3d as View);
                    var objectSceneJson = objectScene.ToString();
                    File.WriteAllText(outputFilePath, objectSceneJson);
                }

                this?.OnSymbolExportEnded(familyTypeExportArgs);

                using (var t = new Transaction(docWrapper, $"Remove family symbol '{familyInstance.Name}'"))
                {
                    t.Start();
                    docWrapper.Delete(familySymbol.Id);
                    t.Commit();
                }

                familyInstance.Dispose();
            }

            this?.OnExportEnded(familyExportArgs);

            using (var t = new Transaction(docWrapper, $"Remove family '{family.Name}'"))
            {
                t.Start();
                docWrapper.Delete(family.Id);
                t.Commit();
            }

            family.Dispose();
        }
 public ObjectSceneExporter(Document document, ObjectSceneExportContext context)
     : base(document, context)
 {
     this.context = context;
 }