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


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » ObjectARX(VB.NET/C#)
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-29, 04:42 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】.net下自定义autocad表格样式 - 精华帖集合

.net下自定义autocad表格样式 - 精华帖集合
www.dimcax.com
.net下自定义autocad表格样式
需要知道的是表格样式对象存储在一个特别的字典中,可通过database的tablestyledictionaryid属性进行访问。可以通过这个objectid属性来访问字典来查询存在的表格样式或添加一个新的样式。这样,指定表格样式的颜色和格式就变得简单了。下面的c#代码定义了一个新的表格样式 "garish table style":一个红色的表头,黄色的数据区以及品红色的文字(kean有点太。。。不过他也提示了 运行本文程序的时候 最好戴上太阳镜):-) using autodesk.autocad.applicationservices; using autodesk.autocad.databaseservices; using autodesk.autocad.editorinput; using autodesk.autocad.runtime; using autodesk.autocad.colors; //trans by yiweimi.更多文章: qq:68006907 转载注明出处 namespace tableandstylecreation { public class commands { [commandmethod("ctws")] static public void createtablewithstyle() { document doc = application.documentmanager.mdiactivedocument; database db = doc.database; editor ed = doc.editor; promptpointresult pr = ed.getpoint("\nenter table insertion point: "); if (pr.status == promptstatus.ok) { transaction tr = doc.transactionmanager.starttransaction(); using (tr) { // 如果表格样式不存在 则创建 // first let us create our custom style, // if it doesn't exist const string stylename = "garish table style"; objectid tsid = objectid.null; dbdictionary sd = (dbdictionary)tr.getobject( db.tablestyledictionaryid, openmode.forread ); // 如果已经存在则使用 use the style if it already exists if (sd.contains(stylename)) { tsid = sd.getat(stylename); } else { // 不存在,进行创建 otherwise we have to create it tablestyle ts = new tablestyle(); // 表头设为红色 make the header area red ts.setbackgroundcolor( color.fromcolorindex(colormethod.byaci, 1), (int)(rowtype.headerrow | rowtype.titlerow) ); // 数据区域黄色 and the data area yellow ts.setbackgroundcolor( color.fromcolorindex(colormethod.byaci, 2), (int)rowtype.datarow ); // 文字品红色 with magenta text everywhere (yeuch :-) ts.setcolor( color.fromcolorindex(colormethod.byaci, 6), (int)(rowtype.headerrow | rowtype.titlerow | rowtype.datarow) ); // 添加样式到字典 // add our table style to the dictionary // and to the transaction sd.upgradeopen(); tsid = sd.setat(stylename, ts); tr.addnewlycreateddbobject(ts, true); sd.downgradeopen(); } blocktable bt = (blocktable)tr.getobject( doc.database.blocktableid, openmode.forread ); table tb = new table(); // 使用表格样式 use our table style if (tsid == objectid.null) // 这个不可能发生 除非以上逻辑发生了变化 // this should not happen, unless the // above logic changes tb.tablestyle = db.tablestyle; else tb.tablestyle = tsid; tb.numrows = 5; tb.numcolumns = 3; tb.setrowheight(3); tb.setcolumnwidth(15); tb.position = pr.value; // 创建一个包含表格内容的2维数组 // create a 2-dimensional array // of our table contents string[,] str = new string[5, 4]; str[0, 0] = "part no."; str[0, 1] = "name "; str[0, 2] = "material "; str[1, 0] = "1876-1"; str[1, 1] = "flange"; str[1, 2] = "perspex"; str[2, 0] = "0985-4"; str[2, 1] = "bolt"; str[2, 2] = "steel"; str[3, 0] = "3476-k"; str[3, 1] = "tile"; str[3, 2] = "ceramic"; str[4, 0] = "8734-3"; str[4, 1] = "kean"; str[4, 2] = "mostly water"; // 使用一个套嵌的循环添加和格式化每个表格 // use a nested loop to add and format each cell for (int i = 0; i < 5; i++) { for (int j = 0; j < 3; j++) { tb.settextheight(i, j, 1); tb.settextstring(i, j, str[i, j]); tb.setalignment(i, j, cellalignment.middlecenter); } } tb.generatelayout(); blocktablerecord btr = (blocktablerecord)tr.getobject( bt[blocktablerecord.modelspace], openmode.forwrite ); btr.appendentity(tb); tr.addnewlycreateddbobject(tb, true); tr.commit(); } } } } } [ ]
如下为加载net模块、运行ctws命令、选取放置点后获得的"garish"表: 并且如果我们运行tablestyle命令,我们可以在列表中看到自定义的表格样式:
学习,!
感谢一微米兄的精彩翻译!
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 05:19 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多