怎么判断对象是否被删除
www.dimcax.com
怎么判断对象是否被删除
因为我遍历直线的时候对一些符合条件的线进行了删除, 再做其他一些遍历的时候,提示对象已被删除 line怎么判断被删除代码如下 //补齐缺失数据(由于文本的遮挡而缺失的数据) public void supplementset(acadtext text) { arraylist leftlines = new arraylist(); arraylist rightlines = new arraylist(); double textx = ((double[])text.insertionpoint)[0]; double texty = ((double[])text.insertionpoint)[1]; acadselectionset seleline = null; try { seleline = _application.activedocument.selectionsets.add("dashline"); } catch { _application.activedocument.selectionsets.item("dashline").delete(); seleline = _application.activedocument.selectionsets.add("dashline"); } short[] filtertype = new short[1] ; filtertype[0] = 0; object[] filterdata = new object[] { "line" }; double[] lpoints ={ textx-10, texty-10, 0, textx-10, texty + text.height, 0, textx,texty+text.height,0,textx,texty-10,0}; seleline.selectbypolygon(acselect.acselectionsetcrossingpolygon,lpoints,filtertype,filterdata); if (seleline.count > 0) { foreach (acadentity ent in seleline) { acadline line = (acadline)ent; leftlines.add(line); } } double[] rpoints ={ textx, texty, 0, textx, texty + text.height, 0, textx + 10, texty + text.height, 0, textx + 10, texty, 0 }; seleline.clear(); seleline.selectbypolygon(acselect.acselectionsetcrossingpolygon, rpoints, filtertype, filterdata); if (seleline.count > 0) { foreach (acadentity ent in seleline) { acadline line = (acadline)ent; rightlines.add(line); } } if ((rightlines.count > 0) && (leftlines.count > 0)) { object[] rline = rightlines.toarray(); for (int i = 0; i < rightlines.count; i++) { acadline line = (acadline)rline; if (line.visible!=false) { double x1 = ((double[])line.startpoint)[0]; double y1 = ((double[])line.startpoint)[1]; double x2 = ((double[])line.endpoint)[0]; double y2 = ((double[])line.endpoint)[1]; double k = 0; double b = 0; if (x2 < x1) { double mx = x1; double my = y1; x1 = x2; y1 = y2; x2 = mx; y2 = my; } if ((x2 - x1) != 0) { k = (y2 - y1) / (x2 - x1); b = (y2 * x1 - x2 * y1) / (x2 - x1); } else { } // acadline[] lelines = (acadline[])leftlines.toarray(); object[] lelines = leftlines.toarray(); for (int j = 0; j < leftlines.count; j++) { acadline leline = (acadline)leftlines[j]; if (line != leline) { double xl1 = ((double[])leline.startpoint)[0]; double yl1 = ((double[])leline.startpoint)[1]; double xl2 = ((double[])leline.endpoint)[0]; double yl2 = ((double[])leline.endpoint)[1]; if (xl2 < xl1) { double nx = xl1; double ny = yl1; xl1 = xl2; yl1 = yl2; xl2 = nx; yl2 = ny; } if ((xl2 - xl1) != 0) { double kl = (yl2 - yl1) / (xl2 - xl1); double bl = (yl2 * xl1 - xl2 * yl1) / (xl2 - xl1); if ((k == kl) && (b == bl)) { double[] lp ={ xl2, yl2, 0 }; //((double[])lp.coordinates)[0]=xl2; // ((double[])lp.coordinates)[1]=yl2; // ((double[])lp.coordinates)[2]=0; double[] rp ={ x1, y1, 0 }; //((double[])rp.coordinates)[0]=x1; //((double[])rp.coordinates)[1]=y2; //((double[])rp.coordinates)[2]=0; dbxdoc.modelspace.addline(lp, rp); line.delete(); leline.delete(); //leline.database.modelspace.delete(); _application.update(); leftlines.remove(lelines[j]); break; } } } } } } } }
你这个是com方式的吧,这里基本上没人用。
c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。
re
是的,大家都怎么用的,
re
我用的autocad 我用的autocad