using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
public partial class WindowSetting : Form
{
public WindowSetting()
{
InitializeComponent();
}
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocumen;
Database acCurDb = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
private void button1_Click(object sender, EventArgs e)
{
string filepath = "";
OpenFileDialog OPF = new OpenFileDialog();
if (OPF.ShowDialog() == DialogResult.OK)
{
filepath = OPF.FileName;
string s = System.IO.File.ReadAllText(filepath);
int poz1 = s.IndexOf("AK\r\n v");
string Text_v = s.Substring(0, poz1);
string[] words = Text_v.Split(new char[] { '\n' });
double dlinna = Convert.ToDouble(words[10].Trim());
double peremichka = Convert.ToDouble(words[11].Trim());
double polka = Convert.ToDouble(words[12].Trim());
#region risovanie balki
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Открытие таблицы Блоков для чтения
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Открытие записи таблицы БЛоков для записи
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
// polka nijnya
Line acLine1 = new Line();
acLine1.SetDatabaseDefaults();
acLine1.StartPoint = new Point3d(0.0, 0.0, 0.0);
acLine1.EndPoint = new Point3d(0.0, polka, 0.0);
acBlkTblRec.AppendEntity(acLine1);
acTrans.AddNewlyCreatedDBObject(acLine1, true);
Line acLine2 = new Line();
acLine2.SetDatabaseDefaults();
acLine2.StartPoint = new Point3d(0, polka, 0.0);
acLine2.EndPoint = new Point3d(dlinna, polka, 0.0);
acBlkTblRec.AppendEntity(acLine2);
acTrans.AddNewlyCreatedDBObject(acLine2, true);
Line acLine3 = new Line();
acLine3.SetDatabaseDefaults();
acLine3.StartPoint = new Point3d(dlinna, polka, 0.0);
acLine3.EndPoint = new Point3d(dlinna, 0.0, 0.0);
acBlkTblRec.AppendEntity(acLine3);
acTrans.AddNewlyCreatedDBObject(acLine3, true);
Line acLine4 = new Line();
acLine4.SetDatabaseDefaults();
acLine4.StartPoint = new Point3d(dlinna, 0.0, 0.0);
acLine4.EndPoint = new Point3d(0.0,0.0, 0.0);
acBlkTblRec.AppendEntity(acLine4);
acTrans.AddNewlyCreatedDBObject(acLine4, true);
// peremichka
Line acLine5 = new Line();
acLine5.SetDatabaseDefaults();
acLine5.StartPoint = new Point3d(0,polka + 500, 0.0);
acLine5.EndPoint = new Point3d(0, polka + 500 + peremichka, 0.0);
acBlkTblRec.AppendEntity(acLine5);
acTrans.AddNewlyCreatedDBObject(acLine5, true);
Line acLine6 = new Line();
acLine6.SetDatabaseDefaults();
acLine6.StartPoint = new Point3d(0, polka + 500 + peremichka, 0.0);
acLine6.EndPoint = new Point3d(dlinna, polka + 500 + peremichka, 0.0);
acBlkTblRec.AppendEntity(acLine6);
acTrans.AddNewlyCreatedDBObject(acLine6, true);
Line acLine7 = new Line();
acLine7.SetDatabaseDefaults();
acLine7.StartPoint = new Point3d(dlinna, polka + 500 + peremichka, 0.0);
acLine7.EndPoint = new Point3d(dlinna, polka + 500 , 0.0);
acBlkTblRec.AppendEntity(acLine7);
acTrans.AddNewlyCreatedDBObject(acLine7, true);
Line acLine8 = new Line();
acLine8.SetDatabaseDefaults();
acLine8.StartPoint = new Point3d(dlinna, polka + 500, 0.0);
acLine8.EndPoint = new Point3d(0.0, polka + 500, 0.0);
acBlkTblRec.AppendEntity(acLine8);
acTrans.AddNewlyCreatedDBObject(acLine8, true);
// polka verhnya
Line acLine9 = new Line();
acLine9.SetDatabaseDefaults();
acLine9.StartPoint = new Point3d(0.0, (polka + peremichka + 1000), 0.0);
acLine9.EndPoint = new Point3d(0.0, (polka + peremichka + 1000) + polka, 0.0);
acBlkTblRec.AppendEntity(acLine9);
acTrans.AddNewlyCreatedDBObject(acLine9, true);
Line acLine10 = new Line();
acLine10.SetDatabaseDefaults();
acLine10.StartPoint = new Point3d(0.0, (polka + peremichka + 1000) + polka, 0.0);
acLine10.EndPoint = new Point3d(dlinna, (polka + peremichka + 1000) + polka, 0.0);
acBlkTblRec.AppendEntity(acLine10);
acTrans.AddNewlyCreatedDBObject(acLine10, true);
Line acLine11 = new Line();
acLine11.SetDatabaseDefaults();
acLine11.StartPoint = new Point3d(dlinna, (polka + peremichka + 1000) + polka, 0.0);
acLine11.EndPoint = new Point3d(dlinna, (polka + peremichka + 1000) , 0.0);
acBlkTblRec.AppendEntity(acLine11);
acTrans.AddNewlyCreatedDBObject(acLine11, true);
Line acLine12 = new Line();
acLine12.SetDatabaseDefaults();
acLine12.StartPoint = new Point3d(dlinna, (polka + peremichka + 1000), 0.0);
acLine12.EndPoint = new Point3d(0.0, (polka + peremichka + 1000), 0.0);
acBlkTblRec.AppendEntity(acLine12);
acTrans.AddNewlyCreatedDBObject(acLine12, true);
acTrans.Commit();
}
ed.UpdateScreen();
#endregion
poz1 = s.IndexOf("BO\r\n");
int poz2 = s.IndexOf("EN\r\n");
string Text2 = s.Substring(poz1, poz2 - poz1);
string[] stroki = Text2.Split(new char[] { '\n' });
#region search " o "
for (int i =0; i < stroki.Length ;i++ )
{
if (stroki[i].StartsWith(" o "))
{
string strokaO = stroki[i];
strokaO = strokaO.Replace("s", "");
strokaO = strokaO.Replace("o", "");
strokaO = strokaO.Replace("v", "");
strokaO = strokaO.Replace("u", "");
strokaO = strokaO.Replace("\r", "");
string[] koord = strokaO.Split(new char[] { ' ' });
List<string> numbers = new List<string>() { };
for (int k = 0; k < koord.Length; k++ )
{
if (koord[k] != "" )
{
numbers.Add(koord[k]);
}
}
double x = Convert.ToDouble(numbers[0].Trim());
double y = Convert.ToDouble(numbers[1].Trim());
double diam = Convert.ToDouble(numbers[2].Trim());
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Открытие таблицы Блоков для чтения
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Открытие записи таблицы БЛоков для записи
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
Circle cir = new Circle();
cir.SetDatabaseDefaults();
cir.Center = new Point3d(x, y + 1000 + polka + peremichka, 0.0);
cir.Radius = diam / 2;
acBlkTblRec.AppendEntity(cir);
acTrans.AddNewlyCreatedDBObject(cir, true);
acTrans.Commit();
}
}
}
#endregion
#region search " u "
for (int i = 0; i < stroki.Length; i++)
{
if (stroki[i].StartsWith(" u "))
{
string strokaO = stroki[i];
strokaO = strokaO.Replace("s", "");
strokaO = strokaO.Replace("o", "");
strokaO = strokaO.Replace("v", "");
strokaO = strokaO.Replace("u", "");
strokaO = strokaO.Replace("\r", "");
string[] koord = strokaO.Split(new char[] { ' ' });
List<string> numbers = new List<string>() { };
for (int k = 0; k < koord.Length; k++)
{
if (koord[k] != "")
{
numbers.Add(koord[k]);
}
}
double x = Convert.ToDouble(numbers[0].Trim());
double y = Convert.ToDouble(numbers[1].Trim());
double diam = Convert.ToDouble(numbers[2].Trim());
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Открытие таблицы Блоков для чтения
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Открытие записи таблицы БЛоков для записи
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
Circle cir = new Circle();
cir.SetDatabaseDefaults();
cir.Center = new Point3d(x, y, 0.0);
cir.Radius = diam / 2;
acBlkTblRec.AppendEntity(cir);
acTrans.AddNewlyCreatedDBObject(cir, true);
acTrans.Commit();
}
}
}
#endregion
#region search " v "
for (int i = 0; i < stroki.Length; i++)
{
if (stroki[i].StartsWith(" v "))
{
string strokaO = stroki[i];
strokaO = strokaO.Replace("s", "");
strokaO = strokaO.Replace("o", "");
strokaO = strokaO.Replace("v", "");
strokaO = strokaO.Replace("u", "");
strokaO = strokaO.Replace("\r", "");
string[] koord = strokaO.Split(new char[] { ' ' });
List<string> numbers = new List<string>() { };
for (int k = 0; k < koord.Length; k++)
{
if (koord[k] != "")
{
numbers.Add(koord[k]);
}
}
double x = Convert.ToDouble(numbers[0].Trim());
double y = Convert.ToDouble(numbers[1].Trim());
double diam = Convert.ToDouble(numbers[2].Trim());
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Открытие таблицы Блоков для чтения
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Открытие записи таблицы БЛоков для записи
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
Circle cir = new Circle();
cir.SetDatabaseDefaults();
cir.Center = new Point3d(x, y+500+polka, 0.0);
cir.Radius = diam / 2;
acBlkTblRec.AppendEntity(cir);
acTrans.AddNewlyCreatedDBObject(cir, true);
acTrans.Commit();
}
}
}
#endregion
double pripuskBalki = Convert.ToDouble(pripusk.Text.Trim());
int kolichestvoRazbienii = (int)(pripuskBalki / 0.1);
double DlinnaStart = dlinna / kolichestvoRazbienii;
ed.UpdateScreen();
using (Transaction tr = acCurDb.TransactionManager.StartTransaction())
{
Point3d point1 = new Point3d(4320.0, -350.0, 0.0);
Point3d point2 = new Point3d(4780.0, 1900.0, 0.0);
PromptSelectionResult selRes = ed.SelectWindow(point1, point2);
// здесь selRes содержит ERROR
if (selRes.Status != PromptStatus.OK)
{
ed.WriteMessage("\nError!\n");
return;
}
}
}
}
}