/// <summary> /// Initializes a new instance of the <c>DxfDocument</c> class. /// </summary> /// <param name="drawingVariables"><see cref="HeaderVariables">Drawing variables</see> of the document.</param> public DxfDocument(HeaderVariables drawingVariables) : this(drawingVariables, true) { }
/// <summary> /// Initializes a new instance of the <c>DxfDocument</c> class. /// </summary> /// <param name="drawingVariables"><see cref="HeaderVariables">Drawing variables</see> of the document.</param> /// <param name="createDefaultObjects">Check if the default objects need to be created.</param> internal DxfDocument(HeaderVariables drawingVariables, bool createDefaultObjects) : base("DOCUMENT") { this.comments = new List<string> {"Dxf file generated by netDxf https://netdxf.codeplex.com, Copyright(C) 2009-2016 Daniel Carvajal, Licensed under LGPL"}; this.Owner = null; this.drawingVariables = drawingVariables; this.NumHandles = this.AsignHandle(0); this.DimensionBlocksGenerated = 0; this.GroupNamesGenerated = 0; this.AddedObjects = new Dictionary<string, DxfObject> { {this.Handle, this} }; // keeps track of the added objects this.activeLayout = Layout.ModelSpaceName; // entities lists this.arcs = new List<Arc>(); this.ellipses = new List<Ellipse>(); this.dimensions = new List<Dimension>(); this.faces3d = new List<Face3d>(); this.solids = new List<Solid>(); this.traces = new List<Trace>(); this.inserts = new List<Insert>(); this.lwPolylines = new List<LwPolyline>(); this.polylines = new List<Polyline>(); this.polyfaceMeshes = new List<PolyfaceMesh>(); this.lines = new List<Line>(); this.circles = new List<Circle>(); this.points = new List<Point>(); this.texts = new List<Text>(); this.mTexts = new List<MText>(); this.hatches = new List<Hatch>(); this.splines = new List<Spline>(); this.images = new List<Image>(); this.mLines = new List<MLine>(); this.rays = new List<Ray>(); this.xlines = new List<XLine>(); this.viewports = new List<Viewport>(); this.meshes = new List<Mesh>(); this.leaders = new List<Leader>(); this.tolerances = new List<Tolerance>(); this.underlays = new List<Underlay>(); this.wipeouts = new List<Wipeout>(); this.attributeDefinitions = new List<AttributeDefinition>(); if (createDefaultObjects) this.AddDefaultObjects(); }
private static void AddAndRemove() { Layer layer1 = new Layer("layer1") { Color = AciColor.Blue }; Layer layer2 = new Layer("layer2") { Color = AciColor.Green }; Line line = new Line(new Vector2(0, 0), new Vector2(10, 10)); line.Layer = layer1; Circle circle = new Circle(new Vector2(0, 0), 10); circle.Layer = layer2; double offset = -0.9; Vector3 p1 = new Vector3(1, 2, 0); Vector3 p2 = new Vector3(2, 6, 0); Line line1 = new Line(p1, p2); Vector3 l1; Vector3 l2; MathHelper.OffsetLine(line1.StartPoint, line1.EndPoint, line1.Normal, offset, out l1, out l2); DimensionStyle myStyle = new DimensionStyle("MyDimStyle"); myStyle.DIMPOST = "<>mm"; AlignedDimension dim1 = new AlignedDimension(p1, p2, offset, myStyle); //text TextStyle style = new TextStyle("MyTextStyle", "Arial.ttf"); Text text = new Text("Hello world!", Vector3.Zero, 10.0f, style) { Layer = new Layer("text") { Color = {Index = 8} } }; text.Alignment = TextAlignment.TopRight; HeaderVariables variables = new HeaderVariables { AcadVer = DxfVersion.AutoCad2004 }; DxfDocument dxf = new DxfDocument(); dxf.AddEntity(new EntityObject[] {line, circle, dim1, text}); dxf.Save("before remove.dxf"); dxf.RemoveEntity(circle); dxf.Save("after remove.dxf"); dxf.AddEntity(circle); dxf.Save("after remove and add.dxf"); dxf.RemoveEntity(dim1); dxf.Save("remove dim.dxf"); dxf.AddEntity(dim1); dxf.Save("add dim.dxf"); DxfDocument dxf2 = DxfDocument.Load("dim block names.dxf"); dxf2.AddEntity(dim1); dxf2.Save("dim block names2.dxf"); }