圣·多多 发表于 2005-9-7 16:44:00

如何读取一个图层里面的所有数据?

<P>比如我要读出0图层里的所有直线,而其他图层的直线就不要</P>
<P>难道一定要在遍历ModleSpace里面的所有直线对象,然后判断每根直线的Layer属性是否为"0"吗?能不能直接对0层里的所有对象进行循环而不用理其它图层的对象?</P>

simengliu 发表于 2005-9-9 17:48:00

<P>试试看:</P>
<P>&nbsp;&nbsp;public void test2()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Database db = HostApplicationServices.WorkingDatabase;<BR>&nbsp;&nbsp;&nbsp;Transaction trans = db.TransactionManager.StartTransaction();<BR>&nbsp;&nbsp;&nbsp;BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,OpenMode.ForRead);<BR>&nbsp;&nbsp;&nbsp;BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt,OpenMode.ForWrite);</P>
<P>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;Point3d ptCent = new Point3d(0,0,0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Circle cir = new Circle(ptCent,Vector3d.ZAxis,20);<BR>&nbsp;&nbsp;&nbsp;&nbsp;Ellipse ell = new Ellipse(ptCent,Vector3d.ZAxis,new Vector3d(10,10,0),0.618,0,0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;Line line = new Line(ptCent,new Point3d(10,10,0));</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;btr.AppendEntity (cir);<BR>&nbsp;&nbsp;&nbsp;&nbsp;btr.AppendEntity(ell);<BR>&nbsp;&nbsp;&nbsp;&nbsp;btr.AppendEntity(line);<BR>&nbsp;&nbsp;&nbsp;&nbsp;trans.AddNewlyCreatedDBObject(cir,true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;trans.AddNewlyCreatedDBObject(ell,true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;trans.AddNewlyCreatedDBObject(line,true);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;foreach(ObjectId id in btr)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Entity ent = (Entity)trans.GetObject(id,OpenMode.ForRead);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(ent.GetType() == typeof(Line))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Application.ShowAlertDialog(ent.GetType().ToString());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Application.ShowAlertDialog("Something else!");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;trans.Commit();<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch(System.Exception ex)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;Application.ShowAlertDialog(ex.Message);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;finally<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;trans.Dispose();<BR>&nbsp;&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;}</P>

月海临风 发表于 2005-9-12 13:10:00

<P>2楼的回答不行!你只是把所有的实体都遍历了一遍,根据实体的类型来进行判断,</P>
<P>有没有办法只对直线进行遍历?不用管其他的实体对象,这样效率会提高很多</P>
<P>&nbsp;</P>
<P>&nbsp;</P>

simonkx 发表于 2005-12-28 22:52:00

<P>前一段看到帮助里边DXF过滤器好像可以提供选择过滤功能,具体就没有细看,</P>
<P>你看下帮助吧</P>
页: [1]
查看完整版本: 如何读取一个图层里面的所有数据?