コード例 #1
0
        public void CreateStyles()
        {
            DrawingDocument oDoc = (DrawingDocument)_InvApplication.ActiveDocument;


            //get Drawing Styles Manager
            DrawingStylesManager oDStylesMan = default(DrawingStylesManager);

            oDStylesMan = oDoc.StylesManager;

            // create a new text style
            // by copying from an existing style
            //the new name is "MyNewTextStyle"
            TextStyle oNewTextStyle = default(TextStyle);

            oNewTextStyle = (TextStyle)oDStylesMan.TextStyles["Label Text (ANSI)"].Copy("MyNewTextStyle");

            // change some properties of the new style
            oNewTextStyle.FontSize *= 2;
            oNewTextStyle.Italic    = true;


            LeaderStyle oNewLeaderStyle = default(LeaderStyle);

            oNewLeaderStyle = (LeaderStyle)oDStylesMan.LeaderStyles[1].Copy("MyNewLeaderStyle");

            oNewLeaderStyle.Color       = _InvApplication.TransientObjects.CreateColor(255, 0, 0);
            oNewLeaderStyle.LineWeight *= 2;

            DrawingStandardStyle oNewDrawingStyle = default(DrawingStandardStyle);

            oNewDrawingStyle = (DrawingStandardStyle)oDStylesMan.StandardStyles[1].Copy("MyNewDSStyle");

            //change some general settings
            oNewDrawingStyle.LinearUnits = UnitsTypeEnum.kCentimeterLengthUnits;

            ObjectDefaultsStyle oNewObjDefaultStyle = default(ObjectDefaultsStyle);

            oNewObjDefaultStyle = (ObjectDefaultsStyle)oDStylesMan.ObjectDefaultsStyles[1].Copy("MyNewObjStyles");

            //change some properties
            // e.g. the border text style uses the MyNewTextStyle
            oNewObjDefaultStyle.BorderTextStyle = oNewTextStyle;

            //new standard style uses the new objects styles
            oNewDrawingStyle.ActiveObjectDefaults = oNewObjDefaultStyle;

            // the document uses the new DrawingStandardStyle
            oDStylesMan.ActiveStandardStyle = oNewDrawingStyle;
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Leaders    = new List <LeaderStyle>();
            TextStyles = new List <TextStyle>();
            //FontNames = new List<string>();
            Sizes = new List <double>();

            LeaderStyle leader = new LeaderStyle()
            {
                Name           = "ARROW (30°) FILLED",
                Style          = LeaderStyle.ArrowStyle.Arrow,
                Angle          = 30,
                Filled         = true,
                Size           = 3,
                HeavyEndWeight = 5
            };

            Leaders.Add(leader);

            TextStyle style = new TextStyle()
            {
                Name         = "test",
                Description  = "Bold",
                Background   = true,
                Bold         = true,
                Italic       = false,
                Underline    = false,
                Color        = System.Drawing.Color.Red,
                Leader       = leader,
                LeaderOffset = 1,
                LineWeight   = 1,
                TextBox      = false,
                TabSize      = 12,
                WidthFactor  = 1
            };

            TextStyles.Add(style);


            XmlDocument xdoc = Serialise();

            xdoc.Save(@"C:\Temp\test.xml");
        }
コード例 #3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication app = commandData.Application;
            UIDocument    doc = app.ActiveUIDocument;

            //List<string> fonts = Utils.TextUtilities.InstalledFonts();
            //System.Windows.Forms.MessageBox.Show(string.Format("I found {0} fonts.\nThe first one is: {1}",fonts.Count,fonts[0]));

            //<LeaderStyle Name="ARROW (30°) FILLED"
            //         ArrowStyle="8"
            //         Angle="30"
            //         Filled="1"
            //         Size="3"
            //         HeavyEndWeight="5" />
            LeaderStyle leader = new LeaderStyle()
            {
                Name           = "ARROW (30°) FILLED",
                Style          = LeaderStyle.ArrowStyle.Arrow,
                Angle          = 30,
                Filled         = true,
                Size           = 3,
                HeavyEndWeight = 5
            };

            //<Style Name=""
            //  Description="Bold"
            //  Background="1"
            //  Bold="1"
            //  Italic="0"
            //  Underline="0"
            //  Colour="0"
            //  Leader="ARROW (30°) FILLED"
            //  LeaderOffset="1.0"
            //  LineWeight="1"
            //  TextBox="0"
            //  TabSize="12.0"
            //  WidthFactor="1"
            //>
            TextStyle style = new TextStyle()
            {
                Name         = "test",
                Description  = "Bold",
                Background   = true,
                Bold         = true,
                Italic       = false,
                Underline    = false,
                Color        = System.Drawing.Color.Black,
                Leader       = leader,
                LeaderOffset = 1,
                LineWeight   = 1,
                TextBox      = false,
                TabSize      = 12,
                WidthFactor  = 1
            };

            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?><KRSP_Annotation_Styles />");

            XmlNode node = xdoc.DocumentElement;

            style.AddToXmlDoc(ref node);

            return(Result.Succeeded);
        }
