明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3792|回复: 4

[分享]运用ACADR2005的表格功能创建明细表

[复制链接]
发表于 2004-5-15 10:49:00 | 显示全部楼层 |阅读模式
  1. Sub Main()       ' efan2000编写于2004-05-15
  2.        ' 创建表格样式
  3.        CreateTableStyle
  4.        ' 创建块
  5.        CreateBlock
  6.        ' 创建表格
  7.        CreateTable
  8. End SubSub CreateTableStyle()       Dim DictObj As AcadDictionary
  9.        Set DictObj = ThisDrawing.Database.dictionaries.Item("acad_tablestyle")       Dim keyName As String
  10.        Dim className As String
  11.        Dim customObj As AcadTableStyle
  12.        keyName = "明细表"
  13.        className = "AcDbTableStyle"
  14.        Set customObj = DictObj.AddObject(keyName, className)
  15.       
  16.        ' 表格样式名称
  17.        customObj.Name = "明细表"
  18.        customObj.Description = "明细表表格样式"
  19.       
  20.        ' 由上而下
  21.        customObj.FlowDirection = acTableBottomToTop
  22.       
  23.        ' 边距
  24.        customObj.HorzCellMargin = 0
  25.        customObj.VertCellMargin = 0
  26.       
  27.        ' 取消标题行
  28.        customObj.TitleSuppressed = True
  29.        ' 列标题行,正中对齐,字高为5
  30.        customObj.SetAlignment acHeaderRow, acMiddleCenter
  31.        customObj.SetTextHeight acHeaderRow, 5
  32.        ' 数据行,正中对齐,字高为3.5
  33.        customObj.SetAlignment acDataRow, acMiddleCenter
  34.        customObj.SetTextHeight acDataRow, 3.5
  35. End SubSub CreateBlock()
  36.        Dim iPt(0 To 2) As Double
  37.        iPt(0) = 0: iPt(1) = 0: iPt(2) = 0
  38.        Dim BlockObj As AcadBlock
  39.        Set BlockObj = ThisDrawing.Blocks.Add(iPt, "明细表-表头")
  40.        iPt(0) = 5: iPt(1) = 10.5: iPt(2) = 0
  41.        Dim MTextObj As AcadMText
  42.        Set MTextObj = BlockObj.AddMText(iPt, 10, "单件")
  43.        MTextObj.Height = 3.5
  44.        MTextObj.AttachmentPoint = acAttachmentPointMiddleCenter
  45.        MTextObj.InsertionPoint = iPt
  46.        iPt(0) = 16: iPt(1) = 10.5: iPt(2) = 0
  47.        Set MTextObj = BlockObj.AddMText(iPt, 12, "总计")
  48.        MTextObj.Height = 3.5
  49.        MTextObj.AttachmentPoint = acAttachmentPointMiddleCenter
  50.        MTextObj.InsertionPoint = iPt
  51.        iPt(0) = 11: iPt(1) = 3.5: iPt(2) = 0
  52.        Set MTextObj = BlockObj.AddMText(iPt, 22, "重量")
  53.        MTextObj.Height = 3.5
  54.        MTextObj.AttachmentPoint = acAttachmentPointMiddleCenter
  55.        MTextObj.InsertionPoint = iPt
  56.        Set MTextObj = Nothing
  57.        Dim sPt(0 To 2) As Double
  58.        Dim ePt(0 To 2) As Double
  59.        sPt(0) = 0: sPt(1) = 7: sPt(2) = 0
  60.        ePt(0) = 22: ePt(1) = 7: ePt(2) = 0
  61.        BlockObj.AddLine sPt, ePt
  62.        sPt(0) = 10: sPt(1) = 14: sPt(2) = 0
  63.        ePt(0) = 10: ePt(1) = 7: ePt(2) = 0
  64.        BlockObj.AddLine sPt, ePt
  65.        Set BlockObj = Nothing
  66. End SubSub CreateTable()
  67.        ' 设置当前表格样式
  68.        ThisDrawing.SetVariable "CTABLESTYLE", "明细表"
  69.        Dim MSpaceObj As IAcadModelSpace2
  70.        Set MSpaceObj = ThisDrawing.ModelSpace
  71.        Dim iPt(0 To 2) As Double
  72.        iPt(0) = 0: iPt(1) = 0: iPt(2) = 0
  73.        Dim TableObj As AcadTable
  74.        Set TableObj = MSpaceObj.AddTable(iPt, 2, 8, 7, 10)
  75.        ThisDrawing.SetVariable "CTABLESTYLE", "Standard"
  76.        ' 列标题行,行高为14,其余为7
  77.        TableObj.SetRowHeight 0, 14
  78.        ' 设置列宽
  79.        TableObj.SetColumnWidth 0, 8
  80.        ' 设置单元格文字
  81.        TableObj.SetText 0, 0, "序号"
  82.        TableObj.SetColumnWidth 1, 40
  83.        TableObj.SetText 0, 1, "代   号"
  84.        TableObj.SetColumnWidth 2, 44
  85.        TableObj.SetText 0, 2, "名   称"
  86.        TableObj.SetColumnWidth 3, 8
  87.        TableObj.SetText 0, 3, "数量"
  88.        TableObj.SetColumnWidth 4, 38
  89.        TableObj.SetText 0, 4, "材   料"
  90.        TableObj.SetColumnWidth 5, 10
  91.        TableObj.SetColumnWidth 6, 12
  92.        ' 合并,重量栏
  93.        TableObj.MergeCells 0, 0, 5, 6
  94.        ' 插入块,重理栏
  95.        TableObj.SetBlockTableRecordId 0, 5, ThisDrawing.Blocks("明细表-表头").ObjectID, True
  96.        TableObj.SetCellAlignment 0, 5, acTopCenter
  97.        TableObj.SetColumnWidth 7, 20
  98.        TableObj.SetText 0, 7, "备注"
  99.        ' 数据行
  100.        TableObj.SetText 1, 0, "1"
  101. End Sub

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2004-5-15 11:37:00 | 显示全部楼层
好!学习中
发表于 2004-5-20 17:25:00 | 显示全部楼层
cAD2004的可以吗?


怎么做修改,我想用此程序做我的标题栏
发表于 2012-4-19 10:42:51 | 显示全部楼层
Dim DictObj As AcadDictionary
       Set DictObj = ThisDrawing.Database.dictionaries.Item("acad_tablestyle")       Dim keyName As String
       Dim className As String
       Dim customObj As AcadTableStyle
       keyName = "明细表"
       className = "AcDbTableStyle"
       Set customObj = DictObj.AddObject(keyName, className)
我把这段代码拿来调试,提示错误:系统注册表中不存在 AcRxClassName 项。
这个该怎么解决 ?望指点
发表于 2018-9-16 15:18:09 | 显示全部楼层
谢谢分享太有用了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 08:26 , Processed in 0.190750 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表