public void CreatElement(MapPoint _mapPoint)
{
//получаем ссылкe на документ
Document ad = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
if (ad == null) return;
//получаем ссылкe на БД
Database db = ad.Database;
//получаем ссылку на ALayer
ALayer mapLayer = new ALayer();
//начинаем транзакцию
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//
Point3d BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y, Point3d.Origin.Z);
//
Point3d InsPoint = new Point3d(_mapPoint.X, _mapPoint.Y, _mapPoint.Z);
//получаем ссылку на таблицу блоков
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
//создание определения блока
BlockTableRecord btr = new BlockTableRecord() { Name = ElementMap};
ObjectId idBlock = bt.Add(btr);
tr.AddNewlyCreatedDBObject(btr, true);
//Слой берегоукрепление
mapLayer.PreparationLayer();
mapLayer.ActiveLayerSetup(ALayer.layerMapPoint);
//Создаем масштабный элемент карты исследования
//Создаем полилинию
Polyline poly01 = new Polyline();
poly01.AddVertexAt(0, new Point2d(BasePoint.X - _mapPoint.A / 2, BasePoint.Y + _mapPoint.B / 2), 0, 0, 0);
poly01.AddVertexAt(0, new Point2d(BasePoint.X + _mapPoint.A / 2, BasePoint.Y + _mapPoint.B / 2), 0, 0, 0);
poly01.AddVertexAt(0, new Point2d(BasePoint.X + _mapPoint.A / 2, BasePoint.Y - _mapPoint.B / 2), 0, 0, 0);
poly01.AddVertexAt(0, new Point2d(BasePoint.X - _mapPoint.A / 2, BasePoint.Y - _mapPoint.B / 2), 0, 0, 0);
poly01.Closed = true;
btr.AppendEntity(poly01);
tr.AddNewlyCreatedDBObject(poly01, true);
//Слой атрибутов
mapLayer.ActiveLayerSetup(ALayer.layerMapPointAtt);
//Добавляем атрибут №0
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 1 * (TextAttribute + TextAttributeDelta) - TextAttributeDelta, Point3d.Origin.Z);
AttributeDefinition AttributeBlock00 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagV1,
TextString = (_mapPoint.V1).ToString(),
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock00);
tr.AddNewlyCreatedDBObject(AttributeBlock00, true);
//Добавляем атрибут №1
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 2 * (TextAttribute + TextAttributeDelta) - TextAttributeDelta, Point3d.Origin.Z);
AttributeDefinition AttributeBlock01 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagV2,
TextString = (_mapPoint.V2).ToString(),
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock01);
tr.AddNewlyCreatedDBObject(AttributeBlock01, true);
//Добавляем атрибут №2
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 3 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock02 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagRoad,
TextString = _mapPoint.Road,
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock02);
tr.AddNewlyCreatedDBObject(AttributeBlock02, true);
//Добавляем атрибут №3
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 4 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock03 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagER,
TextString = _mapPoint.ExplanationsRoad,
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock03);
tr.AddNewlyCreatedDBObject(AttributeBlock03, true);
//Добавляем атрибут №4
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 5 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock04 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagZR,
TextString = (_mapPoint.RoadZone).ToString(),
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock04);
tr.AddNewlyCreatedDBObject(AttributeBlock04, true);
//Добавляем атрибут №5
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 6 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock05 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagStc,
TextString = _mapPoint.Stc,
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock05);
tr.AddNewlyCreatedDBObject(AttributeBlock05, true);
//Добавляем атрибут №6
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 7 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock06 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagEStc,
TextString = _mapPoint.ExplanationsStc,
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock06);
tr.AddNewlyCreatedDBObject(AttributeBlock06, true);
//Добавляем атрибут №7
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 8 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock07 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagZStc,
TextString = (_mapPoint.StcZone).ToString(),
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock07);
tr.AddNewlyCreatedDBObject(AttributeBlock07, true);
//Добавляем атрибут №8
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 9 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock08 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagSanitary,
TextString = _mapPoint.Sanitary,
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock08);
tr.AddNewlyCreatedDBObject(AttributeBlock08, true);
//Добавляем атрибут №9
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 10 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock09 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagESanitary,
TextString = _mapPoint.ExplanationsSan,
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock09);
tr.AddNewlyCreatedDBObject(AttributeBlock09, true);
//Добавляем атрибут №10
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 11 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock10 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagZSanitary,
TextString = (_mapPoint.SanitaryZone).ToString(),
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock10);
tr.AddNewlyCreatedDBObject(AttributeBlock10, true);
//Добавляем атрибут №11
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 12 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock11 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagWaterZone,
TextString = _mapPoint.WaterZone,
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock11);
tr.AddNewlyCreatedDBObject(AttributeBlock11, true);
//Добавляем атрибут №12
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 13 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock12 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagPlain,
TextString = _mapPoint.Plain,
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock12);
tr.AddNewlyCreatedDBObject(AttributeBlock12, true);
//Добавляем атрибут №13
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 14 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock13 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagStyling,
TextString = _mapPoint.Styling,
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock13);
tr.AddNewlyCreatedDBObject(AttributeBlock13, true);
//Добавляем атрибут №14
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 15 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock14 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagGrunt,
TextString = _mapPoint.Grunt,
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock14);
tr.AddNewlyCreatedDBObject(AttributeBlock14, true);
//Добавляем атрибут №15
BasePoint = new Point3d(Point3d.Origin.X, Point3d.Origin.Y - 16 * (TextAttribute + TextAttributeDelta), Point3d.Origin.Z);
AttributeDefinition AttributeBlock15 = new AttributeDefinition()
{
Position = BasePoint,
Prompt = "",
Tag = TagGo,
TextString = _mapPoint.Go,
Height = TextAttribute,
HorizontalMode = TextHorizontalMode.TextLeft,
VerticalMode = TextVerticalMode.TextBottom,
Visible = true,
AlignmentPoint = BasePoint
};
btr.AppendEntity(AttributeBlock15);
tr.AddNewlyCreatedDBObject(AttributeBlock15, true);
//Слой блока точки карты
mapLayer.ActiveLayerSetup(ALayer.layerMapPoint);
//открываем пространство модели на запись
BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
//создаем новое вхождение блока, используя ранее сохраненный ID определения блока
BlockReference br = new BlockReference(InsPoint, idBlock);
// добавляем созданное вхождение блока на пространство модели и в транзакцию
ms.AppendEntity(br);
tr.AddNewlyCreatedDBObject(br, true);
// добавляем экземпляр ссылки на объект
AttributeReference AttributeRef00 = new AttributeReference();
AttributeReference AttributeRef01 = new AttributeReference();
AttributeReference AttributeRef02 = new AttributeReference();
AttributeReference AttributeRef03 = new AttributeReference();
AttributeReference AttributeRef04 = new AttributeReference();
AttributeReference AttributeRef05 = new AttributeReference();
AttributeReference AttributeRef06 = new AttributeReference();
AttributeReference AttributeRef07 = new AttributeReference();
AttributeReference AttributeRef08 = new AttributeReference();
AttributeReference AttributeRef09 = new AttributeReference();
AttributeReference AttributeRef10 = new AttributeReference();
AttributeReference AttributeRef11 = new AttributeReference();
AttributeReference AttributeRef12 = new AttributeReference();
AttributeReference AttributeRef13 = new AttributeReference();
AttributeReference AttributeRef14 = new AttributeReference();
AttributeReference AttributeRef15 = new AttributeReference();
AttributeRef00.SetAttributeFromBlock(AttributeBlock00, br.BlockTransform);
AttributeRef00.TextString = (_mapPoint.V1).ToString();
AttributeRef01.SetAttributeFromBlock(AttributeBlock01, br.BlockTransform);
AttributeRef01.TextString = (_mapPoint.V2).ToString();
AttributeRef02.SetAttributeFromBlock(AttributeBlock02, br.BlockTransform);
AttributeRef02.TextString = _mapPoint.Road;
AttributeRef03.SetAttributeFromBlock(AttributeBlock03, br.BlockTransform);
AttributeRef03.TextString = _mapPoint.ExplanationsRoad;
AttributeRef04.SetAttributeFromBlock(AttributeBlock04, br.BlockTransform);
AttributeRef04.TextString = (_mapPoint.RoadZone).ToString();
AttributeRef05.SetAttributeFromBlock(AttributeBlock05, br.BlockTransform);
AttributeRef05.TextString = _mapPoint.Stc;
AttributeRef06.SetAttributeFromBlock(AttributeBlock06, br.BlockTransform);
AttributeRef06.TextString = _mapPoint.ExplanationsStc;
AttributeRef07.SetAttributeFromBlock(AttributeBlock07, br.BlockTransform);
AttributeRef07.TextString = (_mapPoint.StcZone).ToString();
AttributeRef08.SetAttributeFromBlock(AttributeBlock08, br.BlockTransform);
AttributeRef08.TextString = _mapPoint.Sanitary;
AttributeRef09.SetAttributeFromBlock(AttributeBlock09, br.BlockTransform);
AttributeRef09.TextString = _mapPoint.ExplanationsSan;
AttributeRef10.SetAttributeFromBlock(AttributeBlock10, br.BlockTransform);
AttributeRef10.TextString = (_mapPoint.SanitaryZone).ToString();
AttributeRef11.SetAttributeFromBlock(AttributeBlock11, br.BlockTransform);
AttributeRef11.TextString = _mapPoint.WaterZone;
AttributeRef12.SetAttributeFromBlock(AttributeBlock12, br.BlockTransform);
AttributeRef12.TextString = _mapPoint.Plain;
AttributeRef13.SetAttributeFromBlock(AttributeBlock13, br.BlockTransform);
AttributeRef13.TextString = _mapPoint.Styling;
AttributeRef14.SetAttributeFromBlock(AttributeBlock14, br.BlockTransform);
AttributeRef14.TextString = _mapPoint.Grunt;
AttributeRef15.SetAttributeFromBlock(AttributeBlock15, br.BlockTransform);
AttributeRef15.TextString = _mapPoint.Go;
// Добавляем AttributeReference к BlockReference
br.AttributeCollection.AppendAttribute(AttributeRef00);
tr.AddNewlyCreatedDBObject(AttributeRef00, true);
br.AttributeCollection.AppendAttribute(AttributeRef01);
tr.AddNewlyCreatedDBObject(AttributeRef01, true);
br.AttributeCollection.AppendAttribute(AttributeRef02);
tr.AddNewlyCreatedDBObject(AttributeRef02, true);
br.AttributeCollection.AppendAttribute(AttributeRef03);
tr.AddNewlyCreatedDBObject(AttributeRef03, true);
br.AttributeCollection.AppendAttribute(AttributeRef04);
tr.AddNewlyCreatedDBObject(AttributeRef04, true);
br.AttributeCollection.AppendAttribute(AttributeRef05);
tr.AddNewlyCreatedDBObject(AttributeRef05, true);
br.AttributeCollection.AppendAttribute(AttributeRef06);
tr.AddNewlyCreatedDBObject(AttributeRef06, true);
br.AttributeCollection.AppendAttribute(AttributeRef07);
tr.AddNewlyCreatedDBObject(AttributeRef07, true);
br.AttributeCollection.AppendAttribute(AttributeRef08);
tr.AddNewlyCreatedDBObject(AttributeRef08, true);
br.AttributeCollection.AppendAttribute(AttributeRef09);
tr.AddNewlyCreatedDBObject(AttributeRef09, true);
br.AttributeCollection.AppendAttribute(AttributeRef10);
tr.AddNewlyCreatedDBObject(AttributeRef10, true);
br.AttributeCollection.AppendAttribute(AttributeRef11);
tr.AddNewlyCreatedDBObject(AttributeRef11, true);
br.AttributeCollection.AppendAttribute(AttributeRef12);
tr.AddNewlyCreatedDBObject(AttributeRef12, true);
br.AttributeCollection.AppendAttribute(AttributeRef13);
tr.AddNewlyCreatedDBObject(AttributeRef13, true);
br.AttributeCollection.AppendAttribute(AttributeRef14);
tr.AddNewlyCreatedDBObject(AttributeRef14, true);
br.AttributeCollection.AppendAttribute(AttributeRef15);
tr.AddNewlyCreatedDBObject(AttributeRef15, true);
tr.Commit();
}
}