Exemplo n.º 1
0
 public void Application_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
 {
     ExecuteEventHooks(EventType.Application_DocumentOpened, sender, e);
 }
Exemplo n.º 2
0
        private void appDocOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
        {
            Variables.logOpenEnd      = DateTime.Now;
            Variables.logOpenDuration = Variables.logOpenEnd - Variables.logOpenStart;

            Autodesk.Revit.ApplicationServices.Application app = sender as Autodesk.Revit.ApplicationServices.Application;
            Document doc = e.Document;

            #region Variables: Document & Application Variables
            string path = GetUNCPath(doc.PathName);

            BasicFileInfo fileInfo = BasicFileInfo.Extract(path);
            FileInfo      f        = new FileInfo(path);

            Variables.logComputerName    = Environment.MachineName;
            Variables.logChangesSaved    = fileInfo.AllLocalChangesSavedToCentral;
            Variables.logFileCentral     = GetUNCPath(fileInfo.CentralPath);
            Variables.logFileCentralName = Path.GetFileName(Variables.logFileCentral);
            Variables.logIsCentral       = fileInfo.IsCentral;
            Variables.logIsWorkshared    = fileInfo.IsWorkshared;
            Variables.logCreatedLocal    = fileInfo.IsCreatedLocal;

            Variables.logFileName = doc.Title;
            Variables.logFilePath = GetUNCPath(doc.PathName);
            Variables.logFileSize = Convert.ToInt32(f.Length / 1000000);

            Variables.logUsername      = app.Username;
            Variables.logVersionBuild  = app.VersionBuild;
            Variables.logVersionName   = app.VersionName;
            Variables.logVersionNumber = app.VersionNumber;
            #endregion

            #region Tracking: Start Logging Pinned Elements
            IEnumerable <Element> a = TrackChanges.Command.GetTrackedElements(doc);
            _start_state = TrackChanges.Command.GetSnapshot(a);
            #endregion


            #region Settings: Load settings if they exist (Extensible Storage)
            ParameterCommands.Load(doc);
            #endregion

            #region Post: Worksharing Warning-Opened Central Model
            bool patheq = string.Equals(Variables.logFileCentral, Variables.logFilePath);

            if (Variables.slackOn && Variables.slackWSWarn)
            {
                if (patheq && Variables.logIsWorkshared)
                {
                    string gif_lg_url = null;
                    string gif_sm_url = null;

                    if (Variables.giphySet > 0)
                    {
                        var    giphyClient = new GiphyClient();
                        string gif_msg     = giphyClient.GetRandomGif("Alarm").Content;
                        var    gif_resp    = JsonConvert.DeserializeObject <Giphy.Response>(gif_msg);

                        if (Variables.giphySet == 1)
                        {
                            gif_sm_url = gif_resp.data.fixed_height_small_url;
                        }

                        if (Variables.giphySet == 2)
                        {
                            gif_lg_url = gif_resp.data.image_url;
                        }
                    }

                    var slackClient = new SlackClient(Variables.slackToken);

                    string text     = "";
                    string channel  = Variables.slackChId;
                    string botname  = "Worksharing Warning";
                    string icon_url = Variables.icon_revit;

                    var attachments = new Attachments
                    {
                        fallback = Variables.logUsername + "has opened the central model",
                        color    = "danger",
                        fields   =
                            new Fields[]
                        {
                            new Fields
                            {
                                title  = "Description",
                                value  = "The user has opened the central model. Close the central model and create a new local file> to work from.",
                                @short = false
                            },
                            new Fields
                            {
                                title  = "User",
                                value  = Variables.logUsername,
                                @short = true
                            },
                            new Fields
                            {
                                title  = "File",
                                value  = Variables.logFileCentralName,
                                @short = true
                            }
                        },
                        image_url = gif_lg_url,
                        thumb_url = gif_sm_url
                    };

                    string msg_response = slackClient.PostMessage(text, channel: channel, botName: botname, attachments: attachments, icon_url: icon_url).Content;
                    var    resp         = JsonConvert.DeserializeObject <ChatPostMessageResponse>(msg_response);
                    msgts_ws.Add(resp.ts);
                }
            }
            #endregion

            #region Post: Model Warning-File Size > 300MB
            if (Variables.slackOn && Variables.slackModelWarn)
            {
                string gif_lg_url = null;
                string gif_sm_url = null;

                if (Variables.logFileSize > 300)
                {
                    if (Variables.giphySet > 0)
                    {
                        var    giphyClient = new GiphyClient();
                        string gif_msg     = giphyClient.GetRandomGif("Gasp").Content;
                        var    gif_resp    = JsonConvert.DeserializeObject <Giphy.Response>(gif_msg);

                        if (Variables.giphySet == 1)
                        {
                            gif_sm_url = gif_resp.data.fixed_height_small_url;
                        }

                        if (Variables.giphySet == 2)
                        {
                            gif_lg_url = gif_resp.data.image_url;
                        }

                        var slackClient = new SlackClient(Variables.slackToken);

                        string text     = "";
                        string channel  = Variables.slackChId;
                        string botname  = "Model Warning";
                        string icon_url = Variables.icon_revit;

                        var attachments = new Attachments
                        {
                            fallback = "The file size has gone above 300MB, time to do some model file size management.",
                            color    = "danger",
                            fields   =
                                new Fields[]
                            {
                                new Fields
                                {
                                    title  = "Description",
                                    value  = "The file size is above 300MB, time to do some model maintenance",
                                    @short = false
                                },
                                new Fields
                                {
                                    title  = "File Size",
                                    value  = Variables.logFileSize.ToString() + "MB",
                                    @short = true
                                },
                                new Fields
                                {
                                    title  = "File",
                                    value  = Variables.logFileCentralName,
                                    @short = true
                                }
                            },
                            image_url = gif_lg_url,
                            thumb_url = gif_sm_url
                        };

                        string msg_response = slackClient.PostMessage(text, channel: channel, botName: botname, attachments: attachments, icon_url: icon_url).Content;
                        var    resp         = JsonConvert.DeserializeObject <ChatPostMessageResponse>(msg_response);

                        msgts_model.Add(resp.ts);
                    }
                }
                #endregion

                #region Post: Tracking-Pinned Element-Started

                if (Variables.slackOn && Variables.slackExtraTrackPin)
                {
                    var slackClient = new SlackClient(Variables.slackToken);

                    //Post pinned elements message
                    string text     = "";
                    string channel  = Variables.slackChId;
                    string botname  = "Pinning Info";
                    string icon_url = Variables.icon_revit;


                    var attachments = new Attachments
                    {
                        fallback = Variables.logUsername + "has started tracking pinned elements.",
                        color    = "good",
                        fields   =
                            new Fields[]
                        {
                            new Fields
                            {
                                title  = "Status",
                                value  = Variables.logUsername + " has started tracking pinned elements.\n[" + Variables.logFileCentralName + "]",
                                @short = true
                            }
                        }
                    };

                    string msg_response = slackClient.PostMessage(text, channel: channel, botName: botname, attachments: attachments, icon_url: icon_url).Content;
                    var    resp         = JsonConvert.DeserializeObject <ChatPostMessageResponse>(msg_response);
                    msgts_extra.Add(resp.ts);
                }
                #endregion
            }
        }
