示例#1
0
        void handleMessage(MessageBuffer buf, int msgType,Document doc,UIDocument uidoc, UIApplication app)
        {
            // create Avatar object if not present
             /* if (avatarObject == null)
              {
              createAvatar(doc,uidoc);
              }*/
              switch ((MessageTypes)msgType)
              {

              case MessageTypes.Resend:
                  {
                      Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(uidoc.Document);
                      COVER.Instance.SendGeometry(collector.WhereElementIsNotElementType().GetElementIterator(), app);

                      ElementClassFilter FamilyFilter = new ElementClassFilter(typeof(FamilySymbol));
                      FilteredElementCollector FamilyCollector = new FilteredElementCollector(uidoc.Document);
                      ICollection<Element> AllFamilies = FamilyCollector.WherePasses(FamilyFilter).ToElements();
                      foreach (FamilySymbol Fmly in AllFamilies)
                      {
                          COVER.Instance.sendFamilySymbolParameters(Fmly);
                      }
                  }
                  break;
              case MessageTypes.SetParameter:
                  {
                      int elemID = buf.readInt();
                      int paramID = buf.readInt();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);

                      foreach (Autodesk.Revit.DB.Parameter para in elem.Parameters)
                      {
                          if (para.Id.IntegerValue == paramID)
                          {

                              switch (para.StorageType)
                              {
                                  case Autodesk.Revit.DB.StorageType.Double:
                                      double d = buf.readDouble();
                                      try
                                      {
                                          para.Set(d);
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      d = para.AsDouble();
                                      break;
                                  case Autodesk.Revit.DB.StorageType.ElementId:
                                      //find out the name of the element
                                      int tmpid = buf.readInt();
                                      Autodesk.Revit.DB.ElementId eleId = new Autodesk.Revit.DB.ElementId(tmpid);
                                      try
                                      {
                                          para.Set(eleId);
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  case Autodesk.Revit.DB.StorageType.Integer:
                                      try
                                      {
                                          para.Set(buf.readInt());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  case Autodesk.Revit.DB.StorageType.String:
                                      try
                                      {
                                          para.Set(buf.readString());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  default:
                                      try
                                      {
                                          para.SetValueString(buf.readString());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                              }

                          }
                      }
                  }
                  break;
              case MessageTypes.SetTransform:
                  {
                      int elemID = buf.readInt();
                      double x = buf.readDouble();
                      double y = buf.readDouble();
                      double z = buf.readDouble();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);
                      Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(x, y, z);
                      Autodesk.Revit.DB.LocationCurve ElementPosCurve = elem.Location as Autodesk.Revit.DB.LocationCurve;
                      if (ElementPosCurve != null)
                          ElementPosCurve.Move(translationVec);
                      Autodesk.Revit.DB.LocationPoint ElementPosPoint = elem.Location as Autodesk.Revit.DB.LocationPoint;
                      if (ElementPosPoint != null)
                          ElementPosPoint.Move(translationVec);
                  }
                  break;
              case MessageTypes.UpdateView:
                  {
                      int elemID = buf.readInt();
                      double ex = buf.readDouble();
                      double ey = buf.readDouble();
                      double ez = buf.readDouble();
                      double dx = buf.readDouble();
                      double dy = buf.readDouble();
                      double dz = buf.readDouble();
                      double ux = buf.readDouble();
                      double uy = buf.readDouble();
                      double uz = buf.readDouble();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);
                      Autodesk.Revit.DB.View3D v3d = (Autodesk.Revit.DB.View3D)elem;
                      Autodesk.Revit.DB.ViewOrientation3D ori = new Autodesk.Revit.DB.ViewOrientation3D(new Autodesk.Revit.DB.XYZ(ex, ey, ez), new Autodesk.Revit.DB.XYZ(ux, uy, uz), new Autodesk.Revit.DB.XYZ(dx, dy, dz));
                      v3d.SetOrientation(ori);
                  }
                  break;

              case MessageTypes.NewAnnotation:
                  {

                      int labelNumber = buf.readInt();
                      double x = buf.readDouble();
                      double y = buf.readDouble();
                      double z = buf.readDouble();
                      double h = buf.readDouble();
                      double p = buf.readDouble();
                      double r = buf.readDouble();
                      string labelText = buf.readString();

                      Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(x, y, z);
                      Autodesk.Revit.DB.View view = document.ActiveView;
                      ElementId currentTextTypeId = document.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);
                      Autodesk.Revit.DB.TextNote tn = Autodesk.Revit.DB.TextNote.Create(document, view.Id, translationVec, labelText, currentTextTypeId);
                      // send back revit ID corresponding to this annotationID
                      // the mapping of annotationIDs to Revit element IDs is done in OpenCOVER
                      MessageBuffer mb = new MessageBuffer();
                      mb.add(labelNumber);
                      mb.add(tn.Id.IntegerValue);
                      sendMessage(mb.buf, MessageTypes.NewAnnotationID);

                  }
                  break;
              case MessageTypes.ChangeAnnotation:
                  {

                      int elemID = buf.readInt();
                      double x = buf.readDouble();
                      double y = buf.readDouble();
                      double z = buf.readDouble();
                      double h = buf.readDouble();
                      double p = buf.readDouble();
                      double r = buf.readDouble();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);

                      Autodesk.Revit.DB.TextNote tn = elem as Autodesk.Revit.DB.TextNote;
                      if (tn != null)
                      {
                          Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(x, y, z);
                          tn.Coord = translationVec;
                      }

                  }
                  break;
              case MessageTypes.SetView:
                  {
                      int currentView = buf.readInt();

                      List<View3D> views = new List<View3D>(
              new FilteredElementCollector(doc)
            .OfClass(typeof(View3D))
            .Cast<View3D>()
            .Where<View3D>(v =>
              v.CanBePrinted && !v.IsTemplate));
                      int n = 0;
                      foreach (View3D v in views)
                      {
                          if (n == currentView)
                          {
                              try
                              {
                              uidoc.ActiveView = v;
                              }
                              catch (Autodesk.Revit.Exceptions.ArgumentNullException e)
                              {
                                  Console.WriteLine("Exception information: {0}", e);
                              }
                              catch (Autodesk.Revit.Exceptions.ArgumentException e)
                              {
                                  Console.WriteLine("Exception information: {0}", e);
                              }
                              catch (Autodesk.Revit.Exceptions.InvalidOperationException e)
                              {
                                  Console.WriteLine("Exception information: {0}", e);
                              }
                              break;
                          }
                          n++;
                      }
                  }
                  break;
              case MessageTypes.ChangeAnnotationText:
                  {

                      int elemID = buf.readInt();
                      string labelText = buf.readString();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);

                      Autodesk.Revit.DB.TextNote tn = elem as Autodesk.Revit.DB.TextNote;
                      if (tn != null)
                      {
                          tn.Text = labelText;
                      }

                  }
                  break;

              case MessageTypes.AvatarPosition:
                  {
                      double ex = buf.readDouble();
                      double ey = buf.readDouble();
                      double ez = buf.readDouble();
                      double dx = buf.readDouble();
                      double dy = buf.readDouble();
                      double dz = buf.readDouble();
                      Level currentLevel = getLevel(doc, ez);
                      string lev = "";
                      if (currentLevel != null)
                      {
                          lev = currentLevel.Name;
                      }
                      Room testRaum = null;
                      Room currentRoom = null;
                      try
                      {
                          XYZ point = new XYZ(ex, ey, ez);
                          currentRoom = doc.GetRoomAtPoint(point);
                          if (currentRoom == null && (currentLevel != null))
                          {
                              point = new XYZ(ex, ey, currentLevel.ProjectElevation);
                              currentRoom = doc.GetRoomAtPoint(point);
                              if (currentRoom == null)
                              {
                                  testRaum = getRoom(doc, ex, ey, ez);
                                  currentRoom = testRaum;
                              }

                          }
                      }
                      catch
                      {
                      }
                      if (currentRoom != null)
                      {

                          string nr = currentRoom.Number;
                          string name = currentRoom.Name;
                          double area = currentRoom.Area;
                          MessageBuffer mb = new MessageBuffer();
                          mb.add(nr);
                          mb.add(name);
                          mb.add(area);
                          mb.add(lev);
                          sendMessage(mb.buf, MessageTypes.RoomInfo);
                      }
                      else
                      {
                          string nr = "-1";
                          string name = "No Room";
                          double area = 0.0;
                          MessageBuffer mb = new MessageBuffer();
                          mb.add(nr);
                          mb.add(name);
                          mb.add(area);
                          mb.add(lev);
                          sendMessage(mb.buf, MessageTypes.RoomInfo);
                      }
                      if (avatarObject != null)
                      {
                          /*
                          Autodesk.Revit.DB.LocationCurve ElementPosCurve = avatarObject.Location as Autodesk.Revit.DB.LocationCurve;
                          Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(ex, ey, ez);
                          ElementPosCurve.Move(translationVec);*/
                      }
                  }
                  break;

              }
        }
