/// <summary>
        /// Create a complex fillpattern element
        /// </summary>
        /// <param name="patternName">The fillpattern name</param>
        /// <returns>Created fillpattern element</returns>
        private FillPatternElement GetOrCreateComplexFacePattern(string patternName)
        {
            FillPatternTarget  target             = FillPatternTarget.Model;
            FillPatternElement fillPatternElement = FillPatternElement.GetFillPatternElementByName(doc, target, patternName);

            if (fillPatternElement == null)
            {
                // Create the fill pattern
                FillPattern fillPattern = new FillPattern(patternName, target,
                                                          FillPatternHostOrientation.ToHost);

                // Add grids
                List <FillGrid> grids = new List <FillGrid>();

                //Horizontal lines.
                grids.Add(CreateGrid(new UV(0, 0.1), 0.5, 0, 0.55, 1.0, 0.1));
                grids.Add(CreateGrid(new UV(0, 0.5), 0.5, 0, 0.55, 1.0, 0.1));

                // Vertical lines.
                grids.Add(CreateGrid(new UV(0, 0.1), 0.55, Math.PI / 2, 0.5, 0.4, 0.6));
                grids.Add(CreateGrid(new UV(1.0, 0.1), 0.55, Math.PI / 2, 0.5, 0.4, 0.6));

                fillPattern.SetFillGrids(grids);

                // Create the fill pattern element. Now document is modified; transaction is needed
                Transaction t = new Transaction(doc, "Create fill pattern");
                t.Start();
                fillPatternElement = FillPatternElement.Create(doc, fillPattern);

                t.Commit();
            }

            return(fillPatternElement);
        }
        /// <summary>
        /// Create a fillpattern element
        /// </summary>
        /// <param name="patternName">The fillpattern name</param>
        /// <returns>Created fillpattern element</returns>
        private FillPatternElement GetOrCreateFacePattern(string patternName)
        {
            FillPatternTarget  target             = FillPatternTarget.Model;
            FillPatternElement fillPatternElement = FillPatternElement.GetFillPatternElementByName(doc, target, patternName);

            if (fillPatternElement == null)
            {
                //Create a fillpattern with specified angle and spacing
                FillPattern fillPattern = new FillPattern(patternName, target,
                                                          FillPatternHostOrientation.ToView, 0.5, 0.5, 0.5);

                Transaction trans = new Transaction(doc);
                trans.Start("Create a fillpattern element");
                fillPatternElement = FillPatternElement.Create(doc, fillPattern);
                trans.Commit();
            }
            return(fillPatternElement);
        }