public static void ImportPattern(this Document doc, string name, List <string> lines)
        {
            using (Transaction t = new Transaction(doc, "Create Grids"))
            {
                t.Start();
                List <FillGrid> grids = new List <FillGrid>();
                FillPattern     pat   = new FillPattern(name, FillPatternTarget.Model, FillPatternHostOrientation.ToHost);
                foreach (string line in lines)
                {
                    FillGrid grid = new FillGrid();
                    grid.Angle  = double.Parse(line.Split(',')[0]) * Math.PI / 180;
                    grid.Origin = new UV(double.Parse(line.Split(',')[1]) / 12, double.Parse(line.Split(',')[2]) / 12);
                    grid.Shift  = double.Parse(line.Split(',')[3]) / 12;
                    grid.Offset = double.Parse(line.Split(',')[4]) / 12;
                    var segments = new List <double>();
                    segments.Add(Math.Abs(double.Parse(line.Split(',')[5])) / 12);
                    segments.Add(Math.Abs(double.Parse(line.Split(',')[6])) / 12);
                    grid.SetSegments(segments);
                    grids.Add(grid);
                }

                pat.SetFillGrids(grids);
                FillPatternElement fpe = FillPatternElement.Create(doc, pat);
                t.Commit();
            }
        }
        /// <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);
        }
Beispiel #3
0
        private bool AssignFillGridsFromString(string[] grids, double scale, double rotationAngle)
        {
            var newFillGrids = new List <FillGrid>();

            foreach (string s in grids)
            {
                if (string.IsNullOrEmpty(s.Trim()))
                {
                    continue;
                }
                string[] segs = s.Split(',');
                if (segs.Count() < 5)
                {
                    return(false);
                }
                var           f        = new FillGrid();
                List <double> lineSegs = new List <double>();
                if (!double.TryParse(segs[0], out var angle))
                {
                    return(false);
                }
                if (!double.TryParse(segs[1], out var x))
                {
                    return(false);
                }
                if (!double.TryParse(segs[2], out var y))
                {
                    return(false);
                }
                if (!double.TryParse(segs[3], out var shift))
                {
                    return(false);
                }
                if (!double.TryParse(segs[4], out var offset))
                {
                    return(false);
                }
                for (int i = 5; i < segs.Length; i++)
                {
                    if (!double.TryParse(segs[i], out var individualSeg))
                    {
                        return(false);
                    }
                    individualSeg *= scale;
                    lineSegs.Add(Math.Abs(individualSeg.ToFeet()));
                }
                x       *= scale;
                y       *= scale;
                shift   *= scale;
                offset  *= scale;
                angle   += rotationAngle;
                f.Angle  = angle.ToRad();
                f.Origin = new UV(x.ToFeet(), y.ToFeet());
                f.Shift  = shift.ToFeet();
                f.Offset = offset.ToFeet();
                f.SetSegments(lineSegs);
                newFillGrids.Add(f);
            }
            fillPattern.SetFillGrids(newFillGrids);
            return(true);
        }