如何读取一个图层里面的所有数据?
<P>比如我要读出0图层里的所有直线,而其他图层的直线就不要</P><P>难道一定要在遍历ModleSpace里面的所有直线对象,然后判断每根直线的Layer属性是否为"0"吗?能不能直接对0层里的所有对象进行循环而不用理其它图层的对象?</P> <P>试试看:</P>
<P> public void test2()<BR> {<BR> Database db = HostApplicationServices.WorkingDatabase;<BR> Transaction trans = db.TransactionManager.StartTransaction();<BR> BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,OpenMode.ForRead);<BR> BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt,OpenMode.ForWrite);</P>
<P> try<BR> {<BR> Point3d ptCent = new Point3d(0,0,0);<BR> Circle cir = new Circle(ptCent,Vector3d.ZAxis,20);<BR> Ellipse ell = new Ellipse(ptCent,Vector3d.ZAxis,new Vector3d(10,10,0),0.618,0,0);<BR> Line line = new Line(ptCent,new Point3d(10,10,0));</P>
<P> btr.AppendEntity (cir);<BR> btr.AppendEntity(ell);<BR> btr.AppendEntity(line);<BR> trans.AddNewlyCreatedDBObject(cir,true);<BR> trans.AddNewlyCreatedDBObject(ell,true);<BR> trans.AddNewlyCreatedDBObject(line,true);</P>
<P> foreach(ObjectId id in btr)<BR> {<BR> Entity ent = (Entity)trans.GetObject(id,OpenMode.ForRead);</P>
<P> if(ent.GetType() == typeof(Line))<BR> {<BR> Application.ShowAlertDialog(ent.GetType().ToString()); <BR> }<BR> else<BR> {<BR> Application.ShowAlertDialog("Something else!"); <BR> }<BR> }</P>
<P> trans.Commit();<BR> }<BR> catch(System.Exception ex)<BR> {<BR> Application.ShowAlertDialog(ex.Message);<BR> }<BR> finally<BR> {<BR> trans.Dispose();<BR> }</P>
<P> }</P> <P>2楼的回答不行!你只是把所有的实体都遍历了一遍,根据实体的类型来进行判断,</P>
<P>有没有办法只对直线进行遍历?不用管其他的实体对象,这样效率会提高很多</P>
<P> </P>
<P> </P> <P>前一段看到帮助里边DXF过滤器好像可以提供选择过滤功能,具体就没有细看,</P>
<P>你看下帮助吧</P>
页:
[1]