/// <summary> /// Intitializes a new instance of the <c>Attribute</c> class. /// </summary> /// <param name="definition"><see cref="AttributeDefinition">Attribute definition</see>.</param> /// <param name="value">Attribute value.</param> public Attribute(AttributeDefinition definition, object value) : base(DxfObjectCode.Attribute) { this.definition = definition; this.value = value; this.color = definition.Color; this.layer = definition.Layer; this.lineType = definition.LineType; }
private static void BlockAttributes() { DxfDocument dxf = new DxfDocument( ); Block block = new Block("BlockWithAttributes"); block.Layer = new Layer("BlockSample"); AttributeDefinition attdef = new AttributeDefinition("NewAttribute"); attdef.Text = "InfoText"; attdef.BasePoint = new Vector3f(1, 1, 1); attdef.Style.IsVertical = true; attdef.Rotation = 45; block.Attributes.Add(attdef.Id, attdef); block.Entities.Add(new Line(new Vector3f(-5, -5, 0), new Vector3f(5, 5, 0))); block.Entities.Add(new Line(new Vector3f(5, -5, 0), new Vector3f(-5, 5, 0))); Insert insert = new Insert(block, new Vector3f(5, 5, 5)); insert.Layer = new Layer("insert"); insert.Rotation = 45; insert.Layer.Color.Index = 4; insert.Attributes[0].Value = 24; Insert insert2 = new Insert(block, new Vector3f(-5, -5, -5)); insert2.Attributes[0].Value = 34; XData xdata1 = new XData(new ApplicationRegistry("SharpDxf")); xdata1.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with SharpDxf")); xdata1.XDataRecord.Add(XDataRecord.OpenControlString); xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0)); xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0)); xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0)); xdata1.XDataRecord.Add(XDataRecord.CloseControlString); XData xdata2 = new XData(new ApplicationRegistry("other application")); xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with SharpDxf")); xdata2.XDataRecord.Add(XDataRecord.OpenControlString); xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record")); xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5)); xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Long, 350)); xdata2.XDataRecord.Add(XDataRecord.CloseControlString); insert.XData = new Dictionary<ApplicationRegistry, XData> { {xdata1.ApplicationRegistry, xdata1}, }; dxf.AddEntity(insert); dxf.AddEntity(insert2); Circle circle = new Circle(Vector3f.Zero, 5); circle.Layer = new Layer("circle"); circle.Layer.Color.Index = 2; circle.XData = new Dictionary<ApplicationRegistry, XData> { {xdata2.ApplicationRegistry, xdata2}, }; dxf.AddEntity(circle); dxf.Save("Block with attributes.dxf", DxfVersion.AutoCad2000); dxf.Load("Block with attributes.dxf"); dxf.Save("Block with attributes result.dxf", DxfVersion.AutoCad2000); // both results must be equal only the handles might be different }
private void WriteAttributeDefinition(AttributeDefinition def) { this.WriteCodePair(0, DxfObjectCode.AttributeDefinition); this.WriteCodePair(5, def.Handle); this.WriteCodePair(100, SubclassMarker.Entity); this.WriteEntityCommonCodes(def); this.WriteCodePair(100, SubclassMarker.Text); this.WriteCodePair(10, def.BasePoint.X); this.WriteCodePair(20, def.BasePoint.Y); this.WriteCodePair(30, def.BasePoint.Z); this.WriteCodePair(40, def.Height); this.WriteCodePair(1, def.Value); this.WriteCodePair(7, def.Style); this.WriteCodePair(41, def.WidthFactor); this.WriteCodePair(50, def.Rotation); this.WriteCodePair(100, SubclassMarker.AttributeDefinition); this.WriteCodePair(2, def.Id); this.WriteCodePair(3, def.Text); this.WriteCodePair(70, (int) def.Flags); switch (def.Alignment) { case TextAlignment.TopLeft: this.WriteCodePair(72, 0); this.WriteCodePair(74, 3); break; case TextAlignment.TopCenter: this.WriteCodePair(72, 1); this.WriteCodePair(74, 3); break; case TextAlignment.TopRight: this.WriteCodePair(72, 2); this.WriteCodePair(74, 3); break; case TextAlignment.MiddleLeft: this.WriteCodePair(72, 0); this.WriteCodePair(74, 2); break; case TextAlignment.MiddleCenter: this.WriteCodePair(72, 1); this.WriteCodePair(74, 2); break; case TextAlignment.MiddleRight: this.WriteCodePair(72, 2); this.WriteCodePair(74, 2); break; case TextAlignment.BottomLeft: this.WriteCodePair(72, 0); this.WriteCodePair(74, 1); break; case TextAlignment.BottomCenter: this.WriteCodePair(72, 1); this.WriteCodePair(74, 1); break; case TextAlignment.BottomRight: this.WriteCodePair(72, 2); this.WriteCodePair(74, 1); break; case TextAlignment.BaselineLeft: this.WriteCodePair(72, 0); this.WriteCodePair(74, 0); break; case TextAlignment.BaselineCenter: this.WriteCodePair(72, 1); this.WriteCodePair(74, 0); break; case TextAlignment.BaselineRight: this.WriteCodePair(72, 2); this.WriteCodePair(74, 0); break; } this.WriteCodePair(11, def.BasePoint.X); this.WriteCodePair(21, def.BasePoint.Y); this.WriteCodePair(31, def.BasePoint.Z); }