Jak vytvořit obdélník jako lomenou čáru a vyplnit ho vzorkem
Contents
[
Hide
]Jak vytvořit obdélník jako lomenou čáru a vyplnit ho vzorkem
Problém: Jak vytvořit obdélník jako lomenou čáru a vyplnit ho vzorkem (CADNET-1351).
Tipy: Pro provedení tohoto úkolu vytvořte CadLwPolyline a přidejte do ní souřadnice bodů, použijte CadHatch k práci s barvou a použijte CadEdgeBoundaryPath k propojení, využijte CadHatch k práci s úhly a CadHatchPatternData pro vzor.
Příklad:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CadLwPolyline polyline = new CadLwPolyline(); | |
polyline.Coordinates = new List<Cad2DPoint>(); | |
polyline.Coordinates.Add(new Cad2DPoint(-5d, -5d)); | |
polyline.Coordinates.Add(new Cad2DPoint(-5d, 10d)); | |
polyline.Coordinates.Add(new Cad2DPoint(20d, 10d)); | |
polyline.Coordinates.Add(new Cad2DPoint(20d, -5d)); | |
polyline.Flag = CadLwPolylineFlag.Closed; | |
polyline.ConstantWidth = 0.1; | |
CadHatch hatch = new CadHatch(); | |
hatch.PatternName = "SOLID"; | |
hatch.ColorId = 1; // index of color: https://gohtx.com/acadcolors.php | |
hatch.HatchPatternType = 1; // 0 = User-defined; 1 = Predefined; 2 = Custom, we support only predefined now | |
hatch.BoundaryPaths = new List<CadHatchBoundaryPathContainer>(); | |
CadHatchBoundaryPathContainer container = new CadHatchBoundaryPathContainer(); | |
container.BoundaryPath = new List<ICadBoundaryPath>(); | |
CadEdgeBoundaryPath path = new CadEdgeBoundaryPath(); | |
path.Objects = new List<ICadBoundaryPathEntity>(); | |
path.Objects.Add(new CadBoundaryPathLine() { FirstPoint = new Point2D(-5, -5), SecondPoint = new Point2D(-5, 10) }); | |
path.Objects.Add(new CadBoundaryPathLine() { FirstPoint = new Point2D(-5, 10), SecondPoint = new Point2D(20, 10) }); | |
path.Objects.Add(new CadBoundaryPathLine() { FirstPoint = new Point2D(20, 10), SecondPoint = new Point2D(20, -5) }); | |
path.Objects.Add(new CadBoundaryPathLine() { FirstPoint = new Point2D(20, -5), SecondPoint = new Point2D(-5, -5) }); | |
container.BoundaryPath.Add(path); | |
hatch.BoundaryPaths.Add(container); | |
List<CadBaseEntity> entities = new List<CadBaseEntity>(); | |
entities.Add(polyline); | |
entities.Add(hatch); | |
cadImage.Entities = entities.ToArray(); | |
cadImage.UpdateSize(); | |
CadHatch hatch = new CadHatch(); | |
hatch.PatternName = "ANGLE"; // only known values are available here | |
hatch.ColorId = 1; | |
hatch.HatchPatternType = 1; // | |
hatch.BoundaryPaths = new List<CadHatchBoundaryPathContainer>(); | |
CadHatchBoundaryPathContainer container = new CadHatchBoundaryPathContainer(); | |
container.BoundaryPath = new List<ICadBoundaryPath>(); | |
CadEdgeBoundaryPath path = new CadEdgeBoundaryPath(); | |
path.Objects = new List<ICadBoundaryPathEntity>(); | |
path.Objects.Add(new CadBoundaryPathLine(){FirstPoint = new Point2D(-5, -5), SecondPoint = new Point2D(-5,10)}); | |
path.Objects.Add(new CadBoundaryPathLine() { FirstPoint = new Point2D(-5, 10), SecondPoint = new Point2D(20, 10) }); | |
path.Objects.Add(new CadBoundaryPathLine() { FirstPoint = new Point2D(20, 10), SecondPoint = new Point2D(20, -5) }); | |
path.Objects.Add(new CadBoundaryPathLine() { FirstPoint = new Point2D(20, -5), SecondPoint = new Point2D(-5, -5) }); | |
container.BoundaryPath.Add(path); | |
hatch.BoundaryPaths.Add(container); | |
hatch.PatternDefinitions = new List<CadHatchPatternData>(); | |
CadHatchPatternData data1 = new CadHatchPatternData(); | |
data1.LineBasePoint = new Cad3DPoint(); | |
data1.DashLengths = new List<double>(); | |
data1.DashLengths.Add(4); | |
data1.DashLengths.Add(1.5); | |
data1.DashLengthCount = (short)data1.DashLengths.Count; | |
data1.LineOffset = new Cad2DPoint(0d, 5.5d); | |
CadHatchPatternData data2 = new CadHatchPatternData(); | |
data2.LineBasePoint = new Cad3DPoint(); | |
data2.DashLengths = new List<double>(); | |
data2.DashLengths.Add(4); | |
data2.DashLengths.Add(-1.5); | |
data2.LineAngle = 90; | |
data2.DashLengthCount = (short)data2.DashLengths.Count; | |
data2.LineOffset = new Cad2DPoint(-5.5d, 0d); | |
hatch.PatternDefinitions.Add(data1); | |
hatch.PatternDefinitions.Add(data2); | |
hatch.NumberOfPatternDefinitions = (short)hatch.PatternDefinitions.Count; | |
List<CadBaseEntity> entities = new List<CadBaseEntity>(); | |
entities.Add(polyline); | |
entities.Add(hatch); | |
cadImage.Entities = entities.ToArray(); | |
cadImage.UpdateSize(); |