Exemple #1
0
        static private bool CopyObject(ref Va3cContainer.Va3cObject destObject, Va3cContainer.Va3cObject srcObject)
        {
            if (destObject == null || srcObject == null)
            {
                return(false);
            }

            destObject.type     = srcObject.type;
            destObject.name     = srcObject.name;
            destObject.material = srcObject.material;
            destObject.geometry = srcObject.geometry;

            foreach (var child in srcObject.children)
            {
                Va3cContainer.Va3cObject destChild = new Va3cContainer.Va3cObject();
                destChild.uuid = StringConverter.NewGuid();
                if (!CopyObject(ref destChild, child))
                {
                    return(false);
                }
                destObject.children.Add(destChild);
            }

            return(true);
        }
    static private bool ExportFamily(KeyValuePair <string, List <Element> > familyElements, ref Va3cContainer.Va3cObject categoryObject)
    {
        if (familyElements.Value.Count == 0)
        {
            return(false);
        }

        Va3cContainer.Va3cObject familyObject = new Va3cContainer.Va3cObject();
        familyObject.uuid = StringConverter.NewGuid();
        familyObject.type = "Family";
        familyObject.name = familyElements.Key;

        Dictionary <string, List <Element> > familySymbolElementsDic = new Dictionary <string, List <Element> >();
        List <Element> noFamilySymbolElementsList = new List <Element>();

        foreach (Element element in familyElements.Value)
        {
            string familySymbolName;
            if (GetElementFamilySymbolName(element, out familySymbolName))
            {
                if (familySymbolElementsDic.ContainsKey(familySymbolName))
                {
                    familySymbolElementsDic[familySymbolName].Add(element);
                }
                else
                {
                    familySymbolElementsDic.Add(familySymbolName, new List <Element> {
                            element
                        });
                }
            }
            else
            {
                noFamilySymbolElementsList.Add(element);
            }
        }
        ExportFamilySymbols(familySymbolElementsDic, ref familyObject);

        foreach (Element element in noFamilySymbolElementsList)
        {
            if (!ElementExporter.ExportElement(element, ref familyObject))
            {     /*log*/
            }
        }

        if (familyObject.children.Count > 0)
        {
            categoryObject.children.Add(familyObject);
        }

        return(true);
    }
static private bool ExportFamilySymbol(KeyValuePair <string, List <Element> > familySymbolElements, ref Va3cContainer.Va3cObject familyObject)
{
    Va3cContainer.Va3cObject familySymbolObject = new Va3cContainer.Va3cObject();
    familySymbolObject.uuid = StringConverter.NewGuid();
    familySymbolObject.type = "Family Symbol";
    familySymbolObject.name = familySymbolElements.Key;

    foreach (Element element in familySymbolElements.Value)
    {
        if (!ElementExporter.ExportElement(element, ref familySymbolObject))
        {         /*log*/
        }
    }

    if (familySymbolObject.children.Count > 0)
    {
        familyObject.children.Add(familySymbolObject);
    }

    return(true);
}
Exemple #4
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;
            }
        }
    static private bool ExportFamilySymbols(Dictionary <string, List <Element> > familySymbolElementsDic, ref Va3cContainer.Va3cObject familyObject)
    {
        foreach (var familySymbolElements in familySymbolElementsDic)
        {
            if (!ExportFamilySymbol(familySymbolElements, ref familyObject))
            {
                continue;
            }
            else /*write log*/ } {
    }

    return(true);
}
        static public bool ExportFamilys(Dictionary <string, List <Element> > familyElementsDic, ref Va3cContainer.Va3cObject categoryObject)
        {
            foreach (var familyElements in familyElementsDic)
            {
                if (!ExportFamily(familyElements, ref categoryObject))
                {
                    continue;
                }
                else /*write log*/ } {
        }

        return(true);
    }
Exemple #7
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);
        }