示例#2
0
文件: COVER.cs 项目: nixz/covise
        void handleMessage(MessageBuffer buf, int msgType,Document doc,UIDocument uidoc)
        {
            // create Avatar object if not present
             /* if (avatarObject == null)
              {
              createAvatar(doc,uidoc);
              }*/
              switch ((MessageTypes)msgType)
              {
              case MessageTypes.SetParameter:
                  {
                      int elemID = buf.readInt();
                      int paramID = buf.readInt();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);

                      foreach (Autodesk.Revit.DB.Parameter para in elem.Parameters)
                      {
                          if (para.Id.IntegerValue == paramID)
                          {

                              switch (para.StorageType)
                              {
                                  case Autodesk.Revit.DB.StorageType.Double:
                                      double d = buf.readDouble();
                                      try
                                      {
                                          para.Set(d);
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      d = para.AsDouble();
                                      break;
                                  case Autodesk.Revit.DB.StorageType.ElementId:
                                      //find out the name of the element
                                      int tmpid = buf.readInt();
                                      Autodesk.Revit.DB.ElementId eleId = new Autodesk.Revit.DB.ElementId(tmpid);
                                      try
                                      {
                                          para.Set(eleId);
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  case Autodesk.Revit.DB.StorageType.Integer:
                                      try
                                      {
                                          para.Set(buf.readInt());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  case Autodesk.Revit.DB.StorageType.String:
                                      try
                                      {
                                          para.Set(buf.readString());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                                  default:
                                      try
                                      {
                                          para.SetValueString(buf.readString());
                                      }
                                      catch
                                      {
                                          Autodesk.Revit.UI.TaskDialog.Show("Double", "para.Set failed");
                                      }
                                      break;
                              }

                          }
                      }
                  }
                  break;
              case MessageTypes.SetTransform:
                  {
                      int elemID = buf.readInt();
                      double x = buf.readDouble();
                      double y = buf.readDouble();
                      double z = buf.readDouble();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);
                      Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(x, y, z);
                      Autodesk.Revit.DB.LocationCurve ElementPosCurve = elem.Location as Autodesk.Revit.DB.LocationCurve;
                      if (ElementPosCurve != null)
                          ElementPosCurve.Move(translationVec);
                      Autodesk.Revit.DB.LocationPoint ElementPosPoint = elem.Location as Autodesk.Revit.DB.LocationPoint;
                      if (ElementPosPoint != null)
                          ElementPosPoint.Move(translationVec);
                  }
                  break;
              case MessageTypes.UpdateView:
                  {
                      int elemID = buf.readInt();
                      double ex = buf.readDouble();
                      double ey = buf.readDouble();
                      double ez = buf.readDouble();
                      double dx = buf.readDouble();
                      double dy = buf.readDouble();
                      double dz = buf.readDouble();
                      double ux = buf.readDouble();
                      double uy = buf.readDouble();
                      double uz = buf.readDouble();

                      Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(elemID);
                      Autodesk.Revit.DB.Element elem = document.GetElement(id);
                      Autodesk.Revit.DB.View3D v3d = (Autodesk.Revit.DB.View3D)elem;
                      Autodesk.Revit.DB.ViewOrientation3D ori = new Autodesk.Revit.DB.ViewOrientation3D(new Autodesk.Revit.DB.XYZ(ex, ey, ez), new Autodesk.Revit.DB.XYZ(ux, uy, uz), new Autodesk.Revit.DB.XYZ(dx, dy, dz));
                      v3d.SetOrientation(ori);
                  }
                  break;

              case MessageTypes.AvatarPosition:
                  {
                      double ex = buf.readDouble();
                      double ey = buf.readDouble();
                      double ez = buf.readDouble();
                      double dx = buf.readDouble();
                      double dy = buf.readDouble();
                      double dz = buf.readDouble();
                      Level currentLevel = getLevel(doc, ez);
                      string lev = "";
                      if (currentLevel != null)
                      {
                          lev = currentLevel.Name;
                      }
                      Room testRaum = getRoom(doc, ex, ey, ez);
                      XYZ point = new XYZ(ex, ey, ez);
                      Room currentRoom = doc.GetRoomAtPoint(point);
                      if (currentRoom == null)
                      {
                          point = new XYZ(ex, ey, currentLevel.ProjectElevation);
                          currentRoom = doc.GetRoomAtPoint(point);
                          if (currentRoom == null)
                              currentRoom = testRaum;
                      }
                      if (currentRoom != null)
                      {

                          string nr = currentRoom.Number;
                          string name = currentRoom.Name;
                          double area = currentRoom.Area;
                          MessageBuffer mb = new MessageBuffer();
                          mb.add(nr);
                          mb.add(name);
                          mb.add(area);
                          mb.add(lev);
                          sendMessage(mb.buf, MessageTypes.RoomInfo);
                      }
                      else
                      {
                          string nr = "-1";
                          string name = "No Room";
                          double area = 0.0;
                          MessageBuffer mb = new MessageBuffer();
                          mb.add(nr);
                          mb.add(name);
                          mb.add(area);
                          mb.add(lev);
                          sendMessage(mb.buf, MessageTypes.RoomInfo);
                      }
                      if (avatarObject != null)
                      {
                          /*
                          Autodesk.Revit.DB.LocationCurve ElementPosCurve = avatarObject.Location as Autodesk.Revit.DB.LocationCurve;
                          Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(ex, ey, ez);
                          ElementPosCurve.Move(translationVec);*/
                      }
                  }
                  break;

              }
        }