![]() |
【转帖】自写:对象(圆)浏览,cad焦点问题 - 精华帖集合
自写:对象(圆)浏览,cad焦点问题 - 精华帖集合
www.dimcax.com 自写:对象(圆)浏览,cad焦点问题 [assembly: commandclass(typeof(sbydo.cad.test.test))] namespace sbydo.cad.test { public class test { public static autodesk.autocad.windows.paletteset ps; public static usercontrolcircle control; [commandmethod("sbydo")] public static void paletteset() // this method can have any name { //实例select类 select circle = new select(); if (control == null) control = new usercontrolcircle(); control.datagridviewcircle.datasource = circle.dataset.tables["circle"]; control.datagridviewcircle.columns["handle"].visible = false; if (ps == null) { ps = new autodesk.autocad.windows.paletteset("sbydo"); system.drawing.size s = new system.drawing.size(280, 100); ps.size = s; ps.dock = docksides.left; ps.add("测试", control); } ps.visible = true; } } } 复制代码 namespace sbydo.cad.test { class select { private database db; private autodesk.autocad.databaseservices.transactionmanager tm; private objectid[] ids; private dataset ds; private system.data.datatable dt; public dataset dataset { get { return ds;} } public objectid[] objectids { get { return ids; } } public select() { db = hostapplicationservices.workingdatabase; tm = db.transactionmanager; initializedataset(); getcircleids(); writedataset(); } public void initializedataset() { system.data.datacolumn[] cols; cols = new system.data.datacolumn[]{ new system.data.datacolumn("id",system.type.gettype("system.int32")), new system.data.datacolumn( "x",system.type.gettype("system.double")), new system.data.datacolumn("y",system.type.gettype("system.double")), new system.data .datacolumn ("r",system.type.gettype("system.double")), new system.data .datacolumn ("handle",system.type.gettype("system.int64")) }; ds = new dataset(); dt = new system.data.datatable("circle"); foreach (system.data.datacolumn col in cols) { dt.columns.add(col); } ds.tables.add(dt); } /// <summary> /// 得到所有id集合 /// </summary> public void getcircleids() { editor ed = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.editor; ed.writemessage("\n获取所有圆\n"); typedvalue[] firstvalue = new typedvalue[]{ new typedvalue(0,"circle"), }; selectionfilter filter = new selectionfilter(firstvalue); promptselectionresult resselectopt = ed.selectall(filter); if (resselectopt.status != promptstatus.ok) { ids = null; return; } selectionset ss = resselectopt.value; ids = ss.getobjectids(); } /// <summary> /// 获得圆数据集 /// </summary> public void writedataset() { if (ids == null) return; using (transaction trans = tm.starttransaction()) { try { uint32 i = 1; foreach (objectid id in ids) { circle entity = trans.getobject(id, openmode.forread) as circle ; datarow row = dt.newrow(); row["id"] = i++; row["x"] = math.round(entity.center.x, 4); row["y"] = math.round(entity.center.y, 4); row["r"] = math.round(entity.radius, 4); row["handle"] = entity.handle.value; dt.rows.add(row); } } catch { } trans.commit(); } } } } 复制代码 路漫漫其修远兮,吾将上下而求索! //////////////用户控件类//////////////////// 里面有个datagrid,设置为public public system.windows.forms.datagridview datagridviewcircle; namespace sbydo.cad.test { public partial class usercontrolcircle : usercontrol { objectid[] ids = new objectid[1]; public usercontrolcircle() { initializecomponent(); } private void datagridviewcircle_cellmousedoubleclick(object sender, datagridviewcellmouseeventargs e) { int selectindex = this.datagridviewcircle.currentrow.index; long hd = (long)this.datagridviewcircle.rows[selectindex].cells["handle"].value; zoomobject(hd); } /// <summary> /// 缩放单个实体 /// </summary> public void zoomobject(long handle) { editor ed = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.editor; database db = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.database; handle hd = new handle(handle); objectid id = db.getobjectid(false, hd, 0); ids[0] = id; autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.sendstringtoexecute("zoom o ", true, false, false); ed.setimpliedselection(ids); } //鼠标移出到cad窗口 private void datagridviewcircle_mouseleave(object sender, eventargs e) { if (ids[0].handle.value != 0) { editor ed = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.editor; ed.setimpliedselection(ids); } } } } 复制代码 [ ] 路漫漫其修远兮,吾将上下而求索! 上面用handle的方法不知道是否正确? 以上就是代码了,问题就是: 1.需要鼠标moveleave到cad窗口,才能实现select实体。 2. autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.sendstringtoexecute("zoom o ", true, false, false); ed.setimpliedselection(ids); 找到这个方法缩放到实体对象,不知道有其他方法没,缩放到窗口呢??? 若用"zoom w"缩放到窗口,可以传输一个参数给cad系统知道么??? 3.不知道怎么把文件传到论坛,所以只有这样贴代码了。 大家看看,有什么问题????? 劳驾!!! 路漫漫其修远兮,吾将上下而求索! 项目文件在此! [ ] 路漫漫其修远兮,吾将上下而求索! 原帖由 sbydo 于 2007-10-12 10:48 am 发表 2. autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.sendstringtoexecute("zoom o ", true, false, false); ed.setimpliedselection(ids); 找到这个方法缩放到实体对象,不知道有其他方法没,缩放到窗口呢??? 若用"zoom w"缩放到窗口,可以传输一个参数给cad系统知道么??? 如果你用的cad2007及以上的版本,可以使用autodesk.autocad.graphicssystem.view 类的有关函数:zoom\zoomextents\zoomwindow c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。 才鸟,老大 你说得这个我找到了,但是不知道怎么用啊????拜托举个例子。! [ ] 路漫漫其修远兮,吾将上下而求索! 同请教这个view类应该如何使用,通过什么方法可以得到当前的view, 老大的书里有这方面的内容。 还没开始用arx编程呢,刚想学习 |
所有的时间均为北京时间。 现在的时间是 06:16 AM. |