public ErrorType ExportDocumentWithAcvtiveView(Document document)
        {
            string exportFolder = ExportEventHandler.Settings.OutputFolder;

            if (document == null || !Directory.Exists(exportFolder))
            {
                return(ErrorType.Others);
            }

            Container.metadata.generator    = "NDS";
            Container.metadata.type         = "Object";
            Container.metadata.version      = "1.0";
            Container.va3cobject.uuid       = StringConverter.NewGuid();
            Container.va3cobject.type       = "Root Object";
            Container.va3cobject.name       = StringConverter.ToUtf8(Path.GetFileName(document.PathName));
            Container.va3cobject.bHasMatrix = true;
            TransformExporter.GetRootObjectMatrix(ref Container.va3cobject.matrix);

            //Constructs a new FilteredElementCollector that will search and filter the visible elements in a view.
            FilteredElementCollector elems = new FilteredElementCollector(document, document.ActiveView.Id).WhereElementIsNotElementType();

            if (elems.GetElementCount() == 0)
            {
                return(ErrorType.NoElement);
            }

            Dictionary <ElementId, List <Element> > elementsDic = new Dictionary <ElementId, List <Element> >();

            ClassifyElementsByStructureType(elems, ref elementsDic);
            if (ExportEventHandler.Settings.StructureType == CommonSettings.StructureTreeType.ByLevel)
            {
                if (!LevelExporter.ExportLevels(elementsDic, ref Container.va3cobject, document))
                {
                    return(ErrorType.NoElement);
                }
            }
            else if (ExportEventHandler.Settings.StructureType == CommonSettings.StructureTreeType.ByCategory)
            {
                if (!CategoryExporter.ExportCategories(elementsDic, ref Container.va3cobject, document))
                {
                    return(ErrorType.NoElement);
                }
            }

            MaterialExporter.GetAllMaterials(ref Container.materials);
            MaterialExporter.CopyTextureFiles(exportFolder);
            GeometryExporter.GetAllGeometries(ref Container.geometries);
            PropertyExporter.WritePropertyFiles(exportFolder);
            if (Container.va3cobject.children.Count == 0 || Container.geometries.Count == 0)
            {
                return(ErrorType.NoElement);
            }

            if (!Web3DModelWriterManage.Web3DModelWriterManage.WriteWeb3DModelFilesVersion7BufferChunksBvh(ref Container, exportFolder, "model.js", "geom.bin", 2))
            {
                return(ErrorType.UnSupportedGeometry);
            }

            return(ErrorType.Success);;
        }
 public DocumentExporter(Application app)
 {
     Container = new Va3cContainer();
     ElementExporter.Initial();
     MaterialExporter.Initial(app);
     GeometryExporter.Initial();
     PropertyExporter.Initial();
 }
Пример #3
0
        static public bool ExportElement(Element element, ref Va3cContainer.Va3cObject categoryObject)
        {
            if (!IsValidElement(element))
            {
                return(false);
            }

            Va3cContainer.Va3cObject elementObject = new Va3cContainer.Va3cObject();
            elementObject.uuid = StringConverter.NewGuid();
            elementObject.type = element.GetType().Name;
            elementObject.name = element.Name;

            //export transform matrix
            if (element is FamilyInstance)
            {
                Transform transform = (element as Instance).GetTransform();
                if (!transform.IsIdentity)
                {
                    elementObject.bHasMatrix = true;
                    if (!TransformExporter.ExportTransform(transform, ref elementObject.matrix))
                    {
                        return(false);
                    }
                }
            }

            //FamilyInstance不用重复导出几何数据
            if (element is FamilyInstance)
            {
                int hashcode = GetFamilyInstanceHashCode(element as FamilyInstance);
                if (hashcode != -1 && _existFamilyInstanceObjects.ContainsKey(hashcode))
                {
                    if (CopyObject(ref elementObject, _existFamilyInstanceObjects[hashcode]))
                    {
                        if (elementObject.children.Count > 0)
                        {
                            ExportParameters(element, ref elementObject);
                            categoryObject.children.Add(elementObject);
                        }

                        return(true);
                    }
                }
            }

            List <GeometryObject> geometryObjects = new List <GeometryObject>();

            if (!GetGeometryObjects(element, ref geometryObjects))
            {
                return(false);
            }
            if (!GeometryExporter.ExportGeometryObject(geometryObjects, ref elementObject, element.Document))
            {
                return(false);
            }

            if (elementObject.children.Count > 0)
            {
                ExportParameters(element, ref elementObject);
                categoryObject.children.Add(elementObject);
            }

            if (element is FamilyInstance)
            {
                int hashcode = GetFamilyInstanceHashCode(element as FamilyInstance);
                if (hashcode != -1 && !_existFamilyInstanceObjects.ContainsKey(hashcode))
                {
                    _existFamilyInstanceObjects.Add(hashcode, elementObject);
                }
            }

            return(true);
        }