专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > AutoCAD

cad2008用c#二次开发的填充颜色的有关问题

发布时间:2011-06-27 19:21:10 文章来源:www.iduyao.cn 采编人员:星星草
cad2008用c#二次开发的填充颜色的问题
cad2008用c#二次开发的填充颜色的问题,下面的代码画一个圆填充颜色没问题,我想画几根线组合的封闭图形(就是几个对象的封闭图),再填充颜色,该怎么写呢?
  Database db = HostApplicationServices.WorkingDatabase;
  Transaction trans = db.TransactionManager.StartTransaction();
  try
  {
  Circle circle = new Circle(new Point3d(10, 10, 0), Vector3d.ZAxis, 200);
  BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
  BlockTableRecord btr = (BlockTableRecord)trans.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId, OpenMode.ForWrite);
  btr.AppendEntity(circle);
   
   

  trans.AddNewlyCreatedDBObject(circle, true);
  ObjectIdCollection collection = new ObjectIdCollection();
  collection.Add(circle.ObjectId);
  // collection.Add(circle1.ObjectId);

   
  Hatch hatch = new Hatch();

  hatch.Elevation = 0;
  hatch.HatchStyle = HatchStyle.Normal;
  hatch.ColorIndex = 10;
  hatch.PatternAngle = 0;
  hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案 
  // hatch.Associative = true;
  hatch.AppendLoop(HatchLoopTypes.Default, collection); //设置填充边界 //
  hatch.EvaluateHatch(true);
  btr.AppendEntity(hatch);
  trans.AddNewlyCreatedDBObject(hatch, true);
  trans.Commit();
  }
  catch
  {
  ed.WriteMessage("Error ");
  }
  finally
  {
  trans.Dispose();
  }


------解决方案--------------------
用Polyline可以实现:
[CommandMethod("MyDraw")]
static public void DoDraw()
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
try
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId, OpenMode.ForWrite);


Polyline polyline = new Polyline();
polyline.SetDatabaseDefaults();
polyline.Reset(false, 0);

polyline.AddVertexAt(0, new Point2d(-10, -10), 0, 0, 0);
polyline.AddVertexAt(1, new Point2d(-10, 20), 0, 0, 0);
polyline.AddVertexAt(2, new Point2d(30, 20), 0, 0, 0);
polyline.AddVertexAt(3, new Point2d(30, -10), 0, 0, 0);
polyline.Closed = true;
btr.AppendEntity(polyline);
trans.AddNewlyCreatedDBObject(polyline, true);
ObjectIdCollection collection = new ObjectIdCollection();
collection.Add(polyline.ObjectId);

Hatch hatch = new Hatch();

hatch.Elevation = 0;
hatch.HatchStyle = HatchStyle.Normal;
hatch.ColorIndex = 10;
hatch.PatternAngle = 0;
hatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //设置填充图案
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: