Ejemplo n.º 1
0
        void ApplyWikiwordToBlock(Gtk.TextIter start, Gtk.TextIter end)
        {
            NoteBuffer.GetBlockExtents(ref start,
                                       ref end,
                                       80 /* max wiki name */,
                                       broken_link_tag);

            Buffer.RemoveTag(broken_link_tag, start, end);

            for (Match match = regex.Match(start.GetText(end));
                 match.Success;
                 match = match.NextMatch())
            {
                System.Text.RegularExpressions.Group group = match.Groups [1];

                Logger.Debug("Highlighting wikiword: '{0}' at offset {1}",
                             group,
                             group.Index);

                Gtk.TextIter start_cpy = start;
                start_cpy.ForwardChars(group.Index);

                end = start_cpy;
                end.ForwardChars(group.Length);

                if (Manager.Find(group.ToString()) == null)
                {
                    Buffer.ApplyTag(broken_link_tag, start_cpy, end);
                }
            }
        }
Ejemplo n.º 2
0
        public static string UpdateSpecLayer(ObjectId objectId, string webLayer)
        {
            // TODO: trzeba zalozyc filtr po webLayer i zmieniac wszystkie warstwy w petli poniwaz moze byc kilka tych samych warstw na roznych pietrach
            Editor   ed      = acApp.DocumentManager.MdiActiveDocument.Editor;
            Document acDoc   = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            // Start a transaction
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // This example returns the layer table for the current database
                LayerTable acLyrTbl;
                acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) as LayerTable;
                string layerName    = "";
                string oldLayerName = "";

                // Pobierz starą nazwę warstwy
                LayerTableRecord acLyrTblRecOld;
                acLyrTblRecOld = acTrans.GetObject(objectId, OpenMode.ForRead) as LayerTableRecord;

                Regex regEx = new Regex(@"\[(.+)\]", RegexOptions.IgnoreCase);
                Match match = regEx.Match(acLyrTblRecOld.Name);
                ed.WriteMessage("Match success: " + match.Success.ToString());
                if (match.Success)
                {
                    System.Text.RegularExpressions.Group group = match.Groups[1];
                    oldLayerName = group.ToString();
                }
                ed.WriteMessage("Old layer: " + oldLayerName);

                // Step through the Layer table and print each layer name
                foreach (ObjectId acObjId in acLyrTbl)
                {
                    LayerTableRecord acLyrTblRec;
                    acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForRead) as LayerTableRecord;

                    if (acLyrTblRec.Name.Contains(oldLayerName))
                    {
                        regEx = new Regex(@"\((.)\)", RegexOptions.IgnoreCase);
                        match = regEx.Match(acLyrTblRec.Name);
                        if (match.Success)
                        {
                            System.Text.RegularExpressions.Group group = match.Groups[1];
                            Int32.TryParse(group.ToString(), out currentFloor);
                            layerName = "!FDS_SPEC[" + webLayer + "](" + currentFloor + ")";
                        }
                        acLyrTblRec.UpgradeOpen();
                        acLyrTblRec.Name = layerName;
                        Random r = new Random();
                        acLyrTblRec.Color = Color.FromColorIndex(ColorMethod.ByAci, (Int16)(r.Next(225)));

                        ed.WriteMessage("\n" + acLyrTblRec.Name);
                    }
                }
                acTrans.Commit();
                return("");
            }
        }
Ejemplo n.º 3
0
 private static int GroupToInt(Group g)
 {
     int value;
     if (int.TryParse(g.ToString(), out value))
     {
         return value;
     }
     return -1;
 }
Ejemplo n.º 4
0
 private static string GetDistinctCount(string @select, Group g, string @from)
 {
     var columns = g.ToString().Trim();
     if(columns == "DISTINCT")
     {
         throw new ArgumentException("Malformed SQL; DISTINCT queries must specify at least one column");
     }
     var distinct = string.Concat(@select, "COUNT(", columns,  ") ", @from);
     return distinct;
 }
