|
自己搞定!
Create Table BaseLine
(
Id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
RBID SMALLINT UNSIGNED NOT NULL,
OperatorID SMALLINT UNSIGNED NOT NULL,
Vertex_Index SMALLINT UNSIGNED NOT NULL,
Bugle DOUBLE NOT NULL,
Vertex_x DOUBLE NOT NULL,
Vertex_Y DOUBLE NOT NULL,
Vertex_Z DOUBLE NOT NULL
)
Bugle :1/4圆弧角度的正切值。------------------------
1、写入数据库
------------------------
#region【8、将标准层基线的节点信息写入数据库表Building_Baseline】
public static void VertexToMysql(int RBID, int OperatorId,Polyline pLine,Boolean insert)
{
try
{
if (pLine == null)
{
Autodesk..ApplicationServices.Application.ShowAlertDialog("没有选择基线!");
}
else
{
int VertexNum = pLine.NumberOfVertices;
for (int i = 0; i < VertexNum; i++)
{
if (insert)
{
string sql1 = "insert into Building_Baseline (RBID,OperatorId,Vertex_Index,Bugle,Vertex_x,Vertex_y,Vertex_z) values ('"
sql1 += RBID + "','"
sql1 += OperatorId + "','"
sql1 += i + "','"
sql1 += pLine.GetBulgeAt(i) + "','"
sql1 += pLine.GetPoint3dAt(i).X + "','"
sql1 += pLine.GetPoint3dAt(i).Y + "','"
sql1 += pLine.GetPoint3dAt(i).Z + "')";
DbMysql.Excute(sql1);
}
else
{
string sql2 = "UPDATE Building_Baseline SET OperatorId='" + OperatorId + "',Bugle='" + pLine.GetBulgeAt(i) + "',Vertex_x='" + pLine.GetPoint3dAt(i).X + "',Vertex_y='" + pLine.GetPoint3dAt(i).Y + "',Vertex_z='" + pLine.GetPoint3dAt(i).Z + "' WHERE RBID='" + RBID + "' AND Vertex_Index='" + i + "'";
DbMysql.Excute(sql2);
}
}
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("信息更新成功!");
}
}
catch (MySqlException error)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(error.Message);
}
catch (Autodesk.AutoCAD.Runtime.Exception error)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(error.Message);
}
}
#endregion
------------------------------
2、从数据库读取
------------------------------
#region【5、从Mysql按RBID取得一个Polyline】
public static Polyline BaseLine(int RBID)
{
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Polyline thisPolyline = new Polyline();
using (acDoc.LockDocument())
{
MySqlConnection conn = DbMysql.MyConn();
try
{
conn.Open();
string sql = "SELECT Vertex_Index,Bugle,Vertex_x,Vertex_y,Vertex_z from Baseline where RBID ='" + RBID + "'";
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataReader PolyLineFromMysql = cmd.ExecuteReader();
using (Transaction tans = acCurDb.TransactionManager.StartTransaction())
{
int Vertex_Index;
double Bugle;
double Vertex_X;
double Vertex_Y;
//double Vertex_Z;
Point2d thisPoint;
while (PolyLineFromMysql.Read())
{
Vertex_Index = PolyLineFromMysql.GetInt32(0);
Bugle = PolyLineFromMysql.GetDouble(1);
Vertex_X = PolyLineFromMysql.GetDouble(2);
Vertex_Y = PolyLineFromMysql.GetDouble(3);
//Vertex_Z = PolyLineFromMysql.GetOrdinal("Vertex_z");
thisPoint = new Point2d(Vertex_X, Vertex_Y);
thisPolyline.AddVertexAt(Vertex_Index, thisPoint, Bugle, 0, 0);
thisPolyline.Closed = true;
}
}
conn.Close();
conn.Dispose();
}
catch (MySqlException sqlerr)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("数据库错误:" + sqlerr);
}
catch (System.Exception syserr)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("系统错误:" + syserr.ToString());
}
return thisPolyline;
}
}
#endregion
----------------------------
3、写入当前模型空间
----------------------------
#region【1、以指定基点,角度,写入一条闭合的复合线】
public static void BaseLineDraw(Point3d InsertPoint, double Angle,int RBID)
{
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
using (acDoc.LockDocument())
{
try
{
Point3d BasePoint = DbMysql.BasePoint(RBID);
Polyline BaseLine = DbMysql.BaseLine(RBID);
Vector3d MoveVec = BasePoint.GetVectorTo(InsertPoint);
Vector3d RotateVec = new Vector3d(0, 0, 1);
//先旋转,再移动!
BaseLine.TransformBy(Matrix3d.Rotation(Angle,RotateVec,BasePoint));
BaseLine.TransformBy(Matrix3d.Displacement(MoveVec));
using (Transaction trans = acCurDb.TransactionManager.StartTransaction())
{
ObjectId id = new ObjectId();
BlockTable bt = (BlockTable)trans.GetObject(acCurDb.BlockTableId, OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
id = btr.AppendEntity(BaseLine);
trans.AddNewlyCreatedDBObject(BaseLine, true);
trans.Commit();
trans.Dispose();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception caderr)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("CAD错误:" + caderr);
}
catch (System.Exception syserr)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("系统错误:" + syserr.ToString());
}
}
}
#endregion |
|