|
发表于 2012-10-14 23:59:00
|
显示全部楼层
飞狐,您好,请问一下如果是创建含填充色的块,改如何创建,下面是代码,到acTrans.AddNewlyCreatedDBObject(acCir, true);时报错
//创建块定义
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
BlockTable bt = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord blk = null;
if (!bt.Has("美化天线"))
{
blk = new BlockTableRecord();
blk.Name = "美化天线";
Circle acCir = new Circle();
acCir.Radius = 1.5;
acCir.Center = new Point3d(0, 0, 0);
blk.AppendEntity(acCir);
//acTrans.AddNewlyCreatedDBObject(acCir, true);
Circle acCir1 = new Circle();
acCir1.Radius = 3;
acCir1.Center = new Point3d(0, 0, 0);
blk.AppendEntity(acCir1);
//acTrans.AddNewlyCreatedDBObject(acCir1, true);
/*
ObjectIdCollection acObjIdColl = new ObjectIdCollection();
acObjIdColl.Add(acCir.ObjectId);
ObjectIdCollection acObjIdColl1 = new ObjectIdCollection();
acObjIdColl1.Add(acCir1.ObjectId);
Hatch acHatch = new Hatch();
acTrans.AddNewlyCreatedDBObject(acHatch, true);
acHatch.SetDatabaseDefaults();
acHatch.HatchObjectType = HatchObjectType.GradientObject;
acHatch.SetGradient(GradientPatternType.PreDefinedGradient, "SPHERICAL");
// We're defining two colours
acHatch.GradientOneColorMode = false;
GradientColor[] gcs = new GradientColor[2];
gcs[0] = new GradientColor(Color.FromRgb(213, 213, 210), 0);
gcs[1] = new GradientColor(Color.FromRgb(255, 255, 255), 1);
acHatch.SetGradientColors(gcs);
//acHatch.Elevation = 0;
acHatch.Associative = true;
acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
acHatch.AppendLoop(HatchLoopTypes.Default, acObjIdColl1);
acHatch.EvaluateHatch(true);
acHatch.HatchStyle = HatchStyle.Outer;
blk.AppendEntity(acHatch);
*/
labelblkid = bt.Add(blk);
acTrans.AddNewlyCreatedDBObject(blk, true);
}
else
{
blk = acTrans.GetObject(bt["美化天线"], OpenMode.ForWrite) as BlockTableRecord;
labelblkid = blk.ObjectId;
}
acTrans.Commit();
} |
|