- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("OFT")]
public static void OffsetTowardCentroid()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
{
try
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
PromptEntityOptions peo = new PromptEntityOptions("\nSelect curve to Offset Toward: ");
peo.SetRejectMessage("\nSelect curve only: ");
peo.AddAllowedClass(typeof(Line), true);
peo.AddAllowedClass(typeof(Arc), true);
peo.AddAllowedClass(typeof(Circle), true);
peo.AddAllowedClass(typeof(Ellipse), true);
peo.AddAllowedClass(typeof(Polyline), true);
peo.AddAllowedClass(typeof(Spline), true);
PromptEntityResult pres = ed.GetEntity(peo);
if ((pres.Status != PromptStatus.OK)) return;
Entity ent = (Entity)tr.GetObject(pres.ObjectId, OpenMode.ForRead);
// add the polylines to the array
DBObjectCollection dbobjs = new DBObjectCollection();
dbobjs.Add(ent);
// create the region
Region objreg = new Region();
DBObjectCollection objRegions = new DBObjectCollection();
objRegions = Region.CreateFromCurves(dbobjs);
objreg = objRegions[0] as Region;
Curve curv = ent as Curve;
PromptDoubleResult dres = ed.GetDouble("\nDistance for Offset: ");
double dist = dres.Value;
DBObjectCollection ids = curv.GetOffsetCurves(dist);
DBObjectCollection ids2 = curv.GetOffsetCurves(-1 * dist);
double leg= ((ids[0]) as Curve).Area;
double leg2 = ((ids2[0]) as Curve).Area;
if (leg - leg2 < 0)
{
foreach (Entity oEnt in ids)
{
btr.AppendEntity(oEnt);
tr.AddNewlyCreatedDBObject(oEnt, true);
}
}
else
{
foreach (Entity oEnt in ids2)
{
btr.AppendEntity(oEnt);
tr.AddNewlyCreatedDBObject(oEnt, true);
}
}
objRegions.Dispose();
ids.Dispose();
ids2.Dispose();
doc.TransactionManager.FlushGraphics();
tr.Commit();
ed.UpdateScreen();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage("\nError: {0}\nTrace: {1}", ex.Message, ex.StackTrace);
}
}
} |
|