Exemplo n.º 3
0
 void m_app_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
 {
     DisplayEvent("Document opened");
 }
Exemplo n.º 4
0
 void DocumentOpened(object sender, RevitDB.Events.DocumentOpenedEventArgs e)
 {
 }
Exemplo n.º 5
0
 private void ControlledApplication_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// Handler for Revit's DocumentOpened event.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnApplicationDocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
 {
     HandleApplicationDocumentOpened();
 }
Exemplo n.º 7
0
 void RevitApp_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
 {
     textBox_log.Text     += "RevitApp_DocumentOpened: Cancellable:" + e.Cancellable.ToString() + " , IsCancelled: " + e.IsCancelled().ToString() + " , Status:" + e.Status.ToString() + Environment.NewLine;
     m_receivedCancelEvent = (e.Status == Autodesk.Revit.DB.Events.RevitAPIEventStatus.Cancelled);
 }
Exemplo n.º 8
0
        private void Application_DocumentOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
        {
            Application   app   = sender as Application;
            UIApplication uiApp = new UIApplication(app);
            Document      doc   = uiApp.ActiveUIDocument.Document;

            Utilits.Doc = doc;
            //app.DocumentChanged += new EventHandler<DocumentChangedEventArgs>(OnDocumentChanged);

            //Создание словаря
            MapConnectorsToCircuits dicConnCirc = new MapConnectorsToCircuits();
            //Develop.dicConnectCirc = dicConnCirc;

            //Перебор всех коннекторов для заполнения коннекторов
            //ElementId idConnect = ElementId.InvalidElementId;
            //string idCircuits = "";

            List <ElementId> circuitsId = new List <ElementId>();

            FilteredElementCollector filtConnectors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_TelephoneDevices).WhereElementIsNotElementType();

            foreach (var el in filtConnectors)
            {
                string strIdCirc = el.LookupParameter("ID_Circuits").AsString();
                //Проверка если в коннекторе нет цепей
                if (strIdCirc != null)
                {
                    string[] spl = strIdCirc.Split('?');
                    for (int i = 0; i < spl.Length; i++)
                    {
                        string strid = spl[i];
                        if (Int32.TryParse(strid, out int intId))
                        {
                            ElementId idCirc = new ElementId(Int32.Parse(strid));
                            dicConnCirc.Add(el.Id, idCirc);
                            circuitsId.Add(idCirc);
                        }
                    }
                }
            }

            Develop.dicConnectCirc = dicConnCirc;
            CircUpdater updater = new CircUpdater(uiApp.ActiveAddInId);

            Develop.updater = updater;
            //Регистрация апдатера
            if (!UpdaterRegistry.IsUpdaterRegistered(updater.GetUpdaterId()))
            {
                UpdaterRegistry.RegisterUpdater(updater);
            }

            if (circuitsId.Count != 0)
            {
                //Добавление триггера на электрические цепи

                Element   elem      = doc.GetElement(circuitsId.First());
                Parameter parNumber = elem.get_Parameter(BuiltInParameter.RBS_ELEC_CIRCUIT_NUMBER);
                //Parameter parIdConn = elem.GetParameters("IdConnectors").First();
                UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), doc, circuitsId, Element.GetChangeTypeParameter(parNumber));
                //UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), doc, circuitsId, Element.GetChangeTypeParameter(parIdConn));

                UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), doc, circuitsId, Element.GetChangeTypeElementDeletion());


                updater.dic = dicConnCirc;
            }
            if (filtConnectors.Count() != 0)
            {
                //добавление триггера на коннекторы
                //ElementCategoryFilter filt = new ElementCategoryFilter(BuiltInCategory.OST_TelephoneDevices);
                IList <FilterRule> ruls = new List <FilterRule>();
                FilterRule         rule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(BuiltInParameter.ELEM_FAMILY_PARAM), "Эмуляция потребителя без нагрузки", false);
                ruls.Add(rule);
                rule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(BuiltInCategory.OST_TelephoneDevices), (int)BuiltInCategory.OST_TelephoneDevices);
                ruls.Add(rule);
                ElementParameterFilter filter = new ElementParameterFilter(ruls);
                //FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_TelephoneDevices).WherePasses(filter);

                //var fs = new FilteredElementCollector(doc).WhereElementIsNotElementType().Where(x => x.Name == "Bunch");
                UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), doc, filter, Element.GetChangeTypeElementDeletion());
            }
        }