Ejemplo n.º 1
0
        public void ChangeAlignmentLabelStyle()
        {
            PromptEntityOptions options = new PromptEntityOptions("\nSelect Alignment: ");

            options.SetRejectMessage("\nThe selected object is not a Alignment!");
            options.AddAllowedClass(typeof(Alignment), false);
            PromptEntityResult pres = Active.Editor.GetEntity(options);

            if (pres.Status != PromptStatus.OK)
            {
                return;
            }

            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                try
                {
                    Alignment align = (Alignment)tr.GetObject(pres.ObjectId, OpenMode.ForRead);
                    //ObjectIdCollection ids = align.GetAlignmentLabelIds();
                    ObjectIdCollection ids = align.GetAlignmentLabelGroupIds();
                    foreach (ObjectId id in ids)
                    {
                        AlignmentLabelGroup style = (AlignmentLabelGroup)tr.GetObject(id, OpenMode.ForRead);
                        Active.Editor.WriteMessage("\n " + style.ToString());
                        //result:
                        //Autodesk.Civil.DatabaseServices.AlignmentDesignSpeedLabelGroup
                        //Autodesk.Civil.DatabaseServices.AlignmentGeometryPointLabelGroup
                        //Autodesk.Civil.DatabaseServices.AlignmentMinorStationLabelGroup
                        //Autodesk.Civil.DatabaseServices.AlignmentStationEquationLabelGroup
                        //Autodesk.Civil.DatabaseServices.AlignmentStationLabelGroup

                        //LabelType lblType = (LabelType)tr.GetObject(style.ObjectId, OpenMode.ForRead);     //Autodesk.Civil.DatabaseServices.LabelType
                        //LabelStylesAlignmentRoot root = (LabelStylesRoot)tr.GetObject(id, OpenMode.ForRead);
                    }

                    //Active.Editor.WriteMessage("\nAlignment Curve Label Style Name (before Change) : " + alignLabelStyle.Name);

                    //// The following Style Name is specific to Tutorial DWG file - "Labels-6a.dwg"
                    //alignLabelStyle.Name = "Design Data";
                    //Active.Editor.WriteMessage("\nAlignment Curve Label Style Name (after Change) : " + alignLabelStyle.Name);

                    tr.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception ex)
                {
                    Active.Editor.WriteMessage("\n Exception message :" + ex.Message);
                }
            }
        }