コード例 #4
0
        private bool Deserialise(string pathToConfigXml, out string error)
        {
            FileInfo file = new FileInfo(pathToConfigXml);

            if (file.Exists)
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(file.FullName);

                XmlNodeList leaderStyles = xdoc.GetElementsByTagName("LeaderStyle");
                if (leaderStyles.Count == 0)
                {
                    error = string.Format("The config file at {0} does not contain any LeaderStyles.", pathToConfigXml);
                    return(false);
                }
                XmlNodeList sizes = xdoc.GetElementsByTagName("Size");
                if (sizes.Count == 0)
                {
                    error = string.Format("The config file at {0} does not contain any Sizes.", pathToConfigXml);
                    return(false);
                }
                XmlNodeList textStyles = xdoc.GetElementsByTagName("TextStyle");
                if (textStyles.Count == 0)
                {
                    error = string.Format("The config file at {0} does not contain any TextStyles.", pathToConfigXml);
                    return(false);
                }

                //at this point the xml file contains all relevant information
                //load sizes
                Sizes = new List <double>();
                foreach (XmlNode node in sizes)
                {
                    XmlAttribute att = node.Attributes["Value"];
                    if (att != null)
                    {
                        Sizes.Add(Convert.ToDouble(att.Value));
                    }
                }

                //load leaderStyles
                Leaders = new List <LeaderStyle>();
                foreach (XmlNode node in leaderStyles)
                {
                    //<LeaderStyle HeavyEndWeight="5" Size="3" Filled="1" Angle="30" ArrowStyle="8" Name="ARROW (30°) FILLED"/>
                    LeaderStyle  leader = new LeaderStyle();
                    XmlAttribute att    = node.Attributes["Name"];
                    leader.Name           = att.Value;
                    att                   = node.Attributes["ArrowStyle"];
                    leader.Style          = (LeaderStyle.ArrowStyle)(Convert.ToInt32(att.Value));
                    att                   = node.Attributes["Angle"];
                    leader.Angle          = Convert.ToInt32(att.Value);
                    att                   = node.Attributes["Filled"];
                    leader.Filled         = att.Value == "1";
                    att                   = node.Attributes["Size"];
                    leader.Size           = Convert.ToDouble(att.Value);
                    att                   = node.Attributes["HeavyEndWeight"];
                    leader.HeavyEndWeight = Convert.ToInt32(att.Value);

                    Leaders.Add(leader);
                }

                //load textStyles
                TextStyles = new List <TextStyle>();
                foreach (XmlNode node in textStyles)
                {
                    //<TextStyle Name="test" WidthFactor="1" TabSize="12" TextBox="0" LineWeight="1" LeaderOffset="1"
                    //Leader="ARROW (30°) FILLED" Color="255-000-000" Underline="0" Italic="0" Bold="1" Background="1" Description="Bold"/>
                    TextStyle    textStyle = new TextStyle();
                    XmlAttribute att       = node.Attributes["Name"];
                    textStyle.Name        = att.Value;
                    att                   = node.Attributes["Description"];
                    textStyle.Description = att.Value;
                    att                   = node.Attributes["Background"];
                    textStyle.Background  = att.Value == "1";
                    att                   = node.Attributes["Bold"];
                    textStyle.Bold        = att.Value == "1";
                    att                   = node.Attributes["Italic"];
                    textStyle.Italic      = att.Value == "1";
                    att                   = node.Attributes["Underline"];
                    textStyle.Underline   = att.Value == "1";
                    att                   = node.Attributes["Color"];
                    string[] colorStrings = att.Value.Split('-');
                    if (colorStrings.Length != 3)
                    {
                        error = string.Format("Invalid color string found in xml: {0}.\n{1}", att.Value, pathToConfigXml);
                        return(false);
                    }
                    Color color = Color.FromArgb(Convert.ToInt32(colorStrings[0]), Convert.ToInt32(colorStrings[1]), Convert.ToInt32(colorStrings[2]));
                    textStyle.Color        = color;
                    att                    = node.Attributes["Leader"];
                    textStyle.Leader       = LeaderStyle.getLeaderStyle(Leaders, att.Value);
                    att                    = node.Attributes["LeaderOffset"];
                    textStyle.LeaderOffset = Convert.ToDouble(att.Value);
                    att                    = node.Attributes["LineWeight"];
                    textStyle.LineWeight   = Convert.ToInt32(att.Value);
                    att                    = node.Attributes["TextBox"];
                    textStyle.TextBox      = att.Value == "1";
                    att                    = node.Attributes["TabSize"];
                    textStyle.TabSize      = Convert.ToDouble(att.Value);
                    att                    = node.Attributes["WidthFactor"];
                    textStyle.WidthFactor  = Convert.ToDouble(att.Value);

                    TextStyles.Add(textStyle);
                }

                error = "";
                return(true);
            }
            else
            {
                error = string.Format("Config file could not be found at: {0}", pathToConfigXml);
                return(false);
            }
        }