Example #1
0
        public Result Execute(
            ExternalCommandData revit,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = revit.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            string path = doc.PathName;

            BasicFileInfo info = BasicFileInfo.Extract(
                path);

            DocumentVersion v = info.GetDocumentVersion();

            int n = v.NumberOfSaves;

            Util.InfoMsg(string.Format(
                             "Document '{0}' has GUID {1} and {2} save{3}.",
                             path, v.VersionGUID, n,
                             Util.PluralSuffix(n)));

            return(Result.Succeeded);
        }
        /// <summary>
        /// Retrieve the project identification information
        /// to store in the external database and return it
        /// as a dictionary in a JSON formatted string.
        /// </summary>
        string GetProjectDataJson(
            //string project_id,
            Document doc)
        {
            string path = doc.PathName.Replace('\\', '/');

            BasicFileInfo   file_info   = BasicFileInfo.Extract(path);
            DocumentVersion doc_version = file_info.GetDocumentVersion();
            ModelPath       model_path  = doc.GetWorksharingCentralModelPath();

            string central_server_path = null != model_path
        ? model_path.CentralServerPath
        : string.Empty;

            // Hand-written JSON formatting.

            string s = string.Format(
                //"\"_id\": \"{0}\","
                "\"projectinfo_uid\": \"{0}\","
                + "\"versionguid\": \"{1}\","
                + "\"numberofsaves\": {2},"
                + "\"title\": \"{3}\","
                + "\"centralserverpath\": \"{4}\","
                + "\"path\": \"{5}\","
                + "\"computername\": \"{6}\","
                + "\"jid\": \"{7}\"",
                //project_id,
                doc.ProjectInformation.UniqueId,
                doc_version.VersionGUID,
                doc_version.NumberOfSaves,
                doc.Title,
                central_server_path,
                path,
                System.Environment.MachineName,
                Util.GetProjectIdentifier(doc));

            return("{" + s + "}");

            #region Use JavaScriptSerializer
#if USE_JavaScriptSerializer
            // Use JavaScriptSerializer to format JSON data.

            ProjectData project_data = new ProjectData()
            {
                projectinfo_uid   = doc.ProjectInformation.UniqueId,
                versionguid       = doc_version.VersionGUID.ToString(),
                numberofsaves     = doc_version.NumberOfSaves,
                title             = doc.Title,
                centralserverpath = central_server_path,
                path         = path,
                computername = System.Environment.MachineName
            };

            return(new JavaScriptSerializer().Serialize(
                       project_data));
#endif // USE_JavaScriptSerializer
            #endregion // Use JavaScriptSerializer
        }