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();
 }
Exemple #3
0
        static private void ExportParameters(Element element, ref Va3cContainer.Va3cObject elementObject)
        {
            string      propertyName = string.Empty;
            ElementType elementType  = element.Document.GetElement(element.GetTypeId()) as ElementType;

            if (elementType != null && string.IsNullOrEmpty(elementType.FamilyName))
            {
                propertyName += (elementType.FamilyName + " " + element.Name);
            }
            else
            {
                propertyName = element.Name;
            }

            string propertyFileName;

            if (PropertyExporter.ExportParameters(propertyName, elementObject.uuid, element.ParametersMap, out propertyFileName))
            {
                elementObject.propertyfile = propertyFileName;
            }
        }
Exemple #4
0
    static private bool ExportLevel(KeyValuePair <ElementId, List <Element> > levelElements, ref Va3cContainer.Va3cObject rootObject, Document activeDocument)
    {
        Va3cContainer.Va3cObject levelObject = new Va3cContainer.Va3cObject();
        levelObject.uuid = StringConverter.NewGuid();
        levelObject.type = "Level";
        Level level = activeDocument.GetElement(levelElements.Key) as Level;

        if (level != null)
        {
            levelObject.name = level.Name;
        }
        else
        {
            levelObject.name = "无标高";
        }

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

        foreach (Element element in levelElements.Value)
        {
            Category  category   = element.Category;
            ElementId categoryId = new ElementId(-1);
            if (category != null)
            {
                categoryId = category.Id;
            }
            else
            {
                categoryId = new ElementId(-1);
            }

            if (CategoryElementsDic.ContainsKey(categoryId))
            {
                CategoryElementsDic[categoryId].Add(element);
            }
            else
            {
                CategoryElementsDic.Add(categoryId, new List <Element> {
                        element
                    });
            }
        }

        if (!CategoryExporter.ExportCategories(CategoryElementsDic, ref levelObject, activeDocument))
        {
            return(false);
        }

        if (level != null)
        {
            string propertyFileName;
            if (PropertyExporter.ExportParameters(levelObject.name, levelObject.uuid, level.ParametersMap, out propertyFileName))
            {
                levelObject.propertyfile = propertyFileName;
            }
        }

        if (levelObject.children.Count > 0)
        {
            rootObject.children.Add(levelObject);
        }

        return(true);
    }