Exemple #8
0
        static public bool ExportGeometryObject(List <GeometryObject> rvtGeometryObjects, ref Va3cContainer.Va3cObject elementObject, Document document)
        {
            Dictionary <ElementId, List <Face> > faceGroups = new Dictionary <ElementId, List <Face> >();
            Dictionary <ElementId, List <Mesh> > meshGroups = new Dictionary <ElementId, List <Mesh> >();  //按材质分组
            List <Curve>    curveGroup    = new List <Curve>();
            List <PolyLine> polylineGroup = new List <PolyLine>();

            foreach (GeometryObject rvtGeometryObject in rvtGeometryObjects)
            {
                ClassifyGeometryObjects(rvtGeometryObject, document, ref faceGroups, ref meshGroups, ref curveGroup, ref polylineGroup);
            }

            //导出face
            foreach (KeyValuePair <ElementId, List <Face> > faceGroup in faceGroups)
            {
                Va3cContainer.Va3cObject faceGroupObject = new Va3cContainer.Va3cObject();
                faceGroupObject.uuid = StringConverter.NewGuid();
                faceGroupObject.type = "Mesh";
                faceGroupObject.name = "Face Group";
                Material material = document.GetElement(faceGroup.Key) as Material;
                Va3cContainer.Va3cGeometry faceGroupGeometry = new Va3cContainer.Va3cGeometry();
                faceGroupGeometry.uuid = StringConverter.NewGuid();
                faceGroupGeometry.data.nGeometryCategory = eGeometryCategory.Triangle;
                faceGroupObject.geometry = faceGroupGeometry.uuid;
                bool bHasUvs;
                if (ExportFaces(faceGroup.Value, ref faceGroupGeometry, out bHasUvs))
                {
                    if (bHasUvs)
                    {
                        MaterialExporter.ExportMaterial(material, typeof(Face), ref faceGroupObject.material);
                    }
                    else
                    {
                        MaterialExporter.ExportMaterial(material, typeof(Mesh), ref faceGroupObject.material);
                    }
                    elementObject.children.Add(faceGroupObject);
                    Geometries.Add(faceGroupGeometry);
                }
            }


            //导出mesh
            foreach (KeyValuePair <ElementId, List <Mesh> > meshGroup in meshGroups)
            {
                Va3cContainer.Va3cObject meshGroupObject = new Va3cContainer.Va3cObject();
                meshGroupObject.uuid = StringConverter.NewGuid();
                meshGroupObject.type = "Mesh";
                meshGroupObject.name = "Mesh Group";
                Material material = document.GetElement(meshGroup.Key) as Material;
                MaterialExporter.ExportMaterial(material, typeof(Mesh), ref meshGroupObject.material);
                Va3cContainer.Va3cGeometry meshGroupGeometry = new Va3cContainer.Va3cGeometry();
                meshGroupGeometry.uuid = StringConverter.NewGuid();
                meshGroupGeometry.data.nGeometryCategory = eGeometryCategory.Triangle;
                meshGroupObject.geometry = meshGroupGeometry.uuid;

                if (ExportMeshes(meshGroup.Value, ref meshGroupGeometry))
                {
                    elementObject.children.Add(meshGroupObject);
                    Geometries.Add(meshGroupGeometry);
                }
            }

            //导出edge
            Va3cContainer.Va3cObject edgeGroupObject = new Va3cContainer.Va3cObject();
            edgeGroupObject.uuid = StringConverter.NewGuid();
            edgeGroupObject.type = "LinePieces";
            edgeGroupObject.name = "Edge Group";
            MaterialExporter.ExportMaterial(null, typeof(Edge), ref edgeGroupObject.material);
            Va3cContainer.Va3cGeometry edgeGroupGeometry = new Va3cContainer.Va3cGeometry();
            edgeGroupGeometry.uuid = StringConverter.NewGuid();
            edgeGroupGeometry.data.nGeometryCategory = eGeometryCategory.Line;
            edgeGroupObject.geometry = edgeGroupGeometry.uuid;
            if (ExportCurveAndPoliLines(curveGroup, polylineGroup, ref edgeGroupGeometry))
            {
                elementObject.children.Add(edgeGroupObject);
                Geometries.Add(edgeGroupGeometry);
            }

            return(true);
        }
Exemple #9
0
        static public bool ExportLevels(Dictionary <ElementId, List <Element> > levelElementsDic, ref Va3cContainer.Va3cObject rootObject, Document activeDocument)
        {
            KeyValuePair <ElementId, List <Element> >[] sortedArr;
            SortLevelDictionary(levelElementsDic, out sortedArr, activeDocument);

            foreach (KeyValuePair <ElementId, List <Element> > levelElements in sortedArr)
            {
                if (!ExportLevel(levelElements, ref rootObject, activeDocument))
                {
                    continue;
                }
                else /*write log*/ } {
        }

        return(rootObject.children.Count > 0);
    }
Exemple #10
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);
    }
        static public bool ExportCategories(Dictionary <ElementId, List <Element> > categoryElementsDic, ref Va3cContainer.Va3cObject rootObject, Document activeDocument)
        {
            foreach (var categoryElements in categoryElementsDic)
            {
                if (!ExportCategory(categoryElements, ref rootObject, activeDocument))
                {
                    continue;
                }
                else /*write log*/ } {
        }

        return(true);
    }
    static private bool ExportCategory(KeyValuePair <ElementId, List <Element> > categoryElements, ref Va3cContainer.Va3cObject rootObject, Document activeDocument)
    {
        if (categoryElements.Value.Count == 0)
        {
            return(false);
        }

        Va3cContainer.Va3cObject categoryObject = new Va3cContainer.Va3cObject();
        categoryObject.uuid = StringConverter.NewGuid();
        categoryObject.type = "Category";

        Category category = Category.GetCategory(activeDocument, categoryElements.Key);

        if (category == null)
        {
            categoryObject.name = "无类别";
        }
        else
        {
            categoryObject.name = category.Name;
        }

        Dictionary <string, List <Element> > familyElementsDic = new Dictionary <string, List <Element> >();
        List <Element> noFamilyElementsList = new List <Element>();

        foreach (Element element in categoryElements.Value)
        {
            string familyName;
            if (GetElementFamilyName(element, out familyName))
            {
                if (familyElementsDic.ContainsKey(familyName))
                {
                    familyElementsDic[familyName].Add(element);
                }
                else
                {
                    familyElementsDic.Add(familyName, new List <Element> {
                            element
                        });
                }
            }
            else
            {
                noFamilyElementsList.Add(element);
            }
        }
        FamilyExporter.ExportFamilys(familyElementsDic, ref categoryObject);

        foreach (Element element in noFamilyElementsList)
        {
            if (!ElementExporter.ExportElement(element, ref categoryObject))
            {     /*log*/
            }
        }

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

        return(true);
    }