步骤:
方法实现
public static ObjectId HatchGradient(this Database db,string gradientName,short colorIndex1,short colorIndex2,params ObjectId[] entIds)
{
ObjectId obId= ObjectId.Null;
using(Transaction trans = db.TransactionManager.StartTransaction())
{
Hatch hatch = new Hatch();
hatch.HatchObjectType = HatchObjectType.GradientObject;
hatch.SetGradient(GradientPatternType.PreDefinedGradient, gradientName);
Color color1 = Color.FromColorIndex(ColorMethod.ByColor, colorIndex1);
Color color2= Color.FromColorIndex(ColorMethod.ByColor, colorIndex2);
GradientColor gColor1=new GradientColor(color1,0);
GradientColor gColor2 = new GradientColor(color2, 1);
hatch.SetGradientColors(new GradientColor[] { gColor1, gColor2 });
BlockTable bt=trans.GetObject(db.BlockTableId,OpenMode.ForRead)as BlockTable;
BlockTableRecord btr= trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite) as BlockTableRecord;
obId=btr.AppendEntity(hatch);
trans.AddNewlyCreatedDBObject(hatch, true);
ObjectIdCollection obIds = new ObjectIdCollection();
hatch.Associative = true;
for(int i=0;i<entIds.Length;i++)
{
obIds.Clear();
obIds.Add(entIds[i]);
hatch.AppendLoop(HatchLoopTypes.Outermost, obIds);
}
hatch.EvaluateHatch(true);
trans.Commit();
}
return obId;
}