Message 1 of 10

Not applicable
08-06-2017
04:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In a dwg ,I test a line is really intersectwith a blockreference .The dwg is the follow.But i found it always occour a error :enotapplicable!Oh my god !
The way to test a line is really intersectwith a blockreference is iterating the entity in BlocktableRecord of blockreference and testing whether the line is intersectwith the entity.Does anyone can give me some help?Thanks a lot!
Here is my code:
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\n请选择一条直线");
peo.SetRejectMessage("\n选择的类型不正确");
peo.AddAllowedClass(typeof(Line), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status == PromptStatus.OK)
{
PromptEntityOptions peo1 = new PromptEntityOptions("\n请选择一个图块");
peo1.SetRejectMessage("\n选择的类型不正确");
peo1.AddAllowedClass(typeof(BlockReference), true);
PromptEntityResult per1 = ed.GetEntity(peo1);
if (per1.Status == PromptStatus.OK)
{
using (Transaction tran = db.TransactionManager.StartTransaction())
{
BlockReference br = per1.ObjectId.GetObject(OpenMode.ForRead) as BlockReference;
AcadLine l = per.ObjectId.GetObject(OpenMode.ForRead).AcadObject as AcadLine;
BlockTableRecord btr = br.BlockTableRecord.GetObject(OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId entid in btr)
{
AcadEntity ent = (entid.GetObject(OpenMode.ForRead).AcadObject as AcadEntity).Copy() as AcadEntity;
dynamic count = l.IntersectWith(ent, AcExtendOption.acExtendNone);
}
tran.Commit();
}
}
}
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\n请选择一条直线");
peo.SetRejectMessage("\n选择的类型不正确");
peo.AddAllowedClass(typeof(Line), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status == PromptStatus.OK)
{
PromptEntityOptions peo1 = new PromptEntityOptions("\n请选择一个图块");
peo1.SetRejectMessage("\n选择的类型不正确");
peo1.AddAllowedClass(typeof(BlockReference), true);
PromptEntityResult per1 = ed.GetEntity(peo1);
if (per1.Status == PromptStatus.OK)
{
using (Transaction tran = db.TransactionManager.StartTransaction())
{
BlockReference br = per1.ObjectId.GetObject(OpenMode.ForRead) as BlockReference;
AcadLine l = per.ObjectId.GetObject(OpenMode.ForRead).AcadObject as AcadLine;
BlockTableRecord btr = br.BlockTableRecord.GetObject(OpenMode.ForRead) as BlockTableRecord;
foreach (ObjectId entid in btr)
{
AcadEntity ent = (entid.GetObject(OpenMode.ForRead).AcadObject as AcadEntity).Copy() as AcadEntity;
dynamic count = l.IntersectWith(ent, AcExtendOption.acExtendNone);
}
tran.Commit();
}
}
}
Solved! Go to Solution.