找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 3215|回复: 7

[他山之石] Creating a Table Style with AutoLISP and the ActiveX API

[复制链接]
发表于 2013-8-24 23:45:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
Table styles in AutoCAD are primarily created using the Table Style dialog box (TABLESTYLE command) since there is no command line support, which limits the ability of creating a table style using a script or the COMMAND function in AutoLISP.  However, you can leverage the ActiveX API to create or modify table style and cell styles defined in your current drawing.
NOTE: ActiveX API is not available on AutoCAD for Mac.
To create a table style, you must access the ACAD_TABLESTYLE dictionary in the current drawing.  Once a reference to the ACAD_TABLESTYLE dictionary is obtained, you can then check to see if a table style already exists using the VLA-GETOBJECT function or add a table style using the VLA-ADDOBJECT function.
The following sample code demonstrates how to create a new table style, but does not check to see if the table style already exists first.  If the table style does exist, an error will occur.
  1. (vl-load-com)
  2. (defun c:CreateTableStyle ()
  3.   ;; Get the AutoCAD application and current document
  4.   (setq acad (vlax-get-acad-object))
  5.   (setq doc (vla-get-ActiveDocument acad))
  6.   ;; Get the Dictionaries collection and the TableStyle dictionary
  7.   (setq dicts (vla-get-Dictionaries doc))
  8.   (setq dictObj (vla-Item dicts "acad_tablestyle"))
  9.   ;; Create a custom table style
  10.   (setq key   "MyTableStyle"
  11. class "AcDbTableStyle"
  12.   )
  13.   (setq custObj (vla-AddObject dictObj key class))
  14.   ;; Set the name and description for the style
  15.   (vla-put-Name custObj "MyTableStyle")
  16.   (vla-put-Description
  17.     custObj
  18.     "This is my custom table style"
  19.   )
  20.   ;; Sets the bit flag value for the style
  21.   (vla-put-BitFlags custObj 1)
  22.   ;; Sets the direction of the table, top to bottom or bottom to top
  23.   (vla-put-FlowDirection custObj acTableTopToBottom)
  24.   ;; Sets the supression of the table header
  25.   (vla-put-HeaderSuppressed custObj :vlax-false)
  26.   ;; Sets the horizontal margin for the table cells
  27.   (vla-put-HorzCellMargin custObj 0.22)
  28.   ;; Sets the supression of the table title
  29.   (vla-put-TitleSuppressed custObj :vlax-false)
  30.   ;; Sets the vertical margin for the table cells
  31.   (vla-put-VertCellMargin custObj 0.22)
  32.   ;; Set the alignment for the Data, Header, and Title rows
  33.   (vla-SetAlignment
  34.     custObj
  35.     (+ acDataRow acTitleRow)
  36.     acMiddleLeft
  37.   )
  38.   (vla-SetAlignment custObj acHeaderRow acMiddleCenter)
  39.   ;; Set the background color for the Header and Title rows
  40.   (setq colObj (vlax-create-object "AutoCAD.AcCmColor.19"))
  41.   (vla-SetRGB colObj 98 136 213)
  42.   (vla-SetBackgroundColor
  43.     custObj
  44.     (+ acHeaderRow acTitleRow)
  45.     colObj
  46.   )
  47.   ;; Clear the background color for the Data rows
  48.   (vla-SetBackgroundColorNone custObj acDataRow :vlax-true)
  49.   ;; Set the bottom grid color for the Title row
  50.   (vla-SetRGB colObj 0 0 255)
  51.   (vla-SetGridColor custObj acHorzBottom acTitleRow colObj)
  52.   ;; Set the bottom grid lineweight for the Title row
  53.   (vla-SetGridLineWeight
  54.     tableStyle
  55.     acHorzBottom
  56.     acTitleRow
  57.     acLnWt025
  58.   )
  59.   ;; Set the inside grid lines visible for the data and header rows
  60.   (vla-SetGridVisibility
  61.     custObj
  62.     acHorzInside
  63.     (+ acDataRow acHeaderRow)
  64.     :vlax-true
  65.   )
  66.   ;; Set the text height for the Title, Header and Data rows
  67.   (vla-SetTextHeight custObj acTitleRow 1.5)
  68.   (vla-SetTextHeight custObj (+ acDataRow acHeaderRow) 1.0)
  69.   ;; Set the text height and style for the Title row
  70.   (vla-SetTextStyle
  71.     custObj
  72.     (+ acDataRow acHeaderRow acTitleRow)
  73.     "Standard"
  74.   )
  75.   ;; Release the color object
  76.   (vlax-release-object colObj)
  77.   (princ)
  78. )

评分

参与人数 2D豆 +10 收起 理由
/db_自贡黄明儒_ + 5 很给力!经验;技术要点;资料分享奖!
xshrimp + 5 很给力!经验;技术要点;资料分享奖!

查看全部评分

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 604个

财富等级: 财运亨通

发表于 2013-8-26 08:36:44 | 显示全部楼层
楼主随便说几汉字吧{:soso_e147:}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 23个

财富等级: 恭喜发财

发表于 2013-8-26 09:01:24 | 显示全部楼层
全英文那里看的懂,自己写的请用中午。别人的请翻译过来。。。

点评

我帮你翻译:表之样式,只能在命令行输入TABLESTYLE建立,如果想用lisp来建立,怎么办呢,请看下文分解(汉语是多么的好呀!).  发表于 2013-8-26 14:16
只能提点希望,不可乱要求。  发表于 2013-8-26 11:24
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1268个

财富等级: 财源广进

发表于 2013-8-26 09:41:59 来自手机 | 显示全部楼层
如果把前面说明删掉仅剩代码能看懂吗?来自: Android客户端
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 604个

财富等级: 财运亨通

发表于 2013-8-26 13:26:14 | 显示全部楼层
楼主看看是不是应该这样
(vla-SetGridLineWeight tableStyle acHorzBottom acTitleRow acLnWt025)
(vla-SetGridLineWeight custObj acHorzBottom acTitleRow acLnWt025)
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 862个

财富等级: 财运亨通

发表于 2013-8-26 15:21:02 | 显示全部楼层
应该开个英文板块~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~·
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-4-28 22:33 , Processed in 0.387535 second(s), 43 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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