예제 #1
0
        private Common.Models.Face UpdateFace(Document doc, Common.Models.Face face)
        {
            _log("GETTING ELEMENT");

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Paint Element");

                ElementId materialId    = new ElementId(Int32.Parse(face.MaterialId));
                ElementId parentId      = new ElementId(Int32.Parse(face.ElementId));
                Element   parentElement = doc.GetElement(parentId);

                GeometryElement          defaultGeometry = parentElement.get_Geometry(new Options());
                Solid                    solidGeometry   = defaultGeometry.FirstOrDefault() as Solid;
                IEnumerable <PlanarFace> faces           = solidGeometry.Faces.Cast <PlanarFace>();

                if (solidGeometry == null)
                {
                    throw new Exception($"Geometry does not exist for {face.ElementId}");
                }

                PlanarFace dbValue = faces.ElementAt(face.FaceIndex);

                if (dbValue == null)
                {
                    throw new Exception($"Could not find face at index {face.FaceIndex}");
                }

                doc.Paint(parentId, dbValue, materialId);

                _log($"MAPPED MATERIAL");

                face = GeometryConversion.ConvertToDTO(parentElement, solidGeometry).ElementAt(face.FaceIndex);

                tx.Commit();
            }

            return(face);
        }
예제 #2
0
        public Message Execute(Document doc, Message msg)
        {
            _log("EXECUTE PAINT");

            JObject dto = JObject.Parse(msg.Data);

            Common.Models.Face face = dto.ToObject <Common.Models.Face>();

            _log("GOT DTO");
            _log(JsonConvert.SerializeObject(face));

            face = UpdateFace(doc, face);

            _log("NEW VALUE");
            _log(JsonConvert.SerializeObject(face));

            return(new Message
            {
                Type = "VALUE",
                Data = JsonConvert.SerializeObject(face)
            });
        }