- UID
- 38377
- 积分
- 135
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-3-25
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
 - using System;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.Runtime;
- namespace AssociativeHatch
- {
- public class Commands
- {
- [CommandMethod("Test")]
- public void AssociativeHatch()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Line lineEnt1 = new Line(new Point3d(0, 0, 0), new Point3d(1000, 0, 0));
- Line lineEnt2 = new Line(new Point3d(1000, 0, 0), new Point3d(800, 600, 0));
- Line lineEnt3 = new Line(new Point3d(800, 600, 0), new Point3d(0, 0, 0));
- Circle circleEnt = new Circle(new Point3d(500, 200, 0), Vector3d.ZAxis, 100);
- ObjectId loopId1 = AppendEntity(lineEnt1);
- ObjectId loopId2 = AppendEntity(lineEnt2);
- ObjectId loopId3 = AppendEntity(lineEnt3);
- ObjectId loopId4 = AppendEntity(circleEnt);
- ObjectIdCollection loops1 = new ObjectIdCollection();
- loops1.Add(loopId1);
- loops1.Add(loopId2);
- loops1.Add(loopId3);
- ObjectIdCollection loops2 = new ObjectIdCollection();
- loops2.Add(loopId4);
- ObjectIdCollection[] loops = new ObjectIdCollection[2];
- loops.SetValue(loops1, 0);
- loops.SetValue(loops2, 1);
- Hatch hatchEnt;
- ObjectId hatEntId = AddHatch(out hatchEnt, 0, "ANGLE", Math.PI / 3, 10);
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- hatchEnt = (Hatch)tr.GetObject(hatEntId, OpenMode.ForWrite);
- hatchEnt.Associative = true;
- for (int i = 0; i < loops.Length; i++)
- {
- hatchEnt.AppendLoop(HatchLoopTypes.Default, loops);
- }
- tr.Commit();
- }
- }
- private ObjectId AddHatch(out Hatch hatchEnt, HatchPatternType patType,
- String patName, Double patternAngle, Double patternScale)
- {
- Hatch ent = new Hatch();
- ent.HatchObjectType = HatchObjectType.HatchObject;
- Database db = HostApplicationServices.WorkingDatabase;
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject
- (db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject
- (bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- ObjectId entId = btr.AppendEntity(ent);
- trans.AddNewlyCreatedDBObject(ent, true);
- ent.SetDatabaseDefaults();
- ent.PatternAngle = patternAngle;
- ent.PatternScale = patternScale;
- ent.SetHatchPattern(patType, patName);
- hatchEnt = ent;
- trans.Commit();
- return entId;
- }
- }
- private ObjectId AppendEntity(Entity ent)
- {
- Database db = HostApplicationServices.WorkingDatabase;
- ObjectId entId;
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,
- OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject
- (bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- entId = btr.AppendEntity(ent);
- trans.AddNewlyCreatedDBObject(ent, true);
- trans.Commit();
- }
- return entId;
- }
- }
- }
|
|