自已定义了一个块,将其画出并返回ObjectId。
根据返回的块ID,进行填充操作,代码如下:- public static void SetHatchPattern(Database acCurDb,ObjectId objEnt)
- {
- // 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;
- // Adds the arc and line to an object id collection
- ObjectIdCollection acObjIdColl = new ObjectIdCollection();
- acObjIdColl.Add(objEnt);
- // Create the hatch object and append it to the block table record
- Hatch acHatch = new Hatch();
- acBlkTblRec.AppendEntity(acHatch);
- acTrans.AddNewlyCreatedDBObject(acHatch, true);
- acHatch.SetDatabaseDefaults();
- acHatch.ColorIndex = 1;
- //acHatch.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
- acHatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");//实心填充,直接用设置的颜色
- acHatch.Associative = true;
- acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
- // Evaluate the hatch
- acHatch.EvaluateHatch(true);
- // Increase the pattern scale by 2 and re-evaluate the hatch
- acHatch.PatternScale = acHatch.PatternScale + 2;
- acHatch.SetHatchPattern(acHatch.PatternType, acHatch.PatternName);
- acHatch.EvaluateHatch(true);
- // Save the new object to the database
- acTrans.Commit();
- }
- }
当执行
acHatch.AppendLoop(HatchLoopTypes.Outermost, acObjIdColl);
时,总是报错,不知是为什么啊?请高手指教!!!急
|