Exemple #1
0
        public void OnElementEnd(
            ElementId id)
        {
            // Note: this method is invoked even for
            // elements that were skipped.

            Element e   = _doc.GetElement(id);
            string  uid = e.UniqueId;

            Debug.WriteLine(string.Format(
                                "OnElementEnd: id {0} category {1} name {2}",
                                id.IntegerValue, e.Category.Name, e.Name));

            if (_objects.ContainsKey(uid))
            {
                Debug.WriteLine("\r\n*** Duplicate element!\r\n");
                return;
            }

            if (null == e.Category)
            {
                Debug.WriteLine("\r\n*** Non-category element!\r\n");
                return;
            }

            List <string> materials = _vertices.Keys.ToList();

            int n = materials.Count;

            _currentElement.children = new List <Va3cContainer.Va3cObject>(n);

            foreach (string material in materials)
            {
                Va3cContainer.Va3cObject   obj = _currentObject[material];
                Va3cContainer.Va3cGeometry geo = _currentGeometry[material];

                foreach (KeyValuePair <PointInt, int> p in _vertices[material])
                {
                    geo.data.vertices.Add(_scale_vertex * p.Key.X);
                    geo.data.vertices.Add(_scale_vertex * p.Key.Y);
                    geo.data.vertices.Add(_scale_vertex * p.Key.Z);
                }
                obj.geometry = geo.uuid;
                _geometries.Add(geo.uuid, geo);
                _currentElement.children.Add(obj);
            }

            Dictionary <string, string> d
                = Util.GetElementProperties(e, true);

            _currentElement.userData = d;

            //also add guid to user data dict
            _currentElement.userData.Add("revit_id", uid);

            _objects.Add(_currentElement.uuid, _currentElement);

            _elementStack.Pop();
        }
Exemple #2
0
        public RenderNodeAction OnElementBegin(
            ElementId elementId)
        {
            Element e   = _doc.GetElement(elementId);
            string  uid = e.UniqueId;

            Debug.WriteLine(string.Format(
                                "OnElementBegin: id {0} category {1} name {2}",
                                elementId.IntegerValue, e.Category.Name, e.Name));

            if (_objects.ContainsKey(uid))
            {
                Debug.WriteLine("\r\n*** Duplicate element!\r\n");
                return(RenderNodeAction.Skip);
            }

            if (null == e.Category)
            {
                Debug.WriteLine("\r\n*** Non-category element!\r\n");
                return(RenderNodeAction.Skip);
            }

            _elementStack.Push(elementId);

            ICollection <ElementId> idsMaterialGeometry = e.GetMaterialIds(false);
            ICollection <ElementId> idsMaterialPaint    = e.GetMaterialIds(true);

            int n = idsMaterialGeometry.Count;

            if (1 < n)
            {
                Debug.Print("{0} has {1} materials: {2}",
                            Util.ElementDescription(e), n,
                            string.Join(", ", idsMaterialGeometry.Select(
                                            id => _doc.GetElement(id).Name)));
            }

            // We handle a current element, which may either
            // be identical to the current object and have
            // one single current geometry or have
            // multiple current child objects each with a
            // separate current geometry.

            _currentElement = new Va3cContainer.Va3cObject();

            _currentElement.name     = Util.ElementDescription(e);
            _currentElement.material = _currentMaterialUid;
            _currentElement.matrix   = new double[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
            _currentElement.type     = "RevitElement";
            _currentElement.uuid     = uid;

            _currentObject   = new Dictionary <string, Va3cContainer.Va3cObject>();
            _currentGeometry = new Dictionary <string, Va3cContainer.Va3cGeometry>();
            _vertices        = new Dictionary <string, VertexLookupInt>();

            if (null != e.Category &&
                null != e.Category.Material)
            {
                SetCurrentMaterial(e.Category.Material.UniqueId);
            }

            return(RenderNodeAction.Proceed);
        }