|
发表于 2010-8-11 16:57:00
|
显示全部楼层
public void AddLine(System.Data.DataTable dt)
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
for (int j = 0; j
if (!Convert.IsDBNull(dt.Rows[j]["p2.X"]) && !Convert.IsDBNull(dt.Rows[j]["p2.Y"]) && !Convert.IsDBNull(dt.Rows[j]["p2.Hight"]) &&
!Convert.IsDBNull(dt.Rows[j]["t1.X"]) && !Convert.IsDBNull(dt.Rows[j]["t1.Y"]) && !Convert.IsDBNull(dt.Rows[j]["t1.Hight"]))
{
// Create a line
Line acLine = new Line
(
new Point3d
(
Convert.ToDouble(dt.Rows[j]["t1.X"]),
Convert.ToDouble(dt.Rows[j]["t1.Y"]),
Convert.ToDouble(dt.Rows[j]["t1.Hight"])
),
new Point3d
(
Convert.ToDouble(dt.Rows[j]["p2.X"]),
Convert.ToDouble(dt.Rows[j]["p2.Y"]),
Convert.ToDouble(dt.Rows[j]["p2.Hight"])
)
);
acLine.SetDatabaseDefaults();
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acLine);
acTrans.AddNewlyCreatedDBObject(acLine, true);
}
}
// Save the new object to the database
acTrans.Commit();
}
}
这是我的代码
|
|