如何从填充图案上获得角点?
本帖最后由 介之推 于 2014-5-20 20:38 编辑大家好,
在AutoCAD中,我们用鼠标点击一个填充时,可以看到这个填充图案四周和中心出现一些点,其中选择中心的那个点后可以移动这个填充图案,如下图所示。
填充一般是Hatch类的一个实例,我想请问一下:中心的这个点是这个填充图案的那个属性啊?或者通过什么方式可以获得中心的这个点? 谢谢指教了。
GripStretchPoints ivde 发表于 2014-5-20 19:47 static/image/common/back.gif
GripStretchPoints
你好,ivde
我用的是AutoCAD 2010, 好像没有这个 GripStretchPoints,倒是有个GetGripPoint(), 但我不知道如何使用啊。这是我现在的代码,请指教:
//从屏幕中选择填充和文字
public bool Select(List<Point3d> hatchPointLst,List<DBText> nameLst)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
//定义过滤器
SelectionFilter flt = new SelectionFilter(new TypedValue[] { new TypedValue(0, "TEXT,HATCH") });
PromptSelectionOptions optSel = new PromptSelectionOptions();
optSel.MessageForAdding = "\n请选择观察点分布图";
PromptSelectionResult resSel = ed.GetSelection(optSel, flt);
if (resSel.Status != PromptStatus.OK)
return false;
SelectionSet selSet = resSel.Value;
ObjectId[] ids = selSet.GetObjectIds();
foreach (ObjectId sSetEntId in ids)
{
Entity ent = (Entity)trans.GetObject(sSetEntId, OpenMode.ForRead);
if (ent.GetType().Name == "Hatch")
{
Hatch myHatch = (Hatch) trans.GetObject(sSetEntId, OpenMode.ForRead);
//myHatch.GetGripPoints();
} //End of the if (ent.GetType().Name == "Hatch")
else if (ent.GetType().Name == "DBText")
{
DBText myText = (DBText)trans.GetObject(sSetEntId, OpenMode.ForRead);
nameLst.Add(myText);
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);
return false;
}
trans.Commit();
//如果执行到这里,表示一切顺利,可以返回true
return true;
}
} 是 GetStretchPoints
public void MyCommand() // This method can have any name
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
PromptEntityResult per = ed.GetEntity("\nSelect Entity:");
if (per.Status != PromptStatus.OK) return;
ObjectId hatId = per.ObjectId;
Entity ent = (Entity) tr.GetObject(hatId, OpenMode.ForRead);
Point3dCollection pts = new Point3dCollection();
ent.GetStretchPoints(pts);
using (tr )
{
try
{
BlockTableRecord btr = (BlockTableRecord) tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
int j = 1;
for (int i = 0; i < pts.Count ; i++)
{
DBPoint dbPoint = new DBPoint();
dbPoint.Position = pts;
dbPoint.ColorIndex = j;
btr.AppendEntity( dbPoint);
tr.AddNewlyCreatedDBObject(dbPoint,true);
if (j > 255) {j = 1;}
j++;
}
tr.Commit();
}
catch (Exception)
{
throw;
}
}
}
好东西,正在找,学习一下
页:
[1]