转帖:获取样式名称


原贴链接

第 1 条消息(共 2 条) Arun.Thiriyat Participant Arun.Thiriyat 24 次查看, 1 条回复 14 小时之前     Profile Style Collection C#

Is there any way to get profile styles in the current dwg.

I want to list the styles.

ObjectId styleId = doc.Styles.ProfileStyles[0];
ObjectId labelSetId = doc.Styles.LabelSetStyles.ProfileLabelSetStyles[0];

Above code only gets 1st style.

Is there any way same like this below?

oAlignments = doc.GetAlignmentIds();





第 2 条消息(共 2 条) Jeff_M Mentor 回复: Arun.Thiriyat 9 小时之前      

This is an extension method to get the names of any StyleCollection:

        public static List StyleCollectionNames(this StyleCollectionBase scb)
        {
            var list = new List();
            foreach(ObjectId id in scb)
            {
                var style = (StyleBase)id.Open(OpenMode.ForRead);
                list.Add(style.Name);
                style.Close();
            }
            return list;
        }

and sample usage:

        var stylelist = CivilApplication.ActiveDocument.Styles.ProfileStyles.StyleCollectionNames();
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nThe first name in the list is {0}", stylelist[0]);
        var setslist = CivilApplication.ActiveDocument.Styles.LabelSetStyles.ProfileLabelSetStyles.StyleCollectionNames();
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nThe first name in the list is {0}", setslist[0]);

相关