几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   ObjectARX(VB.NET/C#) (http://www.dimcax.com/hust/forumdisplay.php?f=176)
-   -   【转帖】大家帮我看看这个jig的例子 (http://www.dimcax.com/hust/showthread.php?t=9457)

yang686526 2009-04-20 09:50 PM

【转帖】大家帮我看看这个jig的例子
 
大家帮我看看这个jig的例子
www.dimcax.com
大家帮我看看这个jig的例子
using system; using system.collections.generic; using system.text; using autodesk.autocad.applicationservices; using autodesk.autocad.databaseservices; using autodesk.autocad.graphicsinterface; using autodesk.autocad.editorinput; using autodesk.autocad.runtime; using autodesk.autocad.colors; using autodesk.autocad.geometry; using app = autodesk.autocad.applicationservices.application; namespace green { public class grasshatch { private matrix3d ucsmatrix; private point3d m_basepoint; private point3d m_destinationpoint; private matrix3d transmat; [commandmethod("drag",)] public void copyalongcurve() { database db = hostapplicationservices.workingdatabase; editor ed = application.documentmanager.mdiactivedocument.editor; try { promptselectionoptions ssoptions = new promptselectionoptions(); ssoptions.messageforadding = "\n选择拖拽的实体 "; ssoptions.messageforremoval = "\n移除实体 "; ssoptions.allowduplicates = true; promptselectionresult ssresult = ed.getselection(ssoptions); if (ssresult.status != promptstatus.ok) return; if (ssresult.value.count == 0) return; ucsmatrix = ed.currentusercoordinatesystem; promptpointresult pointresult = ed.getpoint("\n选取基点: "); if (pointresult.status != promptstatus.ok) return; ucsmatrix = ed.currentusercoordinatesystem; m_basepoint = pointresult.value.transformby(ucsmatrix); do { using (transaction myt = db.transactionmanager.starttransaction()) { dragcallback dragcallbackdelegate = this.followcursor; //start the drag operation promptdragoptions dragoptions = new promptdragoptions(ssresult.value, "\n插入实体:", dragcallbackdelegate); promptpointresult destinationpointresult = ed.drag(dragoptions); if (destinationpointresult.status != promptstatus.ok) return; m_destinationpoint = destinationpointresult.value.transformby(ucsmatrix); //m_destinationpoint = destinationpointresult.value; //point3d tmpdestinationpoint = basecurve.getclosestpointto(m_destinationpoint, false); myt.commit(); } //transform the ss to the new location //this.transformselectionset2(ssresult.value, transmat); this.transformselectionset(ssresult.value, transmat); } while (true); } finally { //myt.dispose(); } } //dragcallback delegate public samplerstatus followcursor(point3d currentpoint, ref matrix3d transmat) { transmat = matrix3d.displacement(m_basepoint.getvectorto(currentpoint)); return samplerstatus.ok; } private void transformselectionset(selectionset ss, matrix3d transmat) { if (ss.count == 0) { return; } database targetdatabase = ss[0].objectid.database; using (transaction trans = targetdatabase.transactionmanager.starttransaction()) { blocktablerecord currentspace = (blocktablerecord)trans.getobject(targetdatabase.currentspaceid, openmode.forwrite); foreach (selectedobject selectedobj in ss) { entity selectedentity = (entity)trans.getobject(selectedobj.objectid, openmode.forread); entity transformedentity = selectedentity.gettransformedcopy(transmat); currentspace.appendentity(transformedentity); trans.addnewlycreateddbobject(transformedentity, true); } trans.commit(); } } private void transformselectionset2(selectionset ss, matrix3d transmatrix) { if (ss.count == 0) return; database targetdatabase = ss[0].objectid.database; using (transaction trans = targetdatabase.transactionmanager.starttransaction()) { objectidcollection entitycollection = new objectidcollection(ss.getobjectids()); idmapping idmap = new idmapping(); targetdatabase.deepcloneobjects(entitycollection, targetdatabase.currentspaceid, idmap, false); foreach (idpair pair in idmap) { entity clonedentity = (entity)trans.getobject(pair.value, openmode.forwrite); clonedentity.transformby(transmatrix); } trans.commit(); } } } }
这是我做的一个jig的例子,能拖动实体在屏幕上移动,但不能把实体添加到模型空间去,请问问题出在哪?
总能把手机放到我自己找不到的地方...


所有的时间均为北京时间。 现在的时间是 02:33 PM.