![]() |
【转帖】新人我的练习作品,请指教~! - 精华帖集合
新人我的练习作品,请指教~! - 精华帖集合
www.dimcax.com 新人我的练习作品,请指教~! , , 偶刚学c#难的东东不会,发个等分曲线的小小程序,请大家指教。 using system; using autodesk.autocad.applicationservices; using acad = autodesk.autocad.applicationservices.application; using autodesk.autocad.databaseservices; using autodesk.autocad.editorinput; using autodesk.autocad.geometry; using autodesk.autocad.runtime; namespace fsxm.acad { public class breakcurve : iextensionapplication { //全局变量,默认等分的段数 static int n = 2; //等分曲线选择集 [commandmethod("averagescurve", commandflags.usepickset)] public void averagescurvess() { document doc = acad.documentmanager.mdiactivedocument; editor ed = doc.editor; database db = doc.database; #region 用户输入================================================= promptselectionoptions sop = new promptselectionoptions(); sop.rejectobjectsonlockedlayers = true;//不允许上锁的图层的东东 promptselectionresult srt = ed.getselection (sop, new selectionfilter(new typedvalue[] { new typedvalue(0, "*line,arc,circle,,ellipse") })); selectionset ss; if (srt.status == promptstatus.ok) ss = srt.value; else return; //=================================== promptintegeroptions iop = new promptintegeroptions("指定等分的段数"); iop.defaultvalue = n; promptintegerresult irt = ed.getinteger(iop); if (irt.status != promptstatus.ok || irt.value < 2) return; else n = irt.value; #endregion//====================================================== using (transaction trans = db.transactionmanager.starttransaction()) { //兼容modelspace,paperspace objectid id = trans.getobject(ss[0].objectid, openmode.forread).ownerid; blocktablerecord spase = (blocktablerecord)trans.getobject(id, openmode.forwrite); foreach (selectedobject obj in ss) { curve cv = (curve)trans.getobject(obj.objectid, openmode.forwrite); foreach (dbobject dbobj in averagescurve(cv, n)) { spase.appendentity((entity)dbobj); trans.addnewlycreateddbobject(dbobj, true); } } trans.commit(); } } //等分单条曲线 public dbobjectcollection averagescurve(curve cv, int n) { double ep = cv.endparam; double len = cv.getdistanceatparameter(ep); double split = len / n; doublecollection pas = new doublecollection(); if (cv.closed) //闭合曲线要先断开 pas.add(cv.startparam); for (int i = 1; i < n; i++) { pas.add(cv.getparameteratdistance(i * split)); } cv.erase(); return cv.getsplitcurves(pas); } #region iextensionapplication 成員 public void initialize() { acad.documentmanager.mdiactivedocument.editor.writemessage ("\n功能:等分打断曲线,命令:averagescurve,copyright (c) 2008 fsxm。"); } public void terminate() { } #endregion } } 复制代码 飞兄写的不错啊,给你加精了 c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。 才大~呵呵 楼主,太需要这样的例子学习了. 学习了,感谢! 找个半天终于找到这样的例子了, ----新手 |
所有的时间均为北京时间。 现在的时间是 01:54 AM. |