public static void CreateBlockPodSignIden(double PX, double PY, double PZ, double AngleBlock)
{
AccessToDocument AcToDraw = new AccessToDocument();
//получаем ссылку на БД
Database AcadDB = AcToDraw.DBase;
using (Transaction tr = AcadDB.TransactionManager.StartTransaction())
{
//ссылка на слои
//MyWorkLayer layer = new MyWorkLayer();
// открываем таблицу блоков на запись
BlockTable blocktable = (BlockTable)tr.GetObject(AcadDB.BlockTableId, OpenMode.ForWrite);
if (blocktable.Has(posNameSign))
{
MessageBox.Show("Блок с именем (" + posNameSign + ") уже существует", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// создаем новое определение блока, задаем ему имя
BlockTableRecord block = new BlockTableRecord() { Name = posNameSign };
// запоминаем ID созданного определения блока
ObjectId blockId = blocktable.Add(block);
tr.AddNewlyCreatedDBObject(block, true);
if (blocktable.Has(posNameSign))
{
MessageBox.Show("Cjpolfy", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
//Подготавливаем слои
//layer.PreparationLayer();
//Слой знака
//layer.ActiveLayerSetup(MyWorkLayer.layerPOS);
//Базовые координаты
Point3d BasePoint = new Point3d(0, 0, 0);
Point3d InsPoint = new Point3d(PX, PY, PZ);
//Создаем полилинию
Polyline poly = new Polyline();
poly.AddVertexAt(0, new Point2d(BasePoint.X - posLengthOne / 2, BasePoint.Y + posLengthOne / 2), 0, 0, 0);
poly.AddVertexAt(0, new Point2d(BasePoint.X + posLengthOne / 2, BasePoint.Y + posLengthOne / 2), 0, 0, 0);
poly.AddVertexAt(0, new Point2d(BasePoint.X + posLengthOne / 2, BasePoint.Y - posLengthOne / 2), 0, 0, 0);
poly.AddVertexAt(0, new Point2d(BasePoint.X - posLengthOne / 2, BasePoint.Y - posLengthOne / 2), 0, 0, 0);
poly.ConstantWidth = 0.5;
poly.Closed = true;
block.AppendEntity(poly);
tr.AddNewlyCreatedDBObject(poly, true);
Line line = new Line();
line = new Line(new Point3d(BasePoint.X, BasePoint.Y, BasePoint.Z), new Point3d(BasePoint.X+ posLengthOne * 2, BasePoint.Y + posLengthOne * 2, BasePoint.Z));
block.AppendEntity(line);
tr.AddNewlyCreatedDBObject(line, true);
// открываем пространство модели на запись
BlockTableRecord ms = (BlockTableRecord)tr.GetObject(blocktable[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
// создаем новое вхождение блока, используя ранее сохраненный ID определения блока
BlockReference br = new BlockReference(InsPoint, blockId);
MessageBox.Show(blockId.ToString(), "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
//Разворот ссылки блока на заданный радиус
br.TransformBy(Matrix3d.Rotation(AngleBlock, Vector3d.ZAxis, InsPoint));
// добавляем созданное вхождение блока на пространство модели и в транзакцию
ms.AppendEntity(br);
tr.AddNewlyCreatedDBObject(br, true);
MessageBox.Show(PX.ToString(), "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show(PY.ToString(), "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show(PZ.ToString(), "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show(tr.ToString(), "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
tr.Commit();
}
}