|
发表于 2016-3-4 20:09:32
|
显示全部楼层
适用于C#
公共静态类命令
{
[命令方法(“测试”)]
静态公共无效测试()
{
数据库Database=HostApplicationServices.WorkingDatabase
DBPoint:DBPoint=new-DBPoint(new-Point3d(1,1,1))
AddToModelSpace(数据库,dbpoint)
}
公共静态ObjectCollection AddToModelSpace(数据库,参数实体[]列表)
{
ObjectdCollection ID=newObjectdCollection()
AcDb。TransactionManager=database.TransactionManager
使用(Transaction=manager.StartTransaction())
{
BlockTable BlockTable=
action.GetObject(database.BlockTableId,OpenMode.ForRead)作为BlockTable
如果(blockTable==null)
抛出一个新系统。NullReferenceException(“blockTable==null”)
BlockTableRecord:blocktablerRecord=
action.GetObject(blockTable[BlockTableRecord.ModelSpace],OpenMode.ForWrite)作为BlockTableRecord
如果(blockTableRecord==null)
抛出一个新系统。NullReferenceException(“blockTableRecord==null”)
foreach(列表中的实体ent)
{
ids.Add(blockTableRecord.AppendEntity(ent))
动作。AddNewlyCreatedBobObject(ent,true)
}
action.Commit()
}
返回ID
}
}
|
|