Ejemplo n.º 5
0
        void OnMenuItemActivated(object sender, EventArgs args)
        {
            NoteTag broken_link_tag = Note.TagTable.BrokenLinkTag;

            Gtk.TextIter note_start, note_end;

            // We get the whole note as a range
            // and then just remove the "broken link" tag from it
            Note.Buffer.GetBounds(out note_start, out note_end);

            // Sweep 'em & recreate WikiWord broken links (depending on Preferences),
            Buffer.RemoveTag(broken_link_tag, note_start, note_end);

            // HACK: The below is copied from Watchers.cs->ApplyWikiwordToBlock()
            // It turns WikiWords back into broken links after sweeping all broken links,
            // but only in case WikiWords are enabled.
            // Most probably there's more elegant way of doing this.

            if ((bool)Preferences.Get(Preferences.ENABLE_WIKIWORDS))
            {
                const string WIKIWORD_REGEX = @"\b((\p{Lu}+[\p{Ll}0-9]+){2}([\p{Lu}\p{Ll}0-9])*)\b";

                Regex regex = new Regex(WIKIWORD_REGEX, RegexOptions.Compiled);

                NoteBuffer.GetBlockExtents(ref note_start,
                                           ref note_end,
                                           80 /* max wiki name */,
                                           broken_link_tag);

                //Buffer.RemoveTag (broken_link_tag, start, end);

                for (Match match = regex.Match(note_start.GetText(note_end));
                     match.Success;
                     match = match.NextMatch())
                {
                    System.Text.RegularExpressions.Group group = match.Groups [1];

                    Logger.Debug("Highlighting back wikiword: '{0}' at offset {1}",
                                 group,
                                 group.Index);

                    Gtk.TextIter start_cpy = note_start;
                    start_cpy.ForwardChars(group.Index);

                    note_end = start_cpy;
                    note_end.ForwardChars(group.Length);

                    if (Manager.Find(group.ToString()) == null)
                    {
                        Buffer.ApplyTag(broken_link_tag, start_cpy, note_end);
                    }
                }
            }
            /// End of hack
        }
Ejemplo n.º 6
0
        public static AdminInfoObject TryParse(string Text)
        {
            Regex           regex;
            MatchCollection matches;
            uint            id;
            string          className;

            AdminInfoProperty[] props;

            // 1) Check if this is an object response

            regex   = new Regex(@":< OBJECT (?<id>\d*) is CLASS (?<classname>.*)");
            matches = regex.Matches(Text);

            // must have exactly one occurence if it is what we're looking for
            if (matches.Count != 1)
            {
                return(null);
            }

            // get values for id and classname
            System.Text.RegularExpressions.Group gID        = matches[0].Groups["id"];
            System.Text.RegularExpressions.Group gClassName = matches[0].Groups["classname"];

            if (!UInt32.TryParse(gID.ToString(), out id))
            {
                id = 0;
            }

            className = gClassName.ToString();

            // 2) Parse out properties

            regex   = new Regex(@": (?<propname>\w*)\s*=\s(?<proptype>[\w$]*)\s(?<propvalue>\w*)");
            matches = regex.Matches(Text);

            props = new AdminInfoProperty[matches.Count];
            for (int i = 0; i < matches.Count; i++)
            {
                props[i] = new AdminInfoProperty(
                    matches[i].Groups["propname"].ToString(),
                    matches[i].Groups["proptype"].ToString(),
                    matches[i].Groups["propvalue"].ToString());
            }

            // 3) Return instance
            return(new AdminInfoObject(id, className, props));
        }
