明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2673|回复: 5

[求助]自定义块的填充问题

[复制链接]
发表于 2010-10-21 09:34:00 | 显示全部楼层 |阅读模式
自已定义了一个块,将其画出并返回ObjectId。
根据返回的块ID,进行填充操作,代码如下:
  1. public static void SetHatchPattern(Database acCurDb,ObjectId objEnt)
  2. {
  3. // Start a transaction
  4. using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  5. {
  6. // Open the Block table for read
  7. BlockTable acBlkTbl;
  8. acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
  9. OpenMode.ForRead) as BlockTable;
  10. // Open the Block table record Model space for write
  11. BlockTableRecord acBlkTblRec;
  12. acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
  13. OpenMode.ForWrite) as BlockTableRecord;
  14. // Adds the arc and line to an object id collection
  15. ObjectIdCollection acObjIdColl = new ObjectIdCollection();
  16. acObjIdColl.Add(objEnt);
  17. // Create the hatch object and append it to the block table record
  18. Hatch acHatch = new Hatch();
  19. acBlkTblRec.AppendEntity(acHatch);
  20. acTrans.AddNewlyCreatedDBObject(acHatch, true);
  21. acHatch.SetDatabaseDefaults();
  22. acHatch.ColorIndex = 1;
  23. //acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
  24. acHatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");//实心填充,直接用设置的颜色
  25. acHatch.Associative = true;
  26. acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
  27. // Evaluate the hatch
  28. acHatch.EvaluateHatch(true);
  29. // Increase the pattern scale by 2 and re-evaluate the hatch
  30. acHatch.PatternScale = acHatch.PatternScale + 2;
  31. acHatch.SetHatchPattern(acHatch.PatternType, acHatch.PatternName);
  32. acHatch.EvaluateHatch(true);
  33. // Save the new object to the database
  34. acTrans.Commit();
  35. }
  36. }

当执行
acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
时,总是报错,不知是为什么啊?请高手指教!!!急
发表于 2010-10-21 10:13:00 | 显示全部楼层

图块?填充?

为什么不用一个封闭曲线测试一下你的代码?

 楼主| 发表于 2010-10-21 10:39:00 | 显示全部楼层

这个图块是由封闭曲线组成的啊,

之所以用图块,是因为所绘图形由一批这种自定义的图块组成。

就是想在这些图块插入后,给它们的封闭区间填充,然后就出错

发表于 2010-10-21 18:10:00 | 显示全部楼层
Hatch的边界只能是曲线集合或多义线
发表于 2010-10-31 18:05:00 | 显示全部楼层
现在还看不懂,但一定要顶
 楼主| 发表于 2010-11-24 14:42:00 | 显示全部楼层
问题解决了,搞了好久,ObjectIdCollection集合中加入line,只要封闭是可以填充的。polyline加入到集合中也不能填,问题虽解决,但还是没搞懂这一点:

  1. //========图块填充============
  2. BlockTableRecordEnumerator enume = record.GetEnumerator();//获取块中图元对象计数器
  3. ObjectIdCollection ids = new ObjectIdCollection();
  4. while (enume.MoveNext())
  5. {
  6. DBObject dbobj = trans.GetObject(enume.Current, OpenMode.ForRead);
  7. if (dbobj.GetType() == typeof(Line))
  8. {
  9. ids.Add(dbobj.ObjectId);
  10. }
  11. }
  12. List<ObjectIdCollection> IDS = new List<ObjectIdCollection>();
  13. IDS.Add(ids);
  14. //填充图块
  15. CDraw.HatchObject(db, trans, record, IDS, "SOLID", eColor.Red);
  16. //============================
  17. //填充指定实体
  18. public static void HatchObject(Database db,Transaction trans,BlockTableRecord btr,List<ObjectIdCollection> IDS,string strHatchPattern,eColor color)
  19. {
  20. Hatch acHatch = new Hatch();
  21. acHatch.SetDatabaseDefaults();
  22. acHatch.ColorIndex = (int)color;
  23. acHatch.SetHatchPattern(HatchPatternType.PreDefined, strHatchPattern);//实心填充,直接用设置的颜色
  24. //acHatch.Associative = true;
  25. foreach (ObjectIdCollection ids in IDS)
  26. {
  27. acHatch.InsertLoopAt(0, HatchLoopTypes.Default, ids);
  28. }
  29. BlockTable bt1 = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  30. BlockTableRecord btr1 = trans.GetObject(bt1[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  31. btr.AppendEntity(acHatch);
  32. trans.AddNewlyCreatedDBObject(acHatch, true);
  33. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 01:56 , Processed in 0.180071 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表