Ejemplo n.º 7
0
        public void HighlightWikiWords(Note note)
        {
            NoteTag broken_link_tag = note.TagTable.BrokenLinkTag;

            Gtk.TextIter note_start, note_end;

            note.Buffer.GetBounds(out note_start, out note_end);

            // HACK: The below is copied from Watchers.cs->ApplyWikiwordToBlock()
            // It turns WikiWords back into broken links after sweeping all broken links,
            // but only in case WikiWords are enabled.
            // Most probably there's more elegant way of doing this.

            const string WIKIWORD_REGEX = @"\b((\p{Lu}+[\p{Ll}0-9]+){2}([\p{Lu}\p{Ll}0-9])*)\b";

            Regex regex = new Regex(WIKIWORD_REGEX, RegexOptions.Compiled);

            NoteBuffer.GetBlockExtents(ref note_start,
                                       ref note_end,
                                       80 /* max wiki name */,
                                       broken_link_tag);

            for (Match match = regex.Match(note_start.GetText(note_end));
                 match.Success;
                 match = match.NextMatch())
            {
                System.Text.RegularExpressions.Group group = match.Groups [1];

                Logger.Debug("Highlighting back wikiword: '{0}' at offset {1}",
                             group,
                             group.Index);

                Gtk.TextIter start_cpy = note_start;
                start_cpy.ForwardChars(group.Index);

                note_end = start_cpy;
                note_end.ForwardChars(group.Length);

                if (note.Manager.Find(group.ToString()) == null)
                {
                    note.Buffer.ApplyTag(broken_link_tag, start_cpy, note_end);
                }
            }
            /// End of hack
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 说明:除img标签外,去掉所有html标签
        /// 作者:李天文
        /// 日期:2010-11-8
        /// </summary>
        /// <param name="html">要过滤的字符串</param>
        /// <returns></returns>
        public static StringBuilder RetainImg(string html)
        {
            StringBuilder str    = new StringBuilder();
            string        pat    = @"<img\s.*?\s?src\s*=\s*['|""]?([^\s'""]+).*?>";
            Regex         r      = new Regex(pat, RegexOptions.Compiled);
            Match         m      = r.Match(html.ToLower());
            string        result = string.Empty;

            while (m.Success)
            {
                System.Text.RegularExpressions.Group g = m.Groups[1];

                if (g.ToString().IndexOf("/xheditor/xheditor_emot") < 0)
                {
                    str.Append(g).Append(",");
                }

                m = m.NextMatch();
            }
            return(str);
        }
Ejemplo n.º 9
0
        public static void CreateLayerForCurrentFloor(string layer)
        {
            Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;
            // Get current floor from current layer name
            Regex regEx = new Regex(@"\((.+)\)", RegexOptions.IgnoreCase);
            Match match = regEx.Match(CurrentLayer());

            if (match.Success)
            {
                System.Text.RegularExpressions.Group group = match.Groups[1];
                Int32.TryParse(group.ToString(), out currentFloor);
                try
                {
                    CreateLayer(layer + "(" + currentFloor + ")");
                    return;
                }
                catch (System.Exception e)
                {
                    CreateLayer(layer + "(0)");
                    ed.WriteMessage("\nProgram exception: " + e.ToString());
                    return;
                }
            }
            else
            {
                try
                {
                    CreateLayer(layer + "(0)");
                }
                catch (System.Exception)
                {
                    CreateLayer("0");
                    ed.WriteMessage("\nWarrning! Layer set to 0. There is no layer " + layer);
                    return;
                }
            }
            return;
        }
Ejemplo n.º 10
0
        public static void DeleteLayer(ObjectId objectId)
        {
            Editor   ed      = acApp.DocumentManager.MdiActiveDocument.Editor;
            Document acDoc   = acApp.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;

            // Upewnij sie czy istnieje warstwa inert
            Utils.Layers.CreateLayer("!FDS_OBST[inert](0)");

            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Layer table for read
                LayerTable acLyrTbl;
                acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
                                             OpenMode.ForRead) as LayerTable;

                LayerTableRecord acLyrTblRec;
                acLyrTblRec = acTrans.GetObject(objectId, OpenMode.ForWrite) as LayerTableRecord;
                string sLayerName = acLyrTblRec.Name;


                if (acLyrTbl.Has(sLayerName) == true)
                {
                    Regex regEx = new Regex(@"\[(.+)\]", RegexOptions.IgnoreCase);
                    Match match = regEx.Match(sLayerName);
                    ed.WriteMessage("\nMatch success: " + match.Success.ToString());
                    string layerName = "";
                    if (match.Success)
                    {
                        System.Text.RegularExpressions.Group group = match.Groups[1];
                        layerName = group.ToString();
                    }
                    ed.WriteMessage("\nOld layer: " + layerName);

                    TypedValue[] filterlist = new TypedValue[1];
                    filterlist[0] = new TypedValue(8, "!FDS*" + layerName + "*");
                    SelectionFilter filter = new SelectionFilter(filterlist);

                    // Request for objects to be selected in the drawing area
                    PromptSelectionResult acSSPrompt;
                    acSSPrompt = ed.SelectAll(filter);

                    if (acSSPrompt.Status == PromptStatus.OK)
                    {
                        SelectionSet acSSet = acSSPrompt.Value;

                        // Step through the objects in the selection set
                        foreach (SelectedObject acSSObj in acSSet)
                        {
                            // Check to make sure a valid SelectedObject object was returned
                            if (acSSObj != null)
                            {
                                // Open the selected object for write
                                Entity acEnt = acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForWrite) as Entity;
                                acEnt.Layer = "!FDS_OBST[inert](0)";
                            }
                        }
                    }

                    // Check to see if it is safe to erase layer
                    ObjectIdCollection acObjIdColl = new ObjectIdCollection();
                    acObjIdColl.Add(acLyrTbl[sLayerName]);
                    acCurDb.Purge(acObjIdColl);

                    if (acObjIdColl.Count > 0)
                    {
                        try
                        {
                            // Erase the unreferenced layer
                            acLyrTblRec.Erase(true);
                            // Save the changes and dispose of the transaction
                            acTrans.Commit();
                        }
                        catch (System.Exception e)
                        {
                            // Layer could not be deleted
                            ed.WriteMessage("WizFDS exception:\n" + e.Message);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public static void CExport()
        {
            Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;

            Dictionary <string, object> Cfast = new Dictionary <string, object>();

            try
            {
                // Select all elements
                // Get the current document and database
                Document acDoc   = acApp.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;

                // Start a transaction
                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    // Create a TypedValue array to define the filter criteria
                    TypedValue[] filterlist = new TypedValue[1];
                    filterlist[0] = new TypedValue(8, "!CFAST*");
                    SelectionFilter filter = new SelectionFilter(filterlist);

                    // Request for objects to be selected in the drawing area
                    PromptSelectionResult acSSPrompt;
                    acSSPrompt = ed.SelectAll(filter);

                    // If the prompt status is OK, objects were selected
                    if (acSSPrompt.Status == PromptStatus.OK)
                    {
                        SelectionSet acSSet = acSSPrompt.Value;

                        // Create dictionary with floors
                        foreach (SelectedObject acSSObj in acSSet)
                        {
                            // Check to make sure a valid SelectedObject object was returned
                            if (acSSObj != null)
                            {
                                // Open the selected object for write
                                Entity acEnt = acTrans.GetObject(acSSObj.ObjectId,
                                                                 OpenMode.ForRead) as Entity;
                                // Get current floor from current layer name
                                Regex regEx = new Regex(@"\((.)\)", RegexOptions.IgnoreCase);
                                Match match = regEx.Match(acEnt.Layer.ToString());
                                if (match.Success)
                                {
                                    System.Text.RegularExpressions.Group group = match.Groups[1];
                                    if (!Cfast.ContainsKey(group.ToString()))
                                    {
                                        Cfast.Add(group.ToString(), null);
                                    }
                                }
                            }
                        }

                        // Foreach floor add object
                        foreach (var floor in Cfast.Keys.ToList())
                        {
                            CfastObject cfastObject = new CfastObject
                            {
                                ROOM = new List <Object>(),
                                HOLE = new List <Object>(),
                                COR  = new List <Object>(),
                                STAI = new List <Object>(),
                                HALL = new List <Object>(),
                                D    = new List <Object>(),
                                E    = new List <Object>(),
                                C    = new List <Object>(),
                                I    = new List <Object>(),
                                W    = new List <Object>(),
                                VNT  = new List <Object>()
                            };

                            foreach (SelectedObject acSSObj in acSSet)
                            {
                                // Check to make sure a valid SelectedObject object was returned
                                if (acSSObj != null)
                                {
                                    // Open the selected object for write
                                    Entity acEnt = acTrans.GetObject(acSSObj.ObjectId,
                                                                     OpenMode.ForRead) as Entity;
                                    // Get current floor from current layer name
                                    Regex regEx = new Regex(@"\((.)\)", RegexOptions.IgnoreCase);
                                    Match match = regEx.Match(acEnt.Layer.ToString());
                                    if (match.Success)
                                    {
                                        // If current object layer name is the same floor -> OK, than skip object
                                        System.Text.RegularExpressions.Group group = match.Groups[1];
                                        if (group.ToString() != floor)
                                        {
                                            continue;
                                        }

                                        // If-else depending on layer name / cfast object type
                                        if (acEnt.Layer.ToString().Contains("room".ToUpper()))
                                        {
                                            try
                                            {
                                                double[] min = GetMin(acEnt);
                                                double[] max = GetMax(acEnt);
                                                cfastObject.ROOM.Add(new List <Object> {
                                                    min, max
                                                });
                                            }
                                            catch (System.Exception e)
                                            {
                                                ed.WriteMessage(e.ToString());
                                            }
                                        }
                                        else if (acEnt.Layer.ToString().Contains("hole".ToUpper()))
                                        {
                                            try
                                            {
                                                double[] min = GetMin(acEnt);
                                                double[] max = GetMax(acEnt);
                                                cfastObject.HOLE.Add(new List <Object> {
                                                    min, max
                                                });
                                            }
                                            catch (System.Exception e)
                                            {
                                                ed.WriteMessage(e.ToString());
                                            }
                                        }
                                        else if (acEnt.Layer.ToString().Contains("corridor".ToUpper()))
                                        {
                                            try
                                            {
                                                double[] min = GetMin(acEnt);
                                                double[] max = GetMax(acEnt);
                                                cfastObject.COR.Add(new List <Object> {
                                                    min, max
                                                });
                                            }
                                            catch (System.Exception e)
                                            {
                                                ed.WriteMessage(e.ToString());
                                            }
                                        }
                                        else if (acEnt.Layer.ToString().Contains("dplain".ToUpper()))
                                        {
                                            try
                                            {
                                                double[] min = GetMin(acEnt);
                                                double[] max = GetMax(acEnt);
                                                cfastObject.D.Add(new List <Object> {
                                                    min, max
                                                });
                                            }
                                            catch (System.Exception e)
                                            {
                                                ed.WriteMessage(e.ToString());
                                            }
                                        }
                                        else if (acEnt.Layer.ToString().Contains("dcloser".ToUpper()))
                                        {
                                            try
                                            {
                                                double[] min = GetMin(acEnt);
                                                double[] max = GetMax(acEnt);
                                                cfastObject.C.Add(new List <Object> {
                                                    min, max
                                                });
                                            }
                                            catch (System.Exception e)
                                            {
                                                ed.WriteMessage(e.ToString());
                                            }
                                        }
                                        else if (acEnt.Layer.ToString().Contains("delectric".ToUpper()))
                                        {
                                            try
                                            {
                                                double[] min = GetMin(acEnt);
                                                double[] max = GetMax(acEnt);
                                                cfastObject.E.Add(new List <Object> {
                                                    min, max
                                                });
                                            }
                                            catch (System.Exception e)
                                            {
                                                ed.WriteMessage(e.ToString());
                                            }
                                        }
                                        else if (acEnt.Layer.ToString().Contains("inlet".ToUpper()))
                                        {
                                            try
                                            {
                                                double[] min = GetMin(acEnt);
                                                double[] max = GetMax(acEnt);
                                                cfastObject.I.Add(new List <Object> {
                                                    min, max
                                                });
                                            }
                                            catch (System.Exception e)
                                            {
                                                ed.WriteMessage(e.ToString());
                                            }
                                        }
                                        else if (acEnt.Layer.ToString().Contains("window".ToUpper()))
                                        {
                                            try
                                            {
                                                double[] min = GetMin(acEnt);
                                                double[] max = GetMax(acEnt);
                                                cfastObject.W.Add(new List <Object> {
                                                    min, max
                                                });
                                            }
                                            catch (System.Exception e)
                                            {
                                                ed.WriteMessage(e.ToString());
                                            }
                                        }
                                        else if (acEnt.Layer.ToString().Contains("vvent".ToUpper()))
                                        {
                                            try
                                            {
                                                double[] min = GetMin(acEnt);
                                                double[] max = GetMax(acEnt);
                                                cfastObject.VNT.Add(new List <Object> {
                                                    min, max
                                                });
                                            }
                                            catch (System.Exception e)
                                            {
                                                ed.WriteMessage(e.ToString());
                                            }
                                        }
                                        else if (acEnt.Layer.ToString().Contains("staircase".ToUpper()))
                                        {
                                            try
                                            {
                                                double[] min = GetMin(acEnt);
                                                double[] max = GetMax(acEnt);
                                                cfastObject.STAI.Add(new List <Object> {
                                                    min, max
                                                });
                                            }
                                            catch (System.Exception e)
                                            {
                                                ed.WriteMessage(e.ToString());
                                            }
                                        }
                                        else if (acEnt.Layer.ToString().Contains("hall".ToUpper()))
                                        {
                                            try
                                            {
                                                double[] min = GetMin(acEnt);
                                                double[] max = GetMax(acEnt);
                                                cfastObject.HALL.Add(new List <Object> {
                                                    min, max
                                                });
                                            }
                                            catch (System.Exception e)
                                            {
                                                ed.WriteMessage(e.ToString());
                                            }
                                        }
                                    }
                                }

                                Cfast[floor] = cfastObject;
                            }
                        }
                    }
                    // Dispose of the transaction

                    //ed.WriteMessage(JsonConvert.SerializeObject(cfastObject, Formatting.Indented).ToString());
                }
            }
            catch (System.Exception e)
            {
                ed.WriteMessage(e.ToString());
            }

            /*
             * // Set a variable to the My Documents path.
             * string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
             *
             * var psfo = new PromptSaveFileOptions("Export Json file");
             * psfo.Filter = "Json (*.json)|*.json";
             * var pr = ed.GetFileNameForSave(psfo);
             *
             * if (pr.Status != PromptStatus.OK)
             *  return;
             *
             * var json = pr.StringResult;
             *
             * // Append text to an existing file named "WriteLines.txt".
             * using (StreamWriter outputFile = new StreamWriter(json))
             * {
             *  string jsonF = JsonConvert.SerializeObject(Cfast, Formatting.Indented);
             *  outputFile.WriteLine(jsonF);
             * }
             */

            try
            {
                ed.WriteMessage("\nSending CFAST objects ...");
                acWebSocketMessage message = new acWebSocketMessage("success", "cExport", JsonConvert.SerializeObject(Cfast), null);
                ed.WriteMessage("\nMessageId: " + message.getId());

                acWebSocketMessage answer = acWebSocketCtrl.syncCtrl.sendMessageAndWaitSync(message);
            }
            catch (System.Exception e)
            {
                ed.WriteMessage("\nWizFDS exception:\n" + e.ToString());
            }
        }
Ejemplo n.º 12
0
        public void fShowLevel()
        {
            Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                // Get the current document and database, and start a transaction
                Document acDoc   = Application.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;

                while (true)
                {
                    PromptDoubleOptions levelO = new PromptDoubleOptions("\nEnter level number:");
                    levelO.DefaultValue = 0;
                    PromptDoubleResult level = ed.GetDouble(levelO);
                    if (level.Status != PromptStatus.OK || level.Status == PromptStatus.Cancel)
                    {
                        goto End;
                    }
                    if (level.Status == PromptStatus.OK)
                    {
                        using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                        {
                            // This example returns the layer table for the current database
                            LayerTable acLyrTbl;
                            acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
                                                         OpenMode.ForRead) as LayerTable;

                            // Step through the Layer table and print each layer name
                            foreach (ObjectId acObjId in acLyrTbl)
                            {
                                LayerTableRecord acLyrTblRec;
                                acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite) as LayerTableRecord;

                                if (acLyrTblRec.Name.Contains("!FDS_") && acLyrTblRec.Name.Contains("("))
                                {
                                    Regex regEx = new Regex(@"\((.+)\)", RegexOptions.IgnoreCase);
                                    Match match = regEx.Match(acLyrTblRec.Name);
                                    if (match.Success)
                                    {
                                        double levelLayer;
                                        System.Text.RegularExpressions.Group group = match.Groups[1];
                                        Double.TryParse(group.ToString(), out levelLayer);

                                        if (level.Value == levelLayer)
                                        {
                                            acLyrTblRec.IsOff = false;
                                        }
                                    }
                                }
                            }
                            acTrans.Commit();
                        }
                    }
                }
                End :;
                return;
            }
            catch (System.Exception e)
            {
                ed.WriteMessage("\nProgram exception: " + e.ToString());
                return;
            }
        }
Ejemplo n.º 13
0
        public void fCreateLevel()
        {
            Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;

            try
            {
                // Get the current document and database, and start a transaction
                Document acDoc   = Application.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;

                PromptDoubleOptions levelO = new PromptDoubleOptions("\nEnter level number:");
                levelO.DefaultValue = 0;
                PromptDoubleResult level = ed.GetDouble(levelO);

                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    // This example returns the layer table for the current database
                    LayerTable acLyrTbl;
                    acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
                                                 OpenMode.ForWrite) as LayerTable;

                    // Step through the Layer table and print each layer name
                    foreach (ObjectId acObjId in acLyrTbl)
                    {
                        LayerTableRecord acLyrTblRec;
                        acLyrTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite) as LayerTableRecord;

                        if (acLyrTblRec.Name.Contains("!FDS_") && acLyrTblRec.Name.Contains("("))
                        {
                            // Tutaj dodaj nowa warstwe ...

                            Regex regEx = new Regex(@"(.+)\(", RegexOptions.IgnoreCase);
                            Match match = regEx.Match(acLyrTblRec.Name);
                            if (match.Success)
                            {
                                System.Text.RegularExpressions.Group group = match.Groups[1];

                                LayerTableRecord acLyrTblRecNew = new LayerTableRecord();

                                // Assign the layer the ACI color 1 and a name
                                acLyrTblRecNew.Name  = group.ToString() + "(" + level.Value.ToString() + ")";
                                acLyrTblRecNew.Color = acLyrTblRec.Color;

                                // Append the new layer to the Layer table and the transaction
                                if (!acLyrTbl.Has(acLyrTblRecNew.Name))
                                {
                                    acLyrTbl.Add(acLyrTblRecNew);
                                    acTrans.AddNewlyCreatedDBObject(acLyrTblRecNew, true);
                                }
                            }

                            //acLyrTblRec.IsOff = true;
                        }
                    }
                    acTrans.Commit();
                }
                return;
            }
            catch (System.Exception e)
            {
                ed.WriteMessage("\nProgram exception: " + e.ToString());
                return;
